Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_listtransactions.py
Show All 18 Lines | class ListTransactionsTest(BitcoinTestFramework): | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
# Leave IBD | # Leave IBD | ||||
self.generate(self.nodes[0], 1) | self.generate(self.nodes[0], 1) | ||||
# Simple send, 0 to 1: | # Simple send, 0 to 1: | ||||
txid = self.nodes[0].sendtoaddress( | txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 100000) | ||||
self.nodes[1].getnewaddress(), 100000) | |||||
self.sync_all() | self.sync_all() | ||||
assert_array_result(self.nodes[0].listtransactions(), | assert_array_result( | ||||
self.nodes[0].listtransactions(), | |||||
{"txid": txid}, | {"txid": txid}, | ||||
{"category": "send", "amount": Decimal("-100000"), "confirmations": 0}) | {"category": "send", "amount": Decimal("-100000"), "confirmations": 0}, | ||||
assert_array_result(self.nodes[1].listtransactions(), | ) | ||||
assert_array_result( | |||||
self.nodes[1].listtransactions(), | |||||
{"txid": txid}, | {"txid": txid}, | ||||
{"category": "receive", "amount": Decimal("100000"), "confirmations": 0}) | {"category": "receive", "amount": Decimal("100000"), "confirmations": 0}, | ||||
) | |||||
# mine a block, confirmations should change: | # mine a block, confirmations should change: | ||||
blockhash = self.generate(self.nodes[0], 1)[0] | blockhash = self.generate(self.nodes[0], 1)[0] | ||||
blockheight = self.nodes[0].getblockheader(blockhash)['height'] | blockheight = self.nodes[0].getblockheader(blockhash)["height"] | ||||
assert_array_result(self.nodes[0].listtransactions(), | assert_array_result( | ||||
self.nodes[0].listtransactions(), | |||||
{"txid": txid}, | {"txid": txid}, | ||||
{"category": "send", "amount": Decimal("-100000"), "confirmations": 1, "blockhash": blockhash, "blockheight": blockheight}) | { | ||||
assert_array_result(self.nodes[1].listtransactions(), | "category": "send", | ||||
"amount": Decimal("-100000"), | |||||
"confirmations": 1, | |||||
"blockhash": blockhash, | |||||
"blockheight": blockheight, | |||||
}, | |||||
) | |||||
assert_array_result( | |||||
self.nodes[1].listtransactions(), | |||||
{"txid": txid}, | {"txid": txid}, | ||||
{"category": "receive", "amount": Decimal("100000"), "confirmations": 1, "blockhash": blockhash, "blockheight": blockheight}) | { | ||||
"category": "receive", | |||||
"amount": Decimal("100000"), | |||||
"confirmations": 1, | |||||
"blockhash": blockhash, | |||||
"blockheight": blockheight, | |||||
}, | |||||
) | |||||
# send-to-self: | # send-to-self: | ||||
txid = self.nodes[0].sendtoaddress( | txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 200000) | ||||
self.nodes[0].getnewaddress(), 200000) | assert_array_result( | ||||
assert_array_result(self.nodes[0].listtransactions(), | self.nodes[0].listtransactions(), | ||||
{"txid": txid, "category": "send"}, | {"txid": txid, "category": "send"}, | ||||
{"amount": Decimal("-200000")}) | {"amount": Decimal("-200000")}, | ||||
assert_array_result(self.nodes[0].listtransactions(), | ) | ||||
assert_array_result( | |||||
self.nodes[0].listtransactions(), | |||||
{"txid": txid, "category": "receive"}, | {"txid": txid, "category": "receive"}, | ||||
{"amount": Decimal("200000")}) | {"amount": Decimal("200000")}, | ||||
) | |||||
# sendmany from node1: twice to self, twice to node2: | # sendmany from node1: twice to self, twice to node2: | ||||
send_to = {self.nodes[0].getnewaddress(): 110000, | send_to = { | ||||
self.nodes[0].getnewaddress(): 110000, | |||||
self.nodes[1].getnewaddress(): 220000, | self.nodes[1].getnewaddress(): 220000, | ||||
self.nodes[0].getnewaddress(): 330000, | self.nodes[0].getnewaddress(): 330000, | ||||
self.nodes[1].getnewaddress(): 440000} | self.nodes[1].getnewaddress(): 440000, | ||||
} | |||||
txid = self.nodes[1].sendmany("", send_to) | txid = self.nodes[1].sendmany("", send_to) | ||||
self.sync_all() | self.sync_all() | ||||
assert_array_result(self.nodes[1].listtransactions(), | assert_array_result( | ||||
self.nodes[1].listtransactions(), | |||||
{"category": "send", "amount": Decimal("-110000")}, | {"category": "send", "amount": Decimal("-110000")}, | ||||
{"txid": txid}) | {"txid": txid}, | ||||
assert_array_result(self.nodes[0].listtransactions(), | ) | ||||
{"category": "receive", | assert_array_result( | ||||
"amount": Decimal("110000")}, | self.nodes[0].listtransactions(), | ||||
{"txid": txid}) | {"category": "receive", "amount": Decimal("110000")}, | ||||
assert_array_result(self.nodes[1].listtransactions(), | {"txid": txid}, | ||||
) | |||||
assert_array_result( | |||||
self.nodes[1].listtransactions(), | |||||
{"category": "send", "amount": Decimal("-220000")}, | {"category": "send", "amount": Decimal("-220000")}, | ||||
{"txid": txid}) | {"txid": txid}, | ||||
assert_array_result(self.nodes[1].listtransactions(), | ) | ||||
{"category": "receive", | assert_array_result( | ||||
"amount": Decimal("220000")}, | self.nodes[1].listtransactions(), | ||||
{"txid": txid}) | {"category": "receive", "amount": Decimal("220000")}, | ||||
assert_array_result(self.nodes[1].listtransactions(), | {"txid": txid}, | ||||
) | |||||
assert_array_result( | |||||
self.nodes[1].listtransactions(), | |||||
{"category": "send", "amount": Decimal("-330000")}, | {"category": "send", "amount": Decimal("-330000")}, | ||||
{"txid": txid}) | {"txid": txid}, | ||||
assert_array_result(self.nodes[0].listtransactions(), | ) | ||||
{"category": "receive", | assert_array_result( | ||||
"amount": Decimal("330000")}, | self.nodes[0].listtransactions(), | ||||
{"txid": txid}) | {"category": "receive", "amount": Decimal("330000")}, | ||||
assert_array_result(self.nodes[1].listtransactions(), | {"txid": txid}, | ||||
) | |||||
assert_array_result( | |||||
self.nodes[1].listtransactions(), | |||||
{"category": "send", "amount": Decimal("-440000")}, | {"category": "send", "amount": Decimal("-440000")}, | ||||
{"txid": txid}) | {"txid": txid}, | ||||
assert_array_result(self.nodes[1].listtransactions(), | ) | ||||
{"category": "receive", | assert_array_result( | ||||
"amount": Decimal("440000")}, | self.nodes[1].listtransactions(), | ||||
{"txid": txid}) | {"category": "receive", "amount": Decimal("440000")}, | ||||
{"txid": txid}, | |||||
) | |||||
if not self.options.descriptors: | if not self.options.descriptors: | ||||
# include_watchonly is a legacy wallet feature, so don't test it | # include_watchonly is a legacy wallet feature, so don't test it | ||||
# for descriptor wallets | # for descriptor wallets | ||||
pubkey = self.nodes[1].getaddressinfo( | pubkey = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())[ | ||||
self.nodes[1].getnewaddress())['pubkey'] | "pubkey" | ||||
] | |||||
multisig = self.nodes[1].createmultisig(1, [pubkey]) | multisig = self.nodes[1].createmultisig(1, [pubkey]) | ||||
self.nodes[0].importaddress( | self.nodes[0].importaddress( | ||||
multisig["redeemScript"], "watchonly", False, True) | multisig["redeemScript"], "watchonly", False, True | ||||
) | |||||
txid = self.nodes[1].sendtoaddress(multisig["address"], 100000) | txid = self.nodes[1].sendtoaddress(multisig["address"], 100000) | ||||
self.generate(self.nodes[1], 1) | self.generate(self.nodes[1], 1) | ||||
assert_equal(len(self.nodes[0].listtransactions( | assert_equal( | ||||
label="watchonly", include_watchonly=True)), 1) | len( | ||||
assert_equal(len(self.nodes[0].listtransactions( | |||||
dummy="watchonly", include_watchonly=True)), 1) | |||||
assert len( | |||||
self.nodes[0].listtransactions( | self.nodes[0].listtransactions( | ||||
label="watchonly", | label="watchonly", include_watchonly=True | ||||
count=100, | ) | ||||
include_watchonly=False)) == 0 | ), | ||||
1, | |||||
) | |||||
assert_equal( | |||||
len( | |||||
self.nodes[0].listtransactions( | |||||
dummy="watchonly", include_watchonly=True | |||||
) | |||||
), | |||||
1, | |||||
) | |||||
assert ( | |||||
len( | |||||
self.nodes[0].listtransactions( | |||||
label="watchonly", count=100, include_watchonly=False | |||||
) | |||||
) | |||||
== 0 | |||||
) | |||||
assert_array_result( | assert_array_result( | ||||
self.nodes[0].listtransactions(label="watchonly", count=100, | self.nodes[0].listtransactions( | ||||
include_watchonly=True), | label="watchonly", count=100, include_watchonly=True | ||||
), | |||||
{"category": "receive", "amount": Decimal("100000")}, | {"category": "receive", "amount": Decimal("100000")}, | ||||
{"txid": txid, "label": "watchonly"}) | {"txid": txid, "label": "watchonly"}, | ||||
) | |||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
ListTransactionsTest().main() | ListTransactionsTest().main() |