Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_listsinceblock.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017 The Bitcoin Core developers | # Copyright (c) 2017 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal, assert_array_result, assert_raises_rpc_error | ||||
class ListSinceBlockTest (BitcoinTestFramework): | class ListSinceBlockTest (BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 4 | self.num_nodes = 4 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"], [], []] | self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"], [], []] | ||||
def run_test(self): | def run_test(self): | ||||
self.nodes[2].generate(101) | self.nodes[2].generate(101) | ||||
self.sync_all() | self.sync_all() | ||||
self.test_no_blockhash() | |||||
self.test_invalid_blockhash() | |||||
self.test_reorg() | self.test_reorg() | ||||
self.test_double_spend() | self.test_double_spend() | ||||
self.test_double_send() | self.test_double_send() | ||||
def test_no_blockhash(self): | |||||
txid = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1) | |||||
blockhash, = self.nodes[2].generate(1) | |||||
self.sync_all() | |||||
txs = self.nodes[0].listtransactions() | |||||
assert_array_result(txs, {"txid": txid}, { | |||||
"category": "receive", | |||||
"amount": 1, | |||||
"blockhash": blockhash, | |||||
"confirmations": 1, | |||||
}) | |||||
assert_equal( | |||||
self.nodes[0].listsinceblock(), | |||||
{"lastblock": blockhash, | |||||
"removed": [], | |||||
"transactions": txs}) | |||||
assert_equal( | |||||
self.nodes[0].listsinceblock(""), | |||||
{"lastblock": blockhash, | |||||
"removed": [], | |||||
"transactions": txs}) | |||||
def test_invalid_blockhash(self): | |||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock, | |||||
"42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4") | |||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock, | |||||
"0000000000000000000000000000000000000000000000000000000000000000") | |||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].listsinceblock, | |||||
"invalid-hex") | |||||
def test_reorg(self): | def test_reorg(self): | ||||
''' | ''' | ||||
`listsinceblock` did not behave correctly when handed a block that was | `listsinceblock` did not behave correctly when handed a block that was | ||||
no longer in the main chain: | no longer in the main chain: | ||||
ab0 | ab0 | ||||
/ \ | / \ | ||||
aa1 [tx0] bb1 | aa1 [tx0] bb1 | ||||
▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines |