Example #1
0
 def test_sendtoaddress(self, test_params):
     rpc = test_params.get('node1').get('rpc')
     addr = rpc.getnewaddress()
     # "{0:.8f}".format(value)) returns number string with 8 digit precision
     amount = ("{0:.8f}".format(Decimal(rpc.listunspent()[-1].get('amount')) / Decimal(10)))
     txid = rpc.sendtoaddress(addr, amount)
     assert isinstance(txid, str)
     # wait tx to be confirmed
     mine_and_waitconfirms(txid, rpc)
Example #2
0
 def test_sendtoaddress(self, test_params):
     rpc = test_params.get('node1').get('rpc')
     addr = rpc.getnewaddress()
     # python float() is double precision floating point number,
     # where sendmany expects regural float (8 digits) value
     # "{0:.8f}".format(value)) returns number string with 8 digit precision and float() corrects the type
     amount = float("{0:.8f}".format(rpc.listunspent()[-1].get('amount') / 10))
     txid = rpc.sendtoaddress(addr, amount)
     assert isinstance(txid, str)
     # wait tx to be confirmed
     mine_and_waitconfirms(txid, rpc)
Example #3
0
 def test_sendmany(self, test_params):
     rpc1 = test_params.get('node1').get('rpc')
     rpc2 = test_params.get('node2').get('rpc')
     address1 = rpc1.getnewaddress()
     address2 = rpc2.getnewaddress()
     amount = ("{0:.8f}".format(Decimal(rpc1.listunspent()[-1].get('amount')) / Decimal(10)))
     send = {address1: amount, address2: amount}
     txid = rpc1.sendmany("", send)
     assert isinstance(txid, str)
     # wait tx to be confirmed
     mine_and_waitconfirms(txid, rpc1)
Example #4
0
 def test_sendmany(self, test_params):
     rpc1 = test_params.get('node1').get('rpc')
     rpc2 = test_params.get('node2').get('rpc')
     address1 = rpc1.getnewaddress()
     address2 = rpc2.getnewaddress()
     # clarification in test_sendtoaddress above
     amount = float("{0:.8f}".format(rpc1.listunspent()[-1].get('amount') / 10))  # float("{0:.8f}".format(amount2))
     send = {address1: amount, address2: amount}
     txid = rpc1.sendmany("", send)
     assert isinstance(txid, str)
     # wait tx to be confirmed
     mine_and_waitconfirms(txid, rpc1)
Example #5
0
    def test_rawtransactions(self,
                             test_params):  # create, fund, sign, send calls
        fund_schema = {
            'type': 'object',
            'properties': {
                'hex': {
                    'type': 'string'
                },
                'fee': {
                    'type': ['integer', 'number']
                },
                'changepos': {
                    'type': ['integer', 'number']
                }
            }
        }
        sign_schema = {
            'type': 'object',
            'properties': {
                'hex': {
                    'type': 'string'
                },
                'complete': {
                    'type': 'boolean'
                }
            }
        }
        rpc = test_params.get('node1').get('rpc')
        res = rpc.listunspent()
        txid = res[0].get('txid')
        vout = res[0].get('vout')
        base_amount = res[0].get('amount')
        # python float() is double precision floating point number,
        # createrawtransaction method expects C float (8 digits) value
        # "{0:.8f}".format(value)) returns number string with 8 digit precision and float() corrects the type
        if isinstance(base_amount, Decimal):
            amount = float("{0:.8f}".format(float(base_amount) * 0.9))
        else:
            amount = float("{0:.8f}".format(base_amount * 0.9))
        address = rpc.getnewaddress()
        ins = [{'txid': txid, 'vout': vout}]
        outs = {address: amount}

        rawtx = rpc.createrawtransaction(ins, outs)
        assert isinstance(rawtx, str)

        fundtx = rpc.fundrawtransaction(rawtx)
        validate_template(fundtx, fund_schema)

        signtx = rpc.signrawtransaction(fundtx.get('hex'))
        validate_template(signtx, sign_schema)
        assert signtx['complete']

        sendtx = rpc.sendrawtransaction(signtx.get('hex'))
        assert isinstance(sendtx, str)
        assert mine_and_waitconfirms(sendtx, rpc)
Example #6
0
    def test_rawtransactions(self,
                             test_params):  # create, fund, sign, send calls
        fund_schema = {
            'type': 'object',
            'properties': {
                'hex': {
                    'type': 'string'
                },
                'fee': {
                    'type': ['integer', 'number']
                },
                'changepos': {
                    'type': ['integer', 'number']
                }
            }
        }
        sign_schema = {
            'type': 'object',
            'properties': {
                'hex': {
                    'type': 'string'
                },
                'complete': {
                    'type': 'boolean'
                }
            }
        }
        rpc = test_params.get('node1').get('rpc')
        res = rpc.listunspent()
        txid = res[0].get('txid')
        vout = res[0].get('vout')
        base_amount = res[0].get('amount')
        if isinstance(base_amount, Decimal):
            amount = float(base_amount) * 0.9
            print(amount)
        else:
            amount = base_amount * 0.9
        address = rpc.getnewaddress()
        ins = [{'txid': txid, 'vout': vout}]
        outs = {address: amount}

        rawtx = rpc.createrawtransaction(ins, outs)
        assert isinstance(rawtx, str)

        fundtx = rpc.fundrawtransaction(rawtx)
        validate_template(fundtx, fund_schema)

        signtx = rpc.signrawtransaction(fundtx.get('hex'))
        validate_template(signtx, sign_schema)
        assert signtx['complete']

        sendtx = rpc.sendrawtransaction(signtx.get('hex'))
        assert isinstance(sendtx, str)
        assert mine_and_waitconfirms(sendtx, rpc)
Example #7
0
 def test_z_send(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'object',
             'properties': {
                 'id': {
                     'type': 'string'
                 },
                 'status': {
                     'type': 'string'
                 },
                 'creation_time': {
                     'type': 'integer'
                 },
                 'execution_secs': {
                     'type': ['number', 'integer']
                 },
                 'method': {
                     'type': 'string'
                 },
                 'error': {
                     'type': 'object',
                     'properties': {
                         'code': {
                             'type': 'integer'
                         },
                         'message': {
                             'type': 'string'
                         }
                     }
                 },
                 'result': {
                     'type': 'object',
                     'properties': {
                         'txid': {
                             'type': 'string'
                         }
                     }
                 },
                 'params': {
                     'type': 'object',
                     'properties': {
                         'fromaddress': {
                             'type': 'string'
                         },
                         'minconf': {
                             'type': 'integer'
                         },
                         'fee': {
                             'type': ['number', 'integer']
                         },
                         'amounts': {
                             'type': 'array',
                             'items': {
                                 'type': 'object',
                                 'properties': {
                                     'address': {
                                         'type': 'string'
                                     },
                                     'amount': {
                                         'type': 'string'
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     schema_list = {
         'type': 'array',
         'items': {
             'type': 'object',
             'properties': {
                 'txid': {
                     'type': 'string'
                 },
                 'memo': {
                     'type': 'string'
                 },
                 'amount': {
                     'type': ['number', 'integer']
                 },
                 'change': {
                     'type': 'boolean'
                 },
                 'outindex': {
                     'type': 'integer'
                 },
                 'confirmations': {
                     'type': 'integer'
                 },
                 'rawconfirmations': {
                     'type': 'integer'
                 },
                 'jsoutindex': {
                     'type': 'integer'
                 },
                 'jsindex': {
                     'type': 'integer'
                 }
             }
         }
     }
     rpc1 = test_params.get('node1').get('rpc')
     rpc2 = test_params.get('node2').get('rpc')
     transparent1 = rpc1.getnewaddress()
     shielded1 = rpc1.z_getnewaddress()
     transparent2 = rpc2.getnewaddress()
     shielded2 = rpc2.z_getnewaddress()
     amount1 = Decimal("{0:.8f}".format(
         rpc1.listunspent()[-1].get('amount') / 10))
     amount2 = Decimal("{0:.8f}".format(amount1 / 10))
     # "{0:.8f}".format(value)) returns number string with 8 digit precision
     t_send1 = [{
         'address': transparent1,
         'amount': ("{0:.8f}".format(amount2))
     }]
     t_send2 = [{
         'address': transparent2,
         'amount': "{0:.8f}".format(amount2 * Decimal(0.4))
     }]
     z_send1 = [{
         'address': shielded1,
         'amount': "{0:.8f}".format(amount2 * Decimal(0.95))
     }]
     z_send2 = [{
         'address': shielded2,
         'amount': "{0:.8f}".format(amount2 * Decimal(0.4))
     }]
     cases = [(transparent1, t_send1), (transparent1, z_send1),
              (shielded1, t_send2), (shielded1, z_send2)]
     # sendmany cannot use coinbase tx vouts
     txid = rpc1.sendtoaddress(transparent1, amount1)
     mine_and_waitconfirms(txid, rpc1)
     for case in cases:
         assert check_synced(
             rpc1)  # to perform z_sendmany nodes should be synced
         opid = rpc1.z_sendmany(case[0], case[1])
         assert isinstance(opid, str)
         attempts = 0
         while True:
             res = rpc1.z_getoperationstatus([opid])
             validate_template(res, schema)
             status = res[0].get('status')
             if status == 'success':
                 print('Operation successfull\nWaiting confirmations\n')
                 res = rpc1.z_getoperationresult(
                     [opid])  # also clears op from memory
                 validate_template(res, schema)
                 txid = res[0].get('result').get('txid')
                 time.sleep(30)
                 tries = 0
                 while True:
                     try:
                         res = rpc1.getrawtransaction(txid, 1)
                         confirms = res['confirmations']
                         print('TX confirmed \nConfirmations: ', confirms)
                         break
                     except Exception as e:
                         print(
                             "\ntx is in mempool still probably, let's wait a little bit more\nError: ",
                             e)
                         time.sleep(5)
                         tries += 1
                         if tries < 100:
                             pass
                         else:
                             print(
                                 "\nwaited too long - probably tx stuck by some reason"
                             )
                             return False
                 break
             else:
                 attempts += 1
                 print('Waiting operation result\n')
                 time.sleep(10)
             if attempts >= 100:
                 print('operation takes too long, aborting\n')
                 return False
     res = rpc1.z_listreceivedbyaddress(shielded1)
     validate_template(res, schema_list)