2016-03-19 20:58:06 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-07-27 00:36:45 +02:00
|
|
|
# Copyright (c) 2014-2018 The Bitcoin Core developers
|
2015-01-07 11:21:53 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2017-01-18 00:34:40 +01:00
|
|
|
"""Test the zapwallettxes functionality.
|
2015-01-07 11:21:53 +01:00
|
|
|
|
2019-08-30 17:28:43 +02:00
|
|
|
- start two lbrycrdd nodes
|
2017-05-03 19:36:13 +02:00
|
|
|
- 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
|
2017-01-18 00:34:40 +01:00
|
|
|
transactions are still available.
|
2017-05-03 19:36:13 +02:00
|
|
|
- restart node 0 with zapwallettxes and persistmempool, and verify that both
|
|
|
|
the confirmed and the unconfirmed transactions are still available.
|
2018-01-18 01:49:45 +01:00
|
|
|
- restart node 0 with just zapwallettxes and verify that the confirmed
|
2017-05-03 19:36:13 +02:00
|
|
|
transactions are still available, but that the unconfirmed transaction has
|
|
|
|
been zapped.
|
2017-01-18 00:34:40 +01:00
|
|
|
"""
|
2015-05-02 12:53:35 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2017-09-12 17:20:26 +02:00
|
|
|
from test_framework.util import (
|
|
|
|
assert_equal,
|
2017-07-12 16:33:46 +02:00
|
|
|
assert_raises_rpc_error,
|
2017-09-12 17:20:26 +02:00
|
|
|
wait_until,
|
|
|
|
)
|
2015-01-07 11:21:53 +01:00
|
|
|
|
|
|
|
class ZapWalletTXesTest (BitcoinTestFramework):
|
2017-06-10 00:21:21 +02:00
|
|
|
def set_test_params(self):
|
2016-05-14 13:01:31 +02:00
|
|
|
self.setup_clean_chain = True
|
2017-05-03 19:36:13 +02:00
|
|
|
self.num_nodes = 2
|
2015-01-07 11:21:53 +01:00
|
|
|
|
2018-09-09 19:32:37 +02:00
|
|
|
def skip_test_if_missing_module(self):
|
|
|
|
self.skip_if_no_wallet()
|
|
|
|
|
2017-05-03 17:49:58 +02:00
|
|
|
def run_test(self):
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Mining blocks...")
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[0].generate(1)
|
2015-01-07 11:21:53 +01:00
|
|
|
self.sync_all()
|
2017-05-03 19:36:13 +02:00
|
|
|
self.nodes[1].generate(100)
|
2015-01-07 11:21:53 +01:00
|
|
|
self.sync_all()
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# This transaction will be confirmed
|
2019-09-19 16:31:07 +02:00
|
|
|
txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[0].generate(1)
|
2015-01-07 11:21:53 +01:00
|
|
|
self.sync_all()
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# This transaction will not be confirmed
|
2019-09-19 16:31:07 +02:00
|
|
|
txid2 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.2)
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# 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)
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# Stop-start node0. Both confirmed and unconfirmed transactions remain in the wallet.
|
|
|
|
self.stop_node(0)
|
2017-06-09 22:35:17 +02:00
|
|
|
self.start_node(0)
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
|
|
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# 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.
|
2017-03-24 04:56:31 +01:00
|
|
|
self.stop_node(0)
|
2017-06-09 22:35:17 +02:00
|
|
|
self.start_node(0, ["-persistmempool=1", "-zapwallettxes=2"])
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-09-12 17:20:26 +02:00
|
|
|
wait_until(lambda: self.nodes[0].getmempoolinfo()['size'] == 1, timeout=3)
|
2018-01-18 16:16:34 +01:00
|
|
|
self.nodes[0].syncwithvalidationinterfacequeue() # Flush mempool to wallet
|
2017-09-12 17:20:26 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
|
|
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
2017-05-03 17:49:58 +02:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# 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)
|
2017-06-09 22:35:17 +02:00
|
|
|
self.start_node(0, ["-zapwallettxes=2"])
|
2015-01-07 11:21:53 +01:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# tx1 is still be available because it was confirmed
|
|
|
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
2015-01-07 11:21:53 +01:00
|
|
|
|
2017-05-03 19:36:13 +02:00
|
|
|
# This will raise an exception because the unconfirmed transaction has been zapped
|
2017-07-12 16:33:46 +02:00
|
|
|
assert_raises_rpc_error(-5, 'Invalid or non-wallet transaction id', self.nodes[0].gettransaction, txid2)
|
2015-01-07 11:21:53 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-05-03 17:49:58 +02:00
|
|
|
ZapWalletTXesTest().main()
|