]> Git Repo - VerusCoin.git/blob - qa/rpc-tests/wallet_persistence.py
Make pythonisms consistent
[VerusCoin.git] / qa / rpc-tests / wallet_persistence.py
1 #!/usr/bin/env python
2 # Copyright (c) 2018 The Zcash developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 import sys; assert sys.version_info < (3,), ur"This script does not run under Python 3. Please use Python 2.7.x."
7
8 from test_framework.test_framework import BitcoinTestFramework
9 from test_framework.util import (
10     assert_equal, assert_true,
11     start_nodes, stop_nodes,
12     initialize_chain_clean, connect_nodes_bi, wait_bitcoinds,
13     wait_and_assert_operationid_status
14 )
15 from decimal import Decimal
16
17 class WalletPersistenceTest (BitcoinTestFramework):
18
19     def setup_chain(self):
20         print("Initializing test directory " + self.options.tmpdir)
21         initialize_chain_clean(self.options.tmpdir, 3)
22
23     def setup_network(self, split=False):
24         self.nodes = start_nodes(3, self.options.tmpdir,
25             extra_args=[[
26                 '-nuparams=5ba81b19:100', # Overwinter
27                 '-nuparams=76b809bb:201', # Sapling
28             ]] * 3)
29         connect_nodes_bi(self.nodes,0,1)
30         connect_nodes_bi(self.nodes,1,2)
31         self.is_network_split=False
32         self.sync_all()
33
34     def run_test(self):
35         # Sanity-check the test harness
36         self.nodes[0].generate(200)
37         assert_equal(self.nodes[0].getblockcount(), 200)
38         self.sync_all()
39
40         # Verify Sapling address is persisted in wallet (even when Sapling is not yet active)
41         sapling_addr = self.nodes[0].z_getnewaddress('sapling')
42
43         # Make sure the node has the addresss
44         addresses = self.nodes[0].z_listaddresses()
45         assert_true(sapling_addr in addresses, "Should contain address before restart")
46
47         # Restart the nodes
48         stop_nodes(self.nodes)
49         wait_bitcoinds()
50         self.setup_network()
51
52         # Make sure we still have the address after restarting
53         addresses = self.nodes[0].z_listaddresses()
54         assert_true(sapling_addr in addresses, "Should contain address after restart")
55
56         # Activate Sapling
57         self.nodes[0].generate(1)
58         self.sync_all()
59
60         # Node 0 shields funds to Sapling address
61         taddr0 = self.nodes[0].getnewaddress()
62         recipients = []
63         recipients.append({"address": sapling_addr, "amount": Decimal('20')})
64         myopid = self.nodes[0].z_sendmany(taddr0, recipients, 1, 0)
65         wait_and_assert_operationid_status(self.nodes[0], myopid)
66
67         self.sync_all()
68         self.nodes[0].generate(1)
69         self.sync_all()
70
71         # Verify shielded balance
72         assert_equal(self.nodes[0].z_getbalance(sapling_addr), Decimal('20'))
73
74         # Verify size of shielded pools
75         pools = self.nodes[0].getblockchaininfo()['valuePools']
76         assert_equal(pools[0]['chainValue'], Decimal('0'))  # Sprout
77         assert_equal(pools[1]['chainValue'], Decimal('20')) # Sapling
78
79         # Restart the nodes
80         stop_nodes(self.nodes)
81         wait_bitcoinds()
82         self.setup_network()
83
84         # Verify size of shielded pools
85         pools = self.nodes[0].getblockchaininfo()['valuePools']
86         assert_equal(pools[0]['chainValue'], Decimal('0'))  # Sprout
87         assert_equal(pools[1]['chainValue'], Decimal('20')) # Sapling
88
89         # Node 0 sends some shielded funds to Node 1
90         dest_addr = self.nodes[1].z_getnewaddress('sapling')
91         recipients = []
92         recipients.append({"address": dest_addr, "amount": Decimal('15')})
93         myopid = self.nodes[0].z_sendmany(sapling_addr, recipients, 1, 0)
94         wait_and_assert_operationid_status(self.nodes[0], myopid)
95
96         self.sync_all()
97         self.nodes[0].generate(1)
98         self.sync_all()
99
100         # Verify balances
101         assert_equal(self.nodes[0].z_getbalance(sapling_addr), Decimal('5'))
102         assert_equal(self.nodes[1].z_getbalance(dest_addr), Decimal('15'))
103
104         # Restart the nodes
105         stop_nodes(self.nodes)
106         wait_bitcoinds()
107         self.setup_network()
108
109         # Verify balances
110         assert_equal(self.nodes[0].z_getbalance(sapling_addr), Decimal('5'))
111         assert_equal(self.nodes[1].z_getbalance(dest_addr), Decimal('15'))
112
113         # Verify importing a spending key will update and persist the nullifiers and witnesses correctly
114         sk0 = self.nodes[0].z_exportkey(sapling_addr)
115         self.nodes[2].z_importkey(sk0, "yes")
116         assert_equal(self.nodes[2].z_getbalance(sapling_addr), Decimal('5'))
117
118         # Restart the nodes
119         stop_nodes(self.nodes)
120         wait_bitcoinds()
121         self.setup_network()
122
123         # Verify nullifiers persisted correctly by checking balance
124         # Prior to PR #3590, there will be an error as spent notes are considered unspent:
125         #    Assertion failed: expected: <25.00000000> but was: <5>
126         assert_equal(self.nodes[2].z_getbalance(sapling_addr), Decimal('5'))
127
128         # Verity witnesses persisted correctly by sending shielded funds
129         recipients = []
130         recipients.append({"address": dest_addr, "amount": Decimal('1')})
131         myopid = self.nodes[2].z_sendmany(sapling_addr, recipients, 1, 0)
132         wait_and_assert_operationid_status(self.nodes[2], myopid)
133
134         self.sync_all()
135         self.nodes[0].generate(1)
136         self.sync_all()
137
138         # Verify balances
139         assert_equal(self.nodes[2].z_getbalance(sapling_addr), Decimal('4'))
140         assert_equal(self.nodes[1].z_getbalance(dest_addr), Decimal('16'))
141
142 if __name__ == '__main__':
143     WalletPersistenceTest().main()
This page took 0.032106 seconds and 4 git commands to generate.