Esempio n. 1
0
 def test_gettxout(self, test_params):
     schema = {
         'type':
         'object',
         'properties': {
             'bestblock': {
                 'type': 'string'
             },
             'confirmations': {
                 'type': 'integer'
             },
             'rawconfirmations': {
                 'type': 'integer'
             },
             'value': {
                 'type': 'number'
             },
             'scriptPubKey': {
                 'type': 'object',
                 'properties': {
                     'asm': {
                         'type': 'string'
                     },
                     'hex': {
                         'type': 'string'
                     },
                     'reqSigs': {
                         'type': 'integer'
                     },
                     'type': {
                         'type': 'string'
                     },
                     'addresses': {
                         'type': 'array',
                         'items': {
                             'type': 'string'
                         }
                     }
                 }
             },
             'version': {
                 'type': 'integer'
             },
             'coinbase': {
                 'type': 'boolean'
             }
         },
         'required': [
             'bestblock', 'confirmations', 'rawconfirmations', 'value',
             'scriptPubKey', 'version', 'coinbase'
         ]
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.listunspent()
     txid = res[0].get('txid')
     vout = res[0].get('vout')
     res = rpc.gettxout(txid, vout)
     validate_template(res, schema)
     res = rpc.gettxout(txid, -1)
     assert not res  # gettxout retuns None when vout does not exist
Esempio n. 2
0
 def test_gettxoutsetinfo(self, test_params):
     schema = {
         'type':
         'object',
         'required': [
             'height', 'bestblock', 'transactions', 'txouts',
             'bytes_serialized', 'hash_serialized', 'total_amount'
         ],
         'properties': {
             'height': {
                 'type': 'integer'
             },
             'bestblock': {
                 'type': 'string'
             },
             'transactions': {
                 'type': 'integer'
             },
             'txouts': {
                 'type': 'integer'
             },
             'bytes_serialized': {
                 'type': 'integer'
             },
             'hash_serialized': {
                 'type': 'string'
             },
             'total_amount': {
                 'type': ['integer', 'number']
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.gettxoutsetinfo()
     validate_template(res, schema)
 def test_getpeerinfo(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'object',
             'properties': {
                 'id': {'type': 'integer'},
                 'addr': {'type': 'string'},
                 'addrlocal': {'type': 'string'},
                 'services': {'type': 'string'},
                 'lastsend': {'type': 'integer'},
                 'lastrecv': {'type': 'integer'},
                 'bytessent': {'type': 'integer'},
                 'bytesrecv': {'type': 'integer'},
                 'conntime': {'type': 'integer'},
                 'timeoffset': {'type': 'integer'},
                 'pingtime': {'type': ['number', 'integer']},
                 'pingwait': {'type': ['number', 'integer']},
                 'version': {'type': 'integer'},
                 'subver': {'type': 'string'},
                 'inbound': {'type': 'boolean'},
                 'startingheight': {'type': 'integer'},
                 'banscore': {'type': ['number', 'integer']},
                 'synced_headers': {'type': 'integer'},
                 'synced_blocks': {'type': 'integer'},
                 'inflight': {'type': 'array'},
                 'whitelisted': {'type': 'boolean'},
                 'number': {'type': 'integer'}
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getpeerinfo()
     validate_template(res, schema)
Esempio n. 4
0
 def test_z_listopertaionsids(self, test_params):
     schema = {'type': 'array', 'items': {'type': 'string'}}
     rpc = test_params.get('node1').get('rpc')
     res = rpc.z_listoperationids()
     validate_template(res, schema)
     res = rpc.z_listoperationids('success')
     validate_template(res, schema)
Esempio n. 5
0
 def test_getchaintips(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'object',
             'required': ['height', 'hash', 'branchlen', 'status'],
             'properties': {
                 'height': {
                     'type': 'integer'
                 },
                 'hash': {
                     'type': 'string'
                 },
                 'branchlen': {
                     'type': 'integer'
                 },
                 'status': {
                     'type': 'string'
                 }
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getchaintips()
     validate_template(res, schema)
Esempio n. 6
0
 def test_listtransactions(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'object',
             'properties': {
                 'account': {'type': 'string'},
                 'address': {'type': 'string'},
                 'category': {'type': 'string'},
                 'blockhash': {'type': 'string'},
                 'txid': {'type': 'string'},
                 'vjoinsplit': {'type': 'array'},
                 'walletconflicts': {'type': 'array'},
                 'amount': {'type': ['integer', 'number']},
                 'vout': {'type': 'integer'},
                 'rawconfirmations': {'type': 'integer'},
                 'confirmations': {'type': 'integer'},
                 'blockindex': {'type': 'integer'},
                 'fee': {'type': ['integer', 'number']},
                 'time': {'type': 'integer'},
                 'timereceived': {'type': 'integer'},
                 'size': {'type': 'integer'},
                 'comment': {'type': 'string'},
                 'otheraccount': {'type': 'string'}
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.listtransactions()
     validate_template(res, schema)
Esempio n. 7
0
 def test_z_validateaddress(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'isvalid': {
                 'type': 'boolean'
             },
             'address': {
                 'type': 'string'
             },
             'payingkey': {
                 'type': 'string'
             },
             'transmissionkey': {
                 'type': 'string'
             },
             'ismine': {
                 'type': 'boolean'
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     zaddr = rpc.z_getnewaddress()
     res = rpc.z_validateaddress(zaddr)
     validate_template(res, schema)
Esempio n. 8
0
 def test_resendwallettransactions(self, test_params):
     schema = {
         'type': 'array',
         'itmes': {'type': 'string'}
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.resendwallettransactions()
     validate_template(res, schema)
Esempio n. 9
0
 def test_getblockchaininfo(self, test_params):
     schema = {
         'type':
         'object',
         'required': [
             'chain', 'blocks', 'synced', 'headers', 'bestblockhash',
             'upgrades', 'consensus', 'difficulty', 'verificationprogress',
             'chainwork', 'pruned', 'commitments'
         ],
         'properties': {
             'chain': {
                 'type': 'string'
             },
             'blocks': {
                 'type': 'integer'
             },
             'synced': {
                 'type': 'boolean'
             },
             'headers': {
                 'type': 'integer'
             },
             'bestblockhash': {
                 'type': 'string'
             },
             'difficulty': {
                 'type': ['integer', 'number']
             },
             'verificationprogress': {
                 'type': ['integer', 'number']
             },
             'chainwork': {
                 'type': 'string'
             },
             'pruned': {
                 'type': 'boolean'
             },
             'commitments': {
                 'type': ['integer', 'number']
             },
             'valuePools': {
                 'type': 'array',
                 'items': {
                     'type': 'object'
                 }
             },
             'upgrades': {
                 'type': 'object'
             },
             'consensus': {
                 'type': 'object'
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getblockchaininfo()
     validate_template(res, schema)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
0
 def test_setupkey(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'address': {'type': 'string'},
             'pubkey': {'type': 'string'},
             'ismine': {'type': 'boolean'}
         }
     }
     rpc = test_params.get('node1').get('rpc')
     pubkey = test_params.get('node1').get('pubkey')
     res = rpc.setpubkey(pubkey)
     validate_template(res, schema)
Esempio n. 13
0
 def test_listaddressgroupings(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'array',
             'items': {
                 'type': 'array',
                 'items': {'type': ['string', 'integer', 'number']}
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.listaddressgroupings()
     validate_template(res, schema)
Esempio n. 14
0
 def test_getblocksubsidy(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'miner': {'type': 'number'}
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getblocksubsidy()
     validate_template(res, schema)
     res = rpc.getinfo()
     block = res.get('blocks')
     res = rpc.getblocksubsidy(block)
     validate_template(res, schema)
Esempio n. 15
0
 def test_getwalletinfo(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'walletversion': {'type': 'integer'},
             'balance': {'type': ['number', 'integer']},
             'unconfirmed_balance': {'type': ['number', 'integer']},
             'immature_balance': {'type': ['number', 'integer']},
             'txount': {'type': 'integer'},
             'keypoololdest': {'type': 'integer'},
             'keypoolsize': {'type': 'integer'},
             'paytxfee': {'type': ['number', 'integer']},
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getwalletinfo()
     validate_template(res, schema)
Esempio n. 16
0
 def test_getnetworkinfo(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'version': {'type': 'integer'},
             'subversion': {'type': 'string'},
             'protocolversion': {'type': 'integer'},
             'localservices': {'type': 'string'},
             'timeoffset': {'type': 'integer'},
             'connections': {'type': 'integer'},
             'networks': {
                 'type': 'array',
                 'items': {
                     'type': 'object',
                     'properties': {
                         'name': {'type': 'string'},
                         'limited': {'type': 'boolean'},
                         'reachable': {'type': 'boolean'},
                         'proxy': {'type': 'string'},
                         'proxy_randomize_credentials': {'type': 'boolean'},
                     }
                 }
             },
             'relayfee': {'type': 'number'},
             'localadresses': {
                 'type': 'array',
                 'items': {
                     'type': 'object',
                     'properties': {
                         'address': {'type': 'string'},
                         'port': {'type': 'integer'},
                         'score': {'type': 'integer'},
                     },
                     'required': ['address', 'port', 'score']
                 }
             },
             'warnings': {'type': 'string'}
         },
         'required': ['version', 'subversion', 'protocolversion', 'localservices', 'timeoffset', 'connections',
                      'networks', 'relayfee', 'localaddresses', 'warnings']
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getnetworkinfo()
     validate_template(res, schema)
Esempio n. 17
0
 def test_createmultisig(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'address': {
                 'type': 'string'
             },
             'redeemScript': {
                 'type': 'string'
             },
         }
     }
     rpc = test_params.get('node1').get('rpc')
     keys = [
         test_params.get('node1').get('pubkey'),
         test_params.get('node2').get('pubkey')
     ]
     res = rpc.createmultisig(2, keys)
     validate_template(res, schema)
Esempio n. 18
0
 def test_list_lockunspent(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'object',
             'properties': {
                 'txid': {'type': 'string'},
                 'vout': {'type': 'integer'}
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.listunspent()
     txid = res[0].get('txid')
     lock = [{"txid": txid, "vout": 0}]
     res = rpc.lockunspent(False, lock)
     assert res  # returns True on success
     res = rpc.listlockunspent()
     validate_template(res, schema)
     res = rpc.lockunspent(True, lock)
     assert res  # returns True on success
Esempio n. 19
0
 def test_z_gettotalbalance(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'transparent': {
                 'type': ['string']
             },
             'interest': {
                 'type': ['string']
             },
             'private': {
                 'type': ['string']
             },
             'total': {
                 'type': ['string']
             },
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.z_gettotalbalance(1)
     validate_template(res, schema)
Esempio n. 20
0
 def test_listunspent(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'object',
             'properties': {
                 'txid': {'type': 'string'},
                 'address': {'type': 'string'},
                 'scriptPubKey': {'type': 'string'},
                 'generated': {'type': 'boolean'},
                 'spendable': {'type': 'boolean'},
                 'vout': {'type': 'integer'},
                 'confirmations': {'type': 'integer'},
                 'rawconfirmations': {'type': 'integer'},
                 'amount': {'type': ['integer', 'number']},
                 'interest': {'type': ['integer', 'number']}
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.listunspent()
     validate_template(res, schema)
Esempio n. 21
0
 def test_listreceivedbyaddress(self, test_params):
     schema = {
         'type': 'array',
         'items': {
             'type': 'object',
             'properties': {
                 'involvesWatchonly': {'type': 'boolean'},
                 'address': {'type': 'string'},
                 'account': {'type': 'string'},
                 'amount': {'type': ['integer', 'number']},
                 'rawconfirmations': {'type': 'integer'},
                 'confirmations': {'type': 'integer'},
                 'txids': {
                     'type': 'array',
                     'items': {'type': 'string'}
                 }
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.listreceivedbyaddress()
     validate_template(res, schema)
Esempio n. 22
0
 def test_validateaddress(self, test_params):
     schema = {
         'type': 'object',
         'properties': {
             'isvalid': {
                 'type': 'boolean'
             },
             'ismine': {
                 'type': 'boolean'
             },
             'isscript': {
                 'type': 'boolean'
             },
             'iscompressed': {
                 'type': 'boolean'
             },
             'account': {
                 'type': 'string'
             },
             'pubkey': {
                 'type': 'string'
             },
             'address': {
                 'type': 'string'
             },
             'scriptPubKey': {
                 'type': 'string'
             },
             'segid': {
                 'type': 'integer'
             }
         }
     }
     rpc = test_params.get('node1').get('rpc')
     addr = test_params.get('node1').get('address')
     res = rpc.validateaddress(addr)
     validate_template(res, schema)
     assert addr == res.get('address')
Esempio n. 23
0
 def test_decodeccopret(self, test_params):
     rpc = test_params.get('node1').get('rpc')
     schema = {
         'type': 'object',
         'properties': {
             'result': {
                 'type': 'string'
             },
             'OpRets': {
                 'type': 'array',
                 'items': {
                     'type': 'object',
                     'properties': {
                         'eval_code': {
                             'type': 'string'
                         },
                         'function': {
                             'type': 'string'
                         }
                     }
                 }
             }
         }
     }
     rawhex = rpc.oraclescreate('TEST',
                                'Orale creation tx for test purpose', 'L')
     res = rpc.decoderawtransaction(rawhex.get('hex'))
     vouts = res.get('vout')
     ccopret = ''
     for n in vouts:
         if n.get('scriptPubKey').get('type') == 'nulldata':
             ccopret = n.get('scriptPubKey').get('hex')
             break
     res = rpc.decodeccopret(ccopret)
     assert res.get('result') == 'success'
     validate_template(res, schema)
Esempio n. 24
0
 def test_getchaintxstats(self, test_params):
     schema = {
         'type':
         'object',
         'properties': {
             'time': {
                 'type': 'integer'
             },
             'txcount': {
                 'type': 'integer'
             },
             'window_final_block_hash': {
                 'type': 'string'
             },
             'window_final_block_count': {
                 'type': 'integer'
             },
             'window_block_count': {
                 'type': 'integer'
             },
             'window_tx_count': {
                 'type': 'integer'
             },
             'window_interval': {
                 'type': 'integer'
             },
             'txrate': {
                 'type': ['number', 'integer']
             }
         },
         'required': [
             'time', 'txcount', 'txrate', 'window_final_block_hash',
             'window_interval', 'window_block_count', 'window_tx_count'
         ]
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getchaintxstats()
     validate_template(res, schema)
     res = rpc.getinfo()
     nblocks = (int(res.get('blocks') / 2))
     blockhash = rpc.getblockhash(res.get('blocks'))
     res = rpc.getchaintxstats(nblocks)
     validate_template(res, schema)
     res = rpc.getchaintxstats(nblocks, blockhash)
     validate_template(res, schema)
Esempio n. 25
0
 def test_z_listaddresses(self, test_params):
     schema = {'type': 'array', 'items': {'type': 'string'}}
     rpc = test_params.get('node1').get('rpc')
     res = rpc.z_listaddresses()
     validate_template(res, schema)
Esempio n. 26
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)
Esempio n. 27
0
    def test_getrawtransaction(self, test_params):  # decode, get methods
        txschema = {
            'type': 'object',
            'properties': {
                'hex': {
                    'type': 'string'
                },
                'txid': {
                    'type': 'string'
                },
                'overwintered': {
                    'type': 'boolean'
                },
                'version': {
                    'type': 'integer'
                },
                'versiongroupid': {
                    'type': 'string'
                },
                'locktime': {
                    'type': 'integer'
                },
                'expiryheight': {
                    'type': 'integer'
                },
                'vin': {
                    'type': 'array',
                    'items': {
                        'type': 'object',
                        'properties': {
                            'coinbase': {
                                'type': 'string'
                            },
                            'txid': {
                                'type': 'string'
                            },
                            'vout': {
                                'type': 'integer'
                            },
                            'address': {
                                'type': 'string'
                            },
                            'scriptSig': {
                                'type': 'object',
                                'properties': {
                                    'asm': {
                                        'type': 'string'
                                    },
                                    'hex': {
                                        'type': 'string'
                                    }
                                }
                            },
                            'value': {
                                'type': ['integer', 'number']
                            },
                            'valueSat': {
                                'type': 'integer'
                            },
                            'sequence': {
                                'type': 'integer'
                            }
                        }
                    }
                },
                'vout': {
                    'type': 'array',
                    'items': {
                        'type': 'object',
                        'properties': {
                            'value': {
                                'type': ['integer', 'number']
                            },
                            'valueSat': {
                                'type': 'integer'
                            },
                            'interest': {
                                'type': ['integer', 'number']
                            },
                            'n': {
                                'type': 'integer'
                            },
                            'scriptPubKey': {
                                'type': 'object',
                                'properties': {
                                    'asm': {
                                        'type': 'string'
                                    },
                                    'hex': {
                                        'type': 'string'
                                    },
                                    'reqSigs': {
                                        'type': 'integer'
                                    },
                                    'type': {
                                        'type': 'string'
                                    },
                                    'addresses': {
                                        'type': 'array',
                                        'items': {
                                            'type': 'string'
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                'vjoinsplit': {
                    'type': 'array'
                },
                'valueBalance': {
                    'type': 'number'
                },
                'vShieldedSpend': {
                    'type': 'array'
                },
                'vShieldedOutput': {
                    'type': 'array'
                },
                'blockhash': {
                    'type': 'string'
                },
                'height': {
                    'type': 'integer'
                },
                'confirmations': {
                    'type': 'integer'
                },
                'rawconfirmations': {
                    'type': 'integer'
                },
                'time': {
                    'type': 'integer'
                },
                'blocktime': {
                    'type': 'integer'
                }
            }
        }
        scriptschema = {
            'type': 'object',
            'properties': {
                'asm': {
                    'type': 'string'
                },
                'hex': {
                    'type': 'string'
                },
                'type': {
                    'type': 'string'
                },
                'reqSigs': {
                    'type': 'integer'
                },
                'address': {
                    'type': 'string'
                },
                'p2sh': {
                    'type': 'string'
                },
                'addresses': {
                    'type': 'array',
                    'items': {
                        'type': 'string'
                    }
                }
            }
        }
        rpc = test_params.get('node1').get('rpc')
        res = rpc.listunspent()
        txid = res[0].get('txid')
        rawhex = rpc.getrawtransaction(txid)
        assert isinstance(rawhex, str)
        res = rpc.getrawtransaction(txid, 1)
        validate_template(res, txschema)

        scripthex = res.get('vout')[0].get('scriptPubKey').get('hex')
        res = rpc.decodescript(scripthex)
        validate_template(res, scriptschema)

        res = rpc.decoderawtransaction(rawhex)
        validate_template(res, txschema)
Esempio n. 28
0
 def test_getblocktemplate(self, test_params):
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getblocktemplate()
     validate_template(res)
Esempio n. 29
0
 def test_getblockheader(self, test_params):
     schema = {
         'type':
         'object',
         'properties': {
             'last_notarized_height': {
                 'type': 'integer'
             },
             'hash': {
                 'type': 'string'
             },
             'confirmations': {
                 'type': 'integer'
             },
             'rawconfirmations': {
                 'type': 'integer'
             },
             'height': {
                 'type': 'integer'
             },
             'version': {
                 'type': 'integer'
             },
             'merkleroot': {
                 'type': 'string'
             },
             'segid': {
                 'type': 'integer'
             },
             'finalsaplingroot': {
                 'type': 'string'
             },
             'time': {
                 'type': 'integer'
             },
             'nonce': {
                 'type': 'string'
             },
             'solution': {
                 'type': 'string'
             },
             'bits': {
                 'type': 'string'
             },
             'difficulty': {
                 'type': ['number', 'integer']
             },
             'chainwork': {
                 'type': 'string'
             },
             'previousblockhash': {
                 'type': 'string'
             },
             'nextblockhash': {
                 'type': 'string'
             }
         },
         'required': [
             'last_notarized_height', 'hash', 'confirmations',
             'rawconfirmations', 'height', 'version', 'merkleroot', 'segid',
             'finalsaplingroot', 'time', 'nonce', 'solution', 'bits',
             'difficulty', 'chainwork', 'previousblockhash'
         ]
     }
     rpc = test_params.get('node1').get('rpc')
     res = rpc.getinfo()
     block = res.get('blocks')
     blockhash = rpc.getblockhash(block)
     res1 = rpc.getblockheader(blockhash)
     res2 = rpc.getblockheader(blockhash, True)
     assert res1 == res2
     validate_template(res1, schema)
     res = rpc.getblockheader(blockhash, False)
     assert isinstance(res, str)
Esempio n. 30
0
 def test_getblock(self, test_params):
     schema = {
         'type':
         'object',
         'properties': {
             'last_notarized_height': {
                 'type': 'integer'
             },
             'hash': {
                 'type': 'string'
             },
             'confirmations': {
                 'type': 'integer'
             },
             'rawconfirmations': {
                 'type': 'integer'
             },
             'size': {
                 'type': 'integer'
             },
             'height': {
                 'type': 'integer'
             },
             'version': {
                 'type': 'integer'
             },
             'merkleroot': {
                 'type': 'string'
             },
             'segid': {
                 'type': 'integer'
             },
             'finalsaplingroot': {
                 'type': 'string'
             },
             'tx': {
                 'type': 'array'
             },
             'time': {
                 'type': 'integer'
             },
             'nonce': {
                 'type': 'string'
             },
             'solution': {
                 'type': 'string'
             },
             'bits': {
                 'type': 'string'
             },
             'difficulty': {
                 'type': ['number', 'integer']
             },
             'chainwork': {
                 'type': 'string'
             },
             'blocktype': {
                 'type': 'string'
             },
             'valuePools': {
                 'type': 'array',
                 'items': {
                     'type': 'object',
                     'properties': {
                         'id': {
                             'type': 'string'
                         },
                         'monitored': {
                             'type': 'boolean'
                         },
                         'chainValue': {
                             'type': ['number', 'integer']
                         },
                         'chainValueZat': {
                             'type': ['number', 'integer']
                         },
                         'valueDelta': {
                             'type': ['number', 'integer']
                         },
                         'valueDeltaZat': {
                             'type': ['number', 'integer']
                         }
                     }
                 }
             },
             'previousblockhash': {
                 'type': 'string'
             },
             'nextblockhash': {
                 'type': 'string'
             }
         },
         'required': [
             'last_notarized_height', 'hash', 'confirmations',
             'rawconfirmations', 'size', 'height', 'version', 'merkleroot',
             'segid', 'finalsaplingroot', 'tx', 'time', 'nonce', 'solution',
             'bits', 'difficulty', 'chainwork', 'anchor', 'blocktype',
             'valuePools', 'previousblockhash'
         ]
     }
     rpc = test_params.get('node1').get('rpc')
     blocknum = str(rpc.getblockcount())
     res = rpc.getblock(blocknum)
     validate_template(res, schema)
     res = rpc.getblock(blocknum, False)
     assert isinstance(res, str)