Skip to content

Commit fa0232a

Browse files
committed
test: add validation for gettxout RPC response
1 parent 2d07384 commit fa0232a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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_scriptPubKey().hex())
426+
decoded_script = node.decodescript(self.wallet.get_scriptPubKey().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]

0 commit comments

Comments
 (0)