@@ -99,25 +99,36 @@ def getrawtransaction_tests(self):
99
99
rawTx = self .nodes [1 ].createrawtransaction ([{'txid' : txid , 'vout' : vout }], {self .nodes [1 ].getnewaddress (): 9.999 })
100
100
rawTxSigned = self .nodes [1 ].signrawtransactionwithwallet (rawTx )
101
101
txId = self .nodes [1 ].sendrawtransaction (rawTxSigned ['hex' ])
102
- self .generate (self .nodes [0 ], 1 )
102
+ self .generateblock (self .nodes [0 ], output = self .nodes [0 ].getnewaddress (), transactions = [rawTxSigned ['hex' ]])
103
+ err_msg = (
104
+ "No such mempool transaction. Use -txindex or provide a block hash to enable"
105
+ " blockchain transaction queries. Use gettransaction for wallet transactions."
106
+ )
103
107
104
108
for n in [0 , 3 ]:
105
109
self .log .info (f"Test getrawtransaction { 'with' if n == 0 else 'without' } -txindex" )
106
- # 1. valid parameters - only supply txid
107
- assert_equal (self .nodes [n ].getrawtransaction (txId ), rawTxSigned ['hex' ])
108
110
109
- # 2. valid parameters - supply txid and 0 for non-verbose
110
- assert_equal (self .nodes [n ].getrawtransaction (txId , 0 ), rawTxSigned ['hex' ])
111
+ if n == 0 :
112
+ # With -txindex.
113
+ # 1. valid parameters - only supply txid
114
+ assert_equal (self .nodes [n ].getrawtransaction (txId ), rawTxSigned ['hex' ])
111
115
112
- # 3 . valid parameters - supply txid and False for non-verbose
113
- assert_equal (self .nodes [n ].getrawtransaction (txId , False ), rawTxSigned ['hex' ])
116
+ # 2 . valid parameters - supply txid and 0 for non-verbose
117
+ assert_equal (self .nodes [n ].getrawtransaction (txId , 0 ), rawTxSigned ['hex' ])
114
118
115
- # 4. valid parameters - supply txid and 1 for verbose.
116
- # We only check the "hex" field of the output so we don't need to update this test every time the output format changes.
117
- assert_equal (self .nodes [n ].getrawtransaction (txId , 1 )["hex" ], rawTxSigned ['hex' ])
119
+ # 3. valid parameters - supply txid and False for non-verbose
120
+ assert_equal (self .nodes [n ].getrawtransaction (txId , False ), rawTxSigned ['hex' ])
118
121
119
- # 5. valid parameters - supply txid and True for non-verbose
120
- assert_equal (self .nodes [n ].getrawtransaction (txId , True )["hex" ], rawTxSigned ['hex' ])
122
+ # 4. valid parameters - supply txid and 1 for verbose.
123
+ # We only check the "hex" field of the output so we don't need to update this test every time the output format changes.
124
+ assert_equal (self .nodes [n ].getrawtransaction (txId , 1 )["hex" ], rawTxSigned ['hex' ])
125
+
126
+ # 5. valid parameters - supply txid and True for non-verbose
127
+ assert_equal (self .nodes [n ].getrawtransaction (txId , True )["hex" ], rawTxSigned ['hex' ])
128
+ else :
129
+ # Without -txindex, expect to raise.
130
+ for verbose in [None , 0 , False , 1 , True ]:
131
+ assert_raises_rpc_error (- 5 , err_msg , self .nodes [n ].getrawtransaction , txId , verbose )
121
132
122
133
# 6. invalid parameters - supply txid and invalid boolean values (strings) for verbose
123
134
for value in ["True" , "False" ]:
@@ -145,10 +156,6 @@ def getrawtransaction_tests(self):
145
156
assert 'in_active_chain' not in gottx
146
157
else :
147
158
self .log .info ("Test getrawtransaction without -txindex, without blockhash: expect the call to raise" )
148
- err_msg = (
149
- "No such mempool transaction. Use -txindex or provide a block hash to enable"
150
- " blockchain transaction queries. Use gettransaction for wallet transactions."
151
- )
152
159
assert_raises_rpc_error (- 5 , err_msg , self .nodes [n ].getrawtransaction , txid = tx , verbose = True )
153
160
# We should not get the tx if we provide an unrelated block
154
161
assert_raises_rpc_error (- 5 , "No such transaction found" , self .nodes [n ].getrawtransaction , txid = tx , blockhash = block2 )
0 commit comments