Skip to content

Commit b9c2418

Browse files
committed
Merge bitcoin/bitcoin#30226: test: add validation for gettxout RPC response
723440c test framework, wallet: rename get_scriptPubKey method to get_output_script (Alfonso Roman Zubeldia) fa0232a test: add validation for gettxout RPC response (Alfonso Roman Zubeldia) Pull request description: Added a new test in `test/functional/rpc_blockchain.py` to validate the gettxout RPC response. This new test ensures all response elements are verified, including `bestblock`, `confirmations`, `value`, `coinbase`, and `scriptPubKey` details. Also renamed the method `get_scriptPubKey` from `test/functional/test_framework/wallet.py` to the modern name `get_output_script` as suggested by maflcko (bitcoin/bitcoin#30226 (comment)) ACKs for top commit: fjahr: reACK 723440c maflcko: lgtm ACK 723440c brunoerg: code review ACK 723440c Tree-SHA512: 3384578909d2e7548cef302c5b8a9fed5b82dfc942892503ad4a05e73f5cceafad1eab3af9a27e54aef3db7631f8935298d6b882c70d2f02a9a75b8e3c209b6c
2 parents 1334ca6 + 723440c commit b9c2418

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

test/functional/feature_coinstatsindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _test_coin_stats_index(self):
151151
# Generate and send a normal tx with two outputs
152152
tx1 = self.wallet.send_to(
153153
from_node=node,
154-
scriptPubKey=self.wallet.get_scriptPubKey(),
154+
scriptPubKey=self.wallet.get_output_script(),
155155
amount=21 * COIN,
156156
)
157157

test/functional/feature_framework_miniwallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_wallet_tagging(self):
4444
tag = ''.join(random.choice(string.ascii_letters) for _ in range(20))
4545
self.log.debug(f"-> ({i}) tag name: {tag}")
4646
tagged_wallet = MiniWallet(node, tag_name=tag)
47-
untagged_wallet.send_to(from_node=node, scriptPubKey=tagged_wallet.get_scriptPubKey(), amount=100000)
47+
untagged_wallet.send_to(from_node=node, scriptPubKey=tagged_wallet.get_output_script(), amount=100000)
4848
tagged_wallet.rescan_utxos()
4949
tagged_wallet.send_self_transfer(from_node=node)
5050
self.generate(node, 1) # clear mempool

test/functional/feature_rbf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def make_utxo(self, node, amount, *, confirmed=True, scriptPubKey=None):
8585
confirmed - txout created will be confirmed in the blockchain;
8686
unconfirmed otherwise.
8787
"""
88-
tx = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_scriptPubKey(), amount=amount)
88+
tx = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_output_script(), amount=amount)
8989

9090
if confirmed:
9191
mempool_size = len(node.getrawmempool())

test/functional/rpc_blockchain.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- getdeploymentinfo
1010
- getchaintxstats
1111
- gettxoutsetinfo
12+
- gettxout
1213
- getblockheader
1314
- getdifficulty
1415
- getnetworkhashps
@@ -90,6 +91,7 @@ def run_test(self):
9091
self._test_getblockchaininfo()
9192
self._test_getchaintxstats()
9293
self._test_gettxoutsetinfo()
94+
self._test_gettxout()
9395
self._test_getblockheader()
9496
self._test_getdifficulty()
9597
self._test_getnetworkhashps()
@@ -400,6 +402,33 @@ def _test_gettxoutsetinfo(self):
400402
# Unknown hash_type raises an error
401403
assert_raises_rpc_error(-8, "'foo hash' is not a valid hash_type", node.gettxoutsetinfo, "foo hash")
402404

405+
def _test_gettxout(self):
406+
self.log.info("Validating gettxout RPC response")
407+
node = self.nodes[0]
408+
409+
# Get the best block hash and the block, which
410+
# should only include the coinbase transaction.
411+
best_block_hash = node.getbestblockhash()
412+
block = node.getblock(best_block_hash)
413+
assert_equal(block['nTx'], 1)
414+
415+
# Get the transaction ID of the coinbase tx and
416+
# the transaction output.
417+
txid = block['tx'][0]
418+
txout = node.gettxout(txid, 0)
419+
420+
# Validate the gettxout response
421+
assert_equal(txout['bestblock'], best_block_hash)
422+
assert_equal(txout['confirmations'], 1)
423+
assert_equal(txout['value'], 25)
424+
assert_equal(txout['scriptPubKey']['address'], self.wallet.get_address())
425+
assert_equal(txout['scriptPubKey']['hex'], self.wallet.get_output_script().hex())
426+
decoded_script = node.decodescript(self.wallet.get_output_script().hex())
427+
assert_equal(txout['scriptPubKey']['asm'], decoded_script['asm'])
428+
assert_equal(txout['scriptPubKey']['desc'], decoded_script['desc'])
429+
assert_equal(txout['scriptPubKey']['type'], decoded_script['type'])
430+
assert_equal(txout['coinbase'], True)
431+
403432
def _test_getblockheader(self):
404433
self.log.info("Test getblockheader")
405434
node = self.nodes[0]

test/functional/test_framework/wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def generate(self, num_blocks, **kwargs):
215215
self.rescan_utxos()
216216
return blocks
217217

218-
def get_scriptPubKey(self):
218+
def get_output_script(self):
219219
return self._scriptPubKey
220220

221221
def get_descriptor(self):

0 commit comments

Comments
 (0)