7 Exercise the wallet backup code. Ported from walletbackup.sh. 10 4 nodes. 1 2 and 3 send transactions between each other, 11 fourth node is a miner. 12 1 2 3 each mine a block to start, then 13 Miner creates 100 blocks so 1 2 3 each have 500 mature 15 Then 5 iterations of 1/2/3 sending coins amongst 16 themselves to get transactions in the wallets, 17 and the miner mining one block. 19 Wallets are backed up using dumpwallet/backupwallet. 20 Then 5 more iterations of transactions and mining a block. 22 Miner then generates 101 more blocks, so any 23 transaction fees paid mature. 26 Sum(1,2,3,4 balances) == 114*500 28 1/2/3 are shutdown, and their wallets erased. 29 Then restore using wallet.dat backup. And 30 confirm 1/2/3/4 balances are same as before. 32 Shutdown again, restore using importwallet, 33 and confirm again balances are correct. 38 from random
import randint
40 logging.basicConfig(format=
'%(levelname)s:%(message)s', level=logging.INFO)
45 logging.info(
"Initializing test directory "+self.options.tmpdir)
51 extra_args = [[
"-keypool=100"], [
"-keypool=100"], [
"-keypool=100"], []]
61 if (randint(1,2) == 1):
62 amount = Decimal(randint(1,10)) / Decimal(10)
98 os.remove(self.options.tmpdir +
"/node0/regtest/wallet.dat")
99 os.remove(self.options.tmpdir +
"/node1/regtest/wallet.dat")
100 os.remove(self.options.tmpdir +
"/node2/regtest/wallet.dat")
103 logging.info(
"Generating initial blockchain")
118 logging.info(
"Creating transactions")
123 logging.info(
"Backing up")
124 tmpdir = self.options.tmpdir
132 logging.info(
"More transactions")
144 total = balance0 + balance1 + balance2 + balance3
153 logging.info(
"Restoring using wallet.dat")
158 shutil.rmtree(self.options.tmpdir +
"/node2/regtest/blocks")
159 shutil.rmtree(self.options.tmpdir +
"/node2/regtest/chainstate")
162 shutil.copyfile(tmpdir +
"/node0/wallet.bak", tmpdir +
"/node0/regtest/wallet.dat")
163 shutil.copyfile(tmpdir +
"/node1/wallet.bak", tmpdir +
"/node1/regtest/wallet.dat")
164 shutil.copyfile(tmpdir +
"/node2/wallet.bak", tmpdir +
"/node2/regtest/wallet.dat")
166 logging.info(
"Re-starting nodes")
174 logging.info(
"Restoring using dumped wallet")
179 shutil.rmtree(self.options.tmpdir +
"/node2/regtest/blocks")
180 shutil.rmtree(self.options.tmpdir +
"/node2/regtest/chainstate")
199 if __name__ ==
'__main__':
UniValue dumpwallet(const UniValue ¶ms, bool fHelp)
def setup_network(self, split=False)
UniValue getbalance(const UniValue ¶ms, bool fHelp)
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None)
UniValue backupwallet(const UniValue ¶ms, bool fHelp)
UniValue sendtoaddress(const UniValue ¶ms, bool fHelp)
def connect_nodes(from_connection, node_num)
UniValue getnewaddress(const UniValue ¶ms, bool fHelp)
def sync_mempools(rpc_connections, wait=1)
def initialize_chain_clean(test_dir, num_nodes)
def one_send(self, from_node, to_address)
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None)
UniValue importwallet(const UniValue ¶ms, bool fHelp)
UniValue generate(const UniValue ¶ms, bool fHelp)
def sync_blocks(rpc_connections, wait=1)
def run_test(self)
Test restoring spender wallets from backups.
def assert_equal(thing1, thing2)