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']
pull/826/head
Sebastian Falbesoner 3 years ago
parent 4dbba3bac7
commit 130ee48108

@ -65,8 +65,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
value = sent_value value = sent_value
chain.append(txid) chain.append(txid)
# We need the wtxids to check P2P announcements # We need the wtxids to check P2P announcements
fulltx = self.nodes[0].getrawtransaction(txid) witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
witness_chain.append(witnesstx['hash']) witness_chain.append(witnesstx['hash'])
# Check that listunspent ancestor{count, size, fees} yield the correct results # Check that listunspent ancestor{count, size, fees} yield the correct results

@ -204,8 +204,7 @@ class AddressTypeTest(BitcoinTestFramework):
def test_change_output_type(self, node_sender, destinations, expected_type): def test_change_output_type(self, node_sender, destinations, expected_type):
txid = self.nodes[node_sender].sendmany(dummy="", amounts=dict.fromkeys(destinations, 0.001)) txid = self.nodes[node_sender].sendmany(dummy="", amounts=dict.fromkeys(destinations, 0.001))
raw_tx = self.nodes[node_sender].getrawtransaction(txid) tx = self.nodes[node_sender].gettransaction(txid=txid, verbose=True)['decoded']
tx = self.nodes[node_sender].decoderawtransaction(raw_tx)
# Make sure the transaction has change: # Make sure the transaction has change:
assert_equal(len(tx["vout"]), len(destinations) + 1) assert_equal(len(tx["vout"]), len(destinations) + 1)

@ -666,7 +666,7 @@ class WalletTest(BitcoinTestFramework):
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1)
destination = self.nodes[1].getnewaddress() destination = self.nodes[1].getnewaddress()
txid = self.nodes[0].sendtoaddress(destination, 0.123) txid = self.nodes[0].sendtoaddress(destination, 0.123)
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex']) tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
output_addresses = [vout['scriptPubKey']['address'] for vout in tx["vout"]] output_addresses = [vout['scriptPubKey']['address'] for vout in tx["vout"]]
assert len(output_addresses) > 1 assert len(output_addresses) > 1
for address in output_addresses: for address in output_addresses:

@ -34,13 +34,13 @@ class CreateTxWalletTest(BitcoinTestFramework):
self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled') self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200) assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex']) tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
assert_equal(tx['locktime'], 0) assert_equal(tx['locktime'], 0)
self.log.info('Check that anti-fee-sniping is enabled when we mine a recent block') self.log.info('Check that anti-fee-sniping is enabled when we mine a recent block')
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1)
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex']) tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
assert 0 < tx['locktime'] <= 201 assert 0 < tx['locktime'] <= 201
def test_tx_size_too_large(self): def test_tx_size_too_large(self):

@ -129,7 +129,7 @@ class WalletHDTest(BitcoinTestFramework):
# send a tx and make sure its using the internal chain for the changeoutput # send a tx and make sure its using the internal chain for the changeoutput
txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1) txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1)
outs = self.nodes[1].decoderawtransaction(self.nodes[1].gettransaction(txid)['hex'])['vout'] outs = self.nodes[1].gettransaction(txid=txid, verbose=True)['decoded']['vout']
keypath = "" keypath = ""
for out in outs: for out in outs:
if out['value'] != 1: if out['value'] != 1:

@ -454,7 +454,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
self.generate(self.nodes[0], 6) self.generate(self.nodes[0], 6)
self.sync_all() self.sync_all()
send_txid = wmulti_priv.sendtoaddress(w0.getnewaddress(), 8) send_txid = wmulti_priv.sendtoaddress(w0.getnewaddress(), 8)
decoded = wmulti_priv.decoderawtransaction(wmulti_priv.gettransaction(send_txid)['hex']) decoded = wmulti_priv.gettransaction(txid=send_txid, verbose=True)['decoded']
assert_equal(len(decoded['vin'][0]['txinwitness']), 4) assert_equal(len(decoded['vin'][0]['txinwitness']), 4)
self.generate(self.nodes[0], 6) self.generate(self.nodes[0], 6)
self.sync_all() self.sync_all()
@ -586,7 +586,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
self.sync_all() self.sync_all()
# It is standard and would relay. # It is standard and would relay.
txid = wmulti_priv_big.sendtoaddress(w0.getnewaddress(), 9.999) txid = wmulti_priv_big.sendtoaddress(w0.getnewaddress(), 9.999)
decoded = wmulti_priv_big.decoderawtransaction(wmulti_priv_big.gettransaction(txid)['hex']) decoded = wmulti_priv_big.gettransaction(txid=txid, verbose=True)['decoded']
# 20 sigs + dummy + witness script # 20 sigs + dummy + witness script
assert_equal(len(decoded['vin'][0]['txinwitness']), 22) assert_equal(len(decoded['vin'][0]['txinwitness']), 22)
@ -620,12 +620,8 @@ class ImportDescriptorsTest(BitcoinTestFramework):
self.generate(self.nodes[0], 6) self.generate(self.nodes[0], 6)
self.sync_all() self.sync_all()
# It is standard and would relay. # It is standard and would relay.
txid = multi_priv_big.sendtoaddress(w0.getnewaddress(), 10, "", "", txid = multi_priv_big.sendtoaddress(w0.getnewaddress(), 10, "", "", True)
True) decoded = multi_priv_big.gettransaction(txid=txid, verbose=True)['decoded']
decoded = multi_priv_big.decoderawtransaction(
multi_priv_big.gettransaction(txid)['hex']
)
self.log.info("Amending multisig with new private keys") self.log.info("Amending multisig with new private keys")
self.nodes[1].createwallet(wallet_name="wmulti_priv3", descriptors=True) self.nodes[1].createwallet(wallet_name="wmulti_priv3", descriptors=True)

Loading…
Cancel
Save