Skip to content

Commit 1b41c2c

Browse files
committed
test: improve gettransaction test coverage
- Test gettransaction response without verbose, with verbose=False, and with verbose=True. - In each case, test presence of expected fields in the output, including absence of the "decoded" field when `verbose` is not passed or false. - Test that the "details" field contains the expected receive vout in each case.
1 parent 0f34f54 commit 1b41c2c

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

test/functional/wallet_basic.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,35 @@ def run_test(self):
499499
self.nodes[0].setlabel(change, 'foobar')
500500
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)
501501

502-
# Test "decoded" field value in gettransaction `verbose` response.
503-
self.log.info("Testing verbose gettransaction...")
502+
# Test gettransaction response with different arguments.
503+
self.log.info("Testing gettransaction response with different arguments...")
504+
self.nodes[0].setlabel(change, 'baz')
505+
baz = self.nodes[0].listtransactions(label="baz", count=1)[0]
506+
expected_receive_vout = {"label": "baz",
507+
"address": baz["address"],
508+
"amount": baz["amount"],
509+
"category": baz["category"],
510+
"vout": baz["vout"]}
511+
expected_fields = frozenset({'amount', 'bip125-replaceable', 'confirmations', 'details', 'fee',
512+
'hex', 'time', 'timereceived', 'trusted', 'txid', 'walletconflicts'})
513+
verbose_field = "decoded"
514+
expected_verbose_fields = expected_fields | {verbose_field}
515+
516+
self.log.debug("Testing gettransaction response without verbose")
517+
tx = self.nodes[0].gettransaction(txid=txid)
518+
assert_equal(set([*tx]), expected_fields)
519+
assert_array_result(tx["details"], {"category": "receive"}, expected_receive_vout)
520+
521+
self.log.debug("Testing gettransaction response with verbose set to False")
522+
tx = self.nodes[0].gettransaction(txid=txid, verbose=False)
523+
assert_equal(set([*tx]), expected_fields)
524+
assert_array_result(tx["details"], {"category": "receive"}, expected_receive_vout)
525+
526+
self.log.debug("Testing gettransaction response with verbose set to True")
504527
tx = self.nodes[0].gettransaction(txid=txid, verbose=True)
505-
assert_equal(tx["decoded"], self.nodes[0].decoderawtransaction(tx["hex"]))
528+
assert_equal(set([*tx]), expected_verbose_fields)
529+
assert_array_result(tx["details"], {"category": "receive"}, expected_receive_vout)
530+
assert_equal(tx[verbose_field], self.nodes[0].decoderawtransaction(tx["hex"]))
506531

507532

508533
if __name__ == '__main__':

0 commit comments

Comments
 (0)