(self)
| 27 | ] |
| 28 | |
| 29 | def run_test(self): |
| 30 | miniwallet = MiniWallet(self.nodes[0]) |
| 31 | # Add enough mature utxos to the wallet, so that all txs spend confirmed coins |
| 32 | self.generate(miniwallet, 5) |
| 33 | self.generate(self.nodes[0], COINBASE_MATURITY) |
| 34 | |
| 35 | chain_height = self.nodes[1].getblockcount() |
| 36 | assert_equal(chain_height, 105) |
| 37 | |
| 38 | txid1 = miniwallet.send_self_transfer(from_node=self.nodes[0])['txid'] |
| 39 | txid2 = miniwallet.send_self_transfer(from_node=self.nodes[0])['txid'] |
| 40 | # This will raise an exception because the transaction is not yet in a block |
| 41 | assert_raises_rpc_error(-5, "Transaction not yet in block", self.nodes[0].gettxoutproof, [txid1]) |
| 42 | |
| 43 | self.generate(self.nodes[0], 1) |
| 44 | blockhash = self.nodes[0].getblockhash(chain_height + 1) |
| 45 | |
| 46 | txlist = [] |
| 47 | blocktxn = self.nodes[0].getblock(blockhash, True)["tx"] |
| 48 | txlist.append(blocktxn[1]) |
| 49 | txlist.append(blocktxn[2]) |
| 50 | |
| 51 | assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1])), [txid1]) |
| 52 | assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2])), txlist) |
| 53 | assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2], blockhash)), txlist) |
| 54 | |
| 55 | txin_spent = miniwallet.get_utxo(txid=txid2) # Get the change from txid2 |
| 56 | tx3 = miniwallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=txin_spent) |
| 57 | txid3 = tx3['txid'] |
| 58 | self.generate(self.nodes[0], 1) |
| 59 | |
| 60 | txid_spent = txin_spent["txid"] |
| 61 | txid_unspent = txid1 # Input was change from txid2, so txid1 should be unspent |
| 62 | |
| 63 | # Invalid txids |
| 64 | assert_raises_rpc_error(-8, "txid must be of length 64 (not 32, for '00000000000000000000000000000000')", self.nodes[0].gettxoutproof, ["00000000000000000000000000000000"], blockhash) |
| 65 | assert_raises_rpc_error(-8, "txid must be hexadecimal string (not 'ZZZ0000000000000000000000000000000000000000000000000000000000000')", self.nodes[0].gettxoutproof, ["ZZZ0000000000000000000000000000000000000000000000000000000000000"], blockhash) |
| 66 | # Invalid blockhashes |
| 67 | assert_raises_rpc_error(-8, "blockhash must be of length 64 (not 32, for '00000000000000000000000000000000')", self.nodes[0].gettxoutproof, [txid_spent], "00000000000000000000000000000000") |
| 68 | assert_raises_rpc_error(-8, "blockhash must be hexadecimal string (not 'ZZZ0000000000000000000000000000000000000000000000000000000000000')", self.nodes[0].gettxoutproof, [txid_spent], "ZZZ0000000000000000000000000000000000000000000000000000000000000") |
| 69 | # We can't find the block from a fully-spent tx |
| 70 | assert_raises_rpc_error(-5, "Transaction not yet in block", self.nodes[0].gettxoutproof, [txid_spent]) |
| 71 | # We can get the proof if we specify the block |
| 72 | assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid_spent], blockhash)), [txid_spent]) |
| 73 | # We can't get the proof if we specify a non-existent block |
| 74 | assert_raises_rpc_error(-5, "Block not found", self.nodes[0].gettxoutproof, [txid_spent], "0000000000000000000000000000000000000000000000000000000000000000") |
| 75 | # We can get the proof if the transaction is unspent |
| 76 | assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid_unspent])), [txid_unspent]) |
| 77 | # We can get the proof if we provide a list of transactions and one of them is unspent. The ordering of the list should not matter. |
| 78 | assert_equal(sorted(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2]))), sorted(txlist)) |
| 79 | assert_equal(sorted(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid2, txid1]))), sorted(txlist)) |
| 80 | # We can always get a proof if we have a -txindex |
| 81 | assert_equal(self.nodes[0].verifytxoutproof(self.nodes[1].gettxoutproof([txid_spent])), [txid_spent]) |
| 82 | # We can't get a proof if we specify transactions from different blocks |
| 83 | assert_raises_rpc_error(-5, "Not all transactions found in specified or retrieved block", self.nodes[0].gettxoutproof, [txid1, txid3]) |
| 84 | # Test empty list |
| 85 | assert_raises_rpc_error(-8, "Parameter 'txids' cannot be empty", self.nodes[0].gettxoutproof, []) |
| 86 | # Test duplicate txid |
nothing calls this directly
no test coverage detected