2016-05-06 11:23:48 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2014-2016 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.
|
2019-01-07 10:55:35 +01:00
|
|
|
"""Test the zapwallettxes functionality.
|
2015-01-07 11:21:53 +01:00
|
|
|
|
2019-07-24 19:13:09 +02:00
|
|
|
- start two dashd nodes
|
2017-07-17 04:23:20 +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
|
2019-01-07 10:55:35 +01:00
|
|
|
transactions are still available.
|
2017-07-17 04:23:20 +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 21:43:47 +01:00
|
|
|
- restart node 0 with just zapwallettxes and verify that the confirmed
|
2017-07-17 04:23:20 +02:00
|
|
|
transactions are still available, but that the unconfirmed transaction has
|
|
|
|
been zapped.
|
2019-01-07 10:55:35 +01:00
|
|
|
"""
|
2015-05-02 12:53:35 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2019-08-16 13:51:15 +02:00
|
|
|
from test_framework.util import (
|
|
|
|
assert_equal,
|
2019-09-25 11:34:51 +02:00
|
|
|
assert_raises_rpc_error,
|
2019-08-16 13:51:15 +02:00
|
|
|
)
|
|
|
|
from test_framework.mininode import wait_until
|
2015-01-07 11:21:53 +01:00
|
|
|
|
|
|
|
class ZapWalletTXesTest (BitcoinTestFramework):
|
2017-09-01 18:47:13 +02:00
|
|
|
def set_test_params(self):
|
2016-05-20 15:16:51 +02:00
|
|
|
self.setup_clean_chain = True
|
2017-07-17 04:23:20 +02:00
|
|
|
self.num_nodes = 2
|
2015-01-07 11:21:53 +01:00
|
|
|
|
2017-07-17 04:23:20 +02:00
|
|
|
def run_test(self):
|
2017-03-09 21:16:20 +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-07-17 04:23:20 +02:00
|
|
|
self.nodes[1].generate(100)
|
2015-01-07 11:21:53 +01:00
|
|
|
self.sync_all()
|
2017-07-17 04:23:20 +02:00
|
|
|
|
|
|
|
# This transaction will be confirmed
|
|
|
|
txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10)
|
|
|
|
|
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-07-17 04:23:20 +02:00
|
|
|
|
|
|
|
# This transaction will not be confirmed
|
|
|
|
txid2 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 20)
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
# Stop-start node0. Both confirmed and unconfirmed transactions remain in the wallet.
|
|
|
|
self.stop_node(0)
|
2017-09-01 18:47:13 +02:00
|
|
|
self.start_node(0)
|
2017-07-17 04:23:20 +02:00
|
|
|
|
|
|
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
|
|
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
|
|
|
|
|
|
|
# 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-06-02 12:08:48 +02:00
|
|
|
self.stop_node(0)
|
2017-09-01 18:47:13 +02:00
|
|
|
self.start_node(0, ["-persistmempool=1", "-zapwallettxes=2"])
|
2017-07-17 04:23:20 +02:00
|
|
|
|
2019-08-16 13:51:15 +02:00
|
|
|
wait_until(lambda: self.nodes[0].getmempoolinfo()['size'] == 1, timeout=3)
|
2018-01-29 10:35:53 +01:00
|
|
|
self.nodes[0].syncwithvalidationinterfacequeue() # Flush mempool to wallet
|
2019-08-16 13:51:15 +02:00
|
|
|
|
2017-07-17 04:23:20 +02:00
|
|
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
|
|
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
|
|
|
|
|
|
|
# Stop node0 and restart with zapwallettxes, but not persistmempool.
|
|
|
|
# The unconfirmed transaction is zapped and is no longer in the wallet.
|
2017-06-02 12:08:48 +02:00
|
|
|
self.stop_node(0)
|
2017-09-01 18:47:13 +02:00
|
|
|
self.start_node(0, ["-zapwallettxes=2"])
|
2015-01-07 11:21:53 +01:00
|
|
|
|
2017-07-17 04:23:20 +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-07-17 04:23:20 +02:00
|
|
|
# This will raise an exception because the unconfirmed transaction has been zapped
|
2019-09-25 11:34:51 +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-07-17 04:23:20 +02:00
|
|
|
ZapWalletTXesTest().main()
|