You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.2 KiB
79 lines
3.2 KiB
9 years ago
|
#!/usr/bin/env python3
|
||
7 years ago
|
# Copyright (c) 2014-2017 The Bitcoin Core developers
|
||
10 years ago
|
# Distributed under the MIT software license, see the accompanying
|
||
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
8 years ago
|
"""Test the zapwallettxes functionality.
|
||
10 years ago
|
|
||
8 years ago
|
- start two bitcoind nodes
|
||
|
- create two transactions on node 0 - one is confirmed and one is unconfirmed.
|
||
|
- restart node 0 and verify that both the confirmed and the unconfirmed
|
||
8 years ago
|
transactions are still available.
|
||
8 years ago
|
- restart node 0 with zapwallettxes and persistmempool, and verify that both
|
||
|
the confirmed and the unconfirmed transactions are still available.
|
||
7 years ago
|
- restart node 0 with just zapwallettxes and verify that the confirmed
|
||
8 years ago
|
transactions are still available, but that the unconfirmed transaction has
|
||
|
been zapped.
|
||
8 years ago
|
"""
|
||
10 years ago
|
from test_framework.test_framework import BitcoinTestFramework
|
||
7 years ago
|
from test_framework.util import (
|
||
|
assert_equal,
|
||
8 years ago
|
assert_raises_rpc_error,
|
||
7 years ago
|
wait_until,
|
||
|
)
|
||
10 years ago
|
|
||
|
class ZapWalletTXesTest (BitcoinTestFramework):
|
||
8 years ago
|
def set_test_params(self):
|
||
9 years ago
|
self.setup_clean_chain = True
|
||
8 years ago
|
self.num_nodes = 2
|
||
10 years ago
|
|
||
8 years ago
|
def run_test(self):
|
||
8 years ago
|
self.log.info("Mining blocks...")
|
||
10 years ago
|
self.nodes[0].generate(1)
|
||
10 years ago
|
self.sync_all()
|
||
8 years ago
|
self.nodes[1].generate(100)
|
||
10 years ago
|
self.sync_all()
|
||
8 years ago
|
|
||
8 years ago
|
# This transaction will be confirmed
|
||
|
txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10)
|
||
8 years ago
|
|
||
10 years ago
|
self.nodes[0].generate(1)
|
||
10 years ago
|
self.sync_all()
|
||
8 years ago
|
|
||
8 years ago
|
# This transaction will not be confirmed
|
||
|
txid2 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 20)
|
||
8 years ago
|
|
||
8 years ago
|
# Confirmed and unconfirmed transactions are now in the wallet.
|
||
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
||
8 years ago
|
|
||
8 years ago
|
# Stop-start node0. Both confirmed and unconfirmed transactions remain in the wallet.
|
||
|
self.stop_node(0)
|
||
8 years ago
|
self.start_node(0)
|
||
8 years ago
|
|
||
8 years ago
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
||
8 years ago
|
|
||
8 years ago
|
# Stop node0 and restart with zapwallettxes and persistmempool. The unconfirmed
|
||
|
# transaction is zapped from the wallet, but is re-added when the mempool is reloaded.
|
||
8 years ago
|
self.stop_node(0)
|
||
8 years ago
|
self.start_node(0, ["-persistmempool=1", "-zapwallettxes=2"])
|
||
8 years ago
|
|
||
7 years ago
|
wait_until(lambda: self.nodes[0].getmempoolinfo()['size'] == 1, timeout=3)
|
||
|
|
||
8 years ago
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
||
8 years ago
|
|
||
8 years ago
|
# Stop node0 and restart with zapwallettxes, but not persistmempool.
|
||
|
# The unconfirmed transaction is zapped and is no longer in the wallet.
|
||
|
self.stop_node(0)
|
||
8 years ago
|
self.start_node(0, ["-zapwallettxes=2"])
|
||
10 years ago
|
|
||
8 years ago
|
# tx1 is still be available because it was confirmed
|
||
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||
10 years ago
|
|
||
8 years ago
|
# This will raise an exception because the unconfirmed transaction has been zapped
|
||
8 years ago
|
assert_raises_rpc_error(-5, 'Invalid or non-wallet transaction id', self.nodes[0].gettransaction, txid2)
|
||
10 years ago
|
|
||
|
if __name__ == '__main__':
|
||
8 years ago
|
ZapWalletTXesTest().main()
|