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.
This commit is contained in:
Jon Atack 2019-09-15 13:27:15 +02:00
parent 0f34f54888
commit 1b41c2c8a1
No known key found for this signature in database
GPG key ID: 4F5721B3D0E3921D

View file

@ -499,10 +499,35 @@ class WalletTest(BitcoinTestFramework):
self.nodes[0].setlabel(change, 'foobar') self.nodes[0].setlabel(change, 'foobar')
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False) assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)
# Test "decoded" field value in gettransaction `verbose` response. # Test gettransaction response with different arguments.
self.log.info("Testing verbose gettransaction...") self.log.info("Testing gettransaction response with different arguments...")
self.nodes[0].setlabel(change, 'baz')
baz = self.nodes[0].listtransactions(label="baz", count=1)[0]
expected_receive_vout = {"label": "baz",
"address": baz["address"],
"amount": baz["amount"],
"category": baz["category"],
"vout": baz["vout"]}
expected_fields = frozenset({'amount', 'bip125-replaceable', 'confirmations', 'details', 'fee',
'hex', 'time', 'timereceived', 'trusted', 'txid', 'walletconflicts'})
verbose_field = "decoded"
expected_verbose_fields = expected_fields | {verbose_field}
self.log.debug("Testing gettransaction response without verbose")
tx = self.nodes[0].gettransaction(txid=txid)
assert_equal(set([*tx]), expected_fields)
assert_array_result(tx["details"], {"category": "receive"}, expected_receive_vout)
self.log.debug("Testing gettransaction response with verbose set to False")
tx = self.nodes[0].gettransaction(txid=txid, verbose=False)
assert_equal(set([*tx]), expected_fields)
assert_array_result(tx["details"], {"category": "receive"}, expected_receive_vout)
self.log.debug("Testing gettransaction response with verbose set to True")
tx = self.nodes[0].gettransaction(txid=txid, verbose=True) tx = self.nodes[0].gettransaction(txid=txid, verbose=True)
assert_equal(tx["decoded"], self.nodes[0].decoderawtransaction(tx["hex"])) assert_equal(set([*tx]), expected_verbose_fields)
assert_array_result(tx["details"], {"category": "receive"}, expected_receive_vout)
assert_equal(tx[verbose_field], self.nodes[0].decoderawtransaction(tx["hex"]))
if __name__ == '__main__': if __name__ == '__main__':