From fa0232a3e07ad6d11b4d4aaec93e9531ac3274f3 Mon Sep 17 00:00:00 2001 From: Alfonso Roman Zubeldia <19962151+alfonsoromanz@users.noreply.github.com> Date: Tue, 18 Jun 2024 10:49:10 +0200 Subject: [PATCH 1/2] test: add validation for gettxout RPC response --- test/functional/rpc_blockchain.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 862786affd7..1c8f252a799 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -9,6 +9,7 @@ Test the following RPCs: - getdeploymentinfo - getchaintxstats - gettxoutsetinfo + - gettxout - getblockheader - getdifficulty - getnetworkhashps @@ -90,6 +91,7 @@ class BlockchainTest(BitcoinTestFramework): self._test_getblockchaininfo() self._test_getchaintxstats() self._test_gettxoutsetinfo() + self._test_gettxout() self._test_getblockheader() self._test_getdifficulty() self._test_getnetworkhashps() @@ -400,6 +402,33 @@ class BlockchainTest(BitcoinTestFramework): # Unknown hash_type raises an error assert_raises_rpc_error(-8, "'foo hash' is not a valid hash_type", node.gettxoutsetinfo, "foo hash") + def _test_gettxout(self): + self.log.info("Validating gettxout RPC response") + node = self.nodes[0] + + # Get the best block hash and the block, which + # should only include the coinbase transaction. + best_block_hash = node.getbestblockhash() + block = node.getblock(best_block_hash) + assert_equal(block['nTx'], 1) + + # Get the transaction ID of the coinbase tx and + # the transaction output. + txid = block['tx'][0] + txout = node.gettxout(txid, 0) + + # Validate the gettxout response + assert_equal(txout['bestblock'], best_block_hash) + assert_equal(txout['confirmations'], 1) + assert_equal(txout['value'], 25) + assert_equal(txout['scriptPubKey']['address'], self.wallet.get_address()) + assert_equal(txout['scriptPubKey']['hex'], self.wallet.get_scriptPubKey().hex()) + decoded_script = node.decodescript(self.wallet.get_scriptPubKey().hex()) + assert_equal(txout['scriptPubKey']['asm'], decoded_script['asm']) + assert_equal(txout['scriptPubKey']['desc'], decoded_script['desc']) + assert_equal(txout['scriptPubKey']['type'], decoded_script['type']) + assert_equal(txout['coinbase'], True) + def _test_getblockheader(self): self.log.info("Test getblockheader") node = self.nodes[0] From 723440c5b8eb3a815c80bfb37ad195b5448b25ed Mon Sep 17 00:00:00 2001 From: Alfonso Roman Zubeldia <19962151+alfonsoromanz@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:57:36 -0300 Subject: [PATCH 2/2] test framework, wallet: rename get_scriptPubKey method to get_output_script --- test/functional/feature_coinstatsindex.py | 2 +- test/functional/feature_framework_miniwallet.py | 2 +- test/functional/feature_rbf.py | 2 +- test/functional/rpc_blockchain.py | 4 ++-- test/functional/test_framework/wallet.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/functional/feature_coinstatsindex.py b/test/functional/feature_coinstatsindex.py index b4392e6002e..764f027c857 100755 --- a/test/functional/feature_coinstatsindex.py +++ b/test/functional/feature_coinstatsindex.py @@ -151,7 +151,7 @@ class CoinStatsIndexTest(BitcoinTestFramework): # Generate and send a normal tx with two outputs tx1 = self.wallet.send_to( from_node=node, - scriptPubKey=self.wallet.get_scriptPubKey(), + scriptPubKey=self.wallet.get_output_script(), amount=21 * COIN, ) diff --git a/test/functional/feature_framework_miniwallet.py b/test/functional/feature_framework_miniwallet.py index 464f18eb488..db211bc0c5f 100755 --- a/test/functional/feature_framework_miniwallet.py +++ b/test/functional/feature_framework_miniwallet.py @@ -41,7 +41,7 @@ class FeatureFrameworkMiniWalletTest(BitcoinTestFramework): tag = ''.join(random.choice(string.ascii_letters) for _ in range(20)) self.log.debug(f"-> ({i}) tag name: {tag}") tagged_wallet = MiniWallet(node, tag_name=tag) - untagged_wallet.send_to(from_node=node, scriptPubKey=tagged_wallet.get_scriptPubKey(), amount=100000) + untagged_wallet.send_to(from_node=node, scriptPubKey=tagged_wallet.get_output_script(), amount=100000) tagged_wallet.rescan_utxos() tagged_wallet.send_self_transfer(from_node=node) self.generate(node, 1) # clear mempool diff --git a/test/functional/feature_rbf.py b/test/functional/feature_rbf.py index ef2ecfab9ed..c7f0cc5e432 100755 --- a/test/functional/feature_rbf.py +++ b/test/functional/feature_rbf.py @@ -85,7 +85,7 @@ class ReplaceByFeeTest(BitcoinTestFramework): confirmed - txout created will be confirmed in the blockchain; unconfirmed otherwise. """ - tx = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_scriptPubKey(), amount=amount) + tx = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_output_script(), amount=amount) if confirmed: mempool_size = len(node.getrawmempool()) diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 1c8f252a799..a9373d6b83b 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -422,8 +422,8 @@ class BlockchainTest(BitcoinTestFramework): assert_equal(txout['confirmations'], 1) assert_equal(txout['value'], 25) assert_equal(txout['scriptPubKey']['address'], self.wallet.get_address()) - assert_equal(txout['scriptPubKey']['hex'], self.wallet.get_scriptPubKey().hex()) - decoded_script = node.decodescript(self.wallet.get_scriptPubKey().hex()) + assert_equal(txout['scriptPubKey']['hex'], self.wallet.get_output_script().hex()) + decoded_script = node.decodescript(self.wallet.get_output_script().hex()) assert_equal(txout['scriptPubKey']['asm'], decoded_script['asm']) assert_equal(txout['scriptPubKey']['desc'], decoded_script['desc']) assert_equal(txout['scriptPubKey']['type'], decoded_script['type']) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 1cef7147056..48c4b90b325 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -212,7 +212,7 @@ class MiniWallet: self.rescan_utxos() return blocks - def get_scriptPubKey(self): + def get_output_script(self): return self._scriptPubKey def get_descriptor(self):