@@ -39,7 +39,8 @@ def run_test(self):
39
39
txid1 = self .nodes [0 ].sendrawtransaction (self .nodes [0 ].signrawtransaction (tx1 )["hex" ])
40
40
tx2 = self .nodes [0 ].createrawtransaction ([node0utxos .pop ()], {self .nodes [1 ].getnewaddress (): 49.99 })
41
41
txid2 = self .nodes [0 ].sendrawtransaction (self .nodes [0 ].signrawtransaction (tx2 )["hex" ])
42
- assert_raises (JSONRPCException , self .nodes [0 ].gettxoutproof , [txid1 ])
42
+ # This will raise an exception because the transaction is not yet in a block
43
+ assert_raises_jsonrpc (- 5 , "Transaction not yet in block" , self .nodes [0 ].gettxoutproof , [txid1 ])
43
44
44
45
self .nodes [0 ].generate (1 )
45
46
blockhash = self .nodes [0 ].getblockhash (chain_height + 1 )
@@ -56,25 +57,29 @@ def run_test(self):
56
57
57
58
txin_spent = self .nodes [1 ].listunspent (1 ).pop ()
58
59
tx3 = self .nodes [1 ].createrawtransaction ([txin_spent ], {self .nodes [0 ].getnewaddress (): 49.98 })
59
- self .nodes [0 ].sendrawtransaction (self .nodes [1 ].signrawtransaction (tx3 )["hex" ])
60
+ txid3 = self .nodes [0 ].sendrawtransaction (self .nodes [1 ].signrawtransaction (tx3 )["hex" ])
60
61
self .nodes [0 ].generate (1 )
61
62
self .sync_all ()
62
63
63
64
txid_spent = txin_spent ["txid" ]
64
65
txid_unspent = txid1 if txin_spent ["txid" ] != txid1 else txid2
65
66
66
67
# We can't find the block from a fully-spent tx
67
- assert_raises ( JSONRPCException , self .nodes [2 ].gettxoutproof , [txid_spent ])
68
- # ...but we can if we specify the block
68
+ assert_raises_jsonrpc ( - 5 , "Transaction not yet in block" , self .nodes [2 ].gettxoutproof , [txid_spent ])
69
+ # We can get the proof if we specify the block
69
70
assert_equal (self .nodes [2 ].verifytxoutproof (self .nodes [2 ].gettxoutproof ([txid_spent ], blockhash )), [txid_spent ])
70
- # ...or if the first tx is not fully-spent
71
+ # We can't get the proof if we specify a non-existent block
72
+ assert_raises_jsonrpc (- 5 , "Block not found" , self .nodes [2 ].gettxoutproof , [txid_spent ], "00000000000000000000000000000000" )
73
+ # We can get the proof if the transaction is unspent
71
74
assert_equal (self .nodes [2 ].verifytxoutproof (self .nodes [2 ].gettxoutproof ([txid_unspent ])), [txid_unspent ])
72
- try :
73
- assert_equal (self .nodes [2 ].verifytxoutproof (self .nodes [2 ].gettxoutproof ([txid1 , txid2 ])), txlist )
74
- except JSONRPCException :
75
- assert_equal (self .nodes [2 ].verifytxoutproof (self .nodes [2 ].gettxoutproof ([txid2 , txid1 ])), txlist )
76
- # ...or if we have a -txindex
75
+ # 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.
76
+ assert_equal (sorted (self .nodes [2 ].verifytxoutproof (self .nodes [2 ].gettxoutproof ([txid1 , txid2 ]))), sorted (txlist ))
77
+ assert_equal (sorted (self .nodes [2 ].verifytxoutproof (self .nodes [2 ].gettxoutproof ([txid2 , txid1 ]))), sorted (txlist ))
78
+ # We can always get a proof if we have a -txindex
77
79
assert_equal (self .nodes [2 ].verifytxoutproof (self .nodes [3 ].gettxoutproof ([txid_spent ])), [txid_spent ])
80
+ # We can't get a proof if we specify transactions from different blocks
81
+ assert_raises_jsonrpc (- 5 , "Not all transactions found in specified or retrieved block" , self .nodes [2 ].gettxoutproof , [txid1 , txid3 ])
82
+
78
83
79
84
if __name__ == '__main__' :
80
85
MerkleBlockTest ().main ()
0 commit comments