Skip to content

Commit 130ee48

Browse files
committed
test: get and decode tx with a single gettransaction RPC call
Rather than subsequently calling `gettransaction` and `decoderawtransaction` to get the decoded information for a specific tx-id, we can simply use the verbose version of `gettransaction`, which returns this in a 'decoded' key. I.e. node.decoderawtransaction(node.gettransaction(txid)['hex']) can be replaced by: node.gettransaction(txid=txid, verbose=True)['decoded']
1 parent 4dbba3b commit 130ee48

File tree

6 files changed

+10
-16
lines changed

6 files changed

+10
-16
lines changed

test/functional/mempool_packages.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def run_test(self):
6565
value = sent_value
6666
chain.append(txid)
6767
# We need the wtxids to check P2P announcements
68-
fulltx = self.nodes[0].getrawtransaction(txid)
69-
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
68+
witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
7069
witness_chain.append(witnesstx['hash'])
7170

7271
# Check that listunspent ancestor{count, size, fees} yield the correct results

test/functional/wallet_address_types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ def test_desc(self, node, address, multisig, typ, utxo):
204204

205205
def test_change_output_type(self, node_sender, destinations, expected_type):
206206
txid = self.nodes[node_sender].sendmany(dummy="", amounts=dict.fromkeys(destinations, 0.001))
207-
raw_tx = self.nodes[node_sender].getrawtransaction(txid)
208-
tx = self.nodes[node_sender].decoderawtransaction(raw_tx)
207+
tx = self.nodes[node_sender].gettransaction(txid=txid, verbose=True)['decoded']
209208

210209
# Make sure the transaction has change:
211210
assert_equal(len(tx["vout"]), len(destinations) + 1)

test/functional/wallet_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def run_test(self):
666666
self.generate(self.nodes[0], 1)
667667
destination = self.nodes[1].getnewaddress()
668668
txid = self.nodes[0].sendtoaddress(destination, 0.123)
669-
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex'])
669+
tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
670670
output_addresses = [vout['scriptPubKey']['address'] for vout in tx["vout"]]
671671
assert len(output_addresses) > 1
672672
for address in output_addresses:

test/functional/wallet_create_tx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def test_anti_fee_sniping(self):
3434
self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')
3535
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
3636
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
37-
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex'])
37+
tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
3838
assert_equal(tx['locktime'], 0)
3939

4040
self.log.info('Check that anti-fee-sniping is enabled when we mine a recent block')
4141
self.generate(self.nodes[0], 1)
4242
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
43-
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex'])
43+
tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
4444
assert 0 < tx['locktime'] <= 201
4545

4646
def test_tx_size_too_large(self):

test/functional/wallet_hd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def run_test(self):
129129

130130
# send a tx and make sure its using the internal chain for the changeoutput
131131
txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1)
132-
outs = self.nodes[1].decoderawtransaction(self.nodes[1].gettransaction(txid)['hex'])['vout']
132+
outs = self.nodes[1].gettransaction(txid=txid, verbose=True)['decoded']['vout']
133133
keypath = ""
134134
for out in outs:
135135
if out['value'] != 1:

test/functional/wallet_importdescriptors.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def run_test(self):
454454
self.generate(self.nodes[0], 6)
455455
self.sync_all()
456456
send_txid = wmulti_priv.sendtoaddress(w0.getnewaddress(), 8)
457-
decoded = wmulti_priv.decoderawtransaction(wmulti_priv.gettransaction(send_txid)['hex'])
457+
decoded = wmulti_priv.gettransaction(txid=send_txid, verbose=True)['decoded']
458458
assert_equal(len(decoded['vin'][0]['txinwitness']), 4)
459459
self.generate(self.nodes[0], 6)
460460
self.sync_all()
@@ -586,7 +586,7 @@ def run_test(self):
586586
self.sync_all()
587587
# It is standard and would relay.
588588
txid = wmulti_priv_big.sendtoaddress(w0.getnewaddress(), 9.999)
589-
decoded = wmulti_priv_big.decoderawtransaction(wmulti_priv_big.gettransaction(txid)['hex'])
589+
decoded = wmulti_priv_big.gettransaction(txid=txid, verbose=True)['decoded']
590590
# 20 sigs + dummy + witness script
591591
assert_equal(len(decoded['vin'][0]['txinwitness']), 22)
592592

@@ -620,12 +620,8 @@ def run_test(self):
620620
self.generate(self.nodes[0], 6)
621621
self.sync_all()
622622
# It is standard and would relay.
623-
txid = multi_priv_big.sendtoaddress(w0.getnewaddress(), 10, "", "",
624-
True)
625-
decoded = multi_priv_big.decoderawtransaction(
626-
multi_priv_big.gettransaction(txid)['hex']
627-
)
628-
623+
txid = multi_priv_big.sendtoaddress(w0.getnewaddress(), 10, "", "", True)
624+
decoded = multi_priv_big.gettransaction(txid=txid, verbose=True)['decoded']
629625

630626
self.log.info("Amending multisig with new private keys")
631627
self.nodes[1].createwallet(wallet_name="wmulti_priv3", descriptors=True)

0 commit comments

Comments
 (0)