[tests] Add -blocknotify functional test
[bitcoinplatinum.git] / test / functional / importprunedfunds.py
blob068052409af99a363488897d6ca7c8843d8a02e6
1 #!/usr/bin/env python3
2 # Copyright (c) 2014-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test the importprunedfunds and removeprunedfunds RPCs."""
6 from test_framework.test_framework import BitcoinTestFramework
7 from test_framework.util import *
9 class ImportPrunedFundsTest(BitcoinTestFramework):
10 def set_test_params(self):
11 self.setup_clean_chain = True
12 self.num_nodes = 2
14 def run_test(self):
15 self.log.info("Mining blocks...")
16 self.nodes[0].generate(101)
18 self.sync_all()
20 # address
21 address1 = self.nodes[0].getnewaddress()
22 # pubkey
23 address2 = self.nodes[0].getnewaddress()
24 # privkey
25 address3 = self.nodes[0].getnewaddress()
26 address3_privkey = self.nodes[0].dumpprivkey(address3) # Using privkey
28 #Check only one address
29 address_info = self.nodes[0].validateaddress(address1)
30 assert_equal(address_info['ismine'], True)
32 self.sync_all()
34 #Node 1 sync test
35 assert_equal(self.nodes[1].getblockcount(),101)
37 #Address Test - before import
38 address_info = self.nodes[1].validateaddress(address1)
39 assert_equal(address_info['iswatchonly'], False)
40 assert_equal(address_info['ismine'], False)
42 address_info = self.nodes[1].validateaddress(address2)
43 assert_equal(address_info['iswatchonly'], False)
44 assert_equal(address_info['ismine'], False)
46 address_info = self.nodes[1].validateaddress(address3)
47 assert_equal(address_info['iswatchonly'], False)
48 assert_equal(address_info['ismine'], False)
50 #Send funds to self
51 txnid1 = self.nodes[0].sendtoaddress(address1, 0.1)
52 self.nodes[0].generate(1)
53 rawtxn1 = self.nodes[0].gettransaction(txnid1)['hex']
54 proof1 = self.nodes[0].gettxoutproof([txnid1])
56 txnid2 = self.nodes[0].sendtoaddress(address2, 0.05)
57 self.nodes[0].generate(1)
58 rawtxn2 = self.nodes[0].gettransaction(txnid2)['hex']
59 proof2 = self.nodes[0].gettxoutproof([txnid2])
61 txnid3 = self.nodes[0].sendtoaddress(address3, 0.025)
62 self.nodes[0].generate(1)
63 rawtxn3 = self.nodes[0].gettransaction(txnid3)['hex']
64 proof3 = self.nodes[0].gettxoutproof([txnid3])
66 self.sync_all()
68 #Import with no affiliated address
69 assert_raises_rpc_error(-5, "No addresses", self.nodes[1].importprunedfunds, rawtxn1, proof1)
71 balance1 = self.nodes[1].getbalance("", 0, True)
72 assert_equal(balance1, Decimal(0))
74 #Import with affiliated address with no rescan
75 self.nodes[1].importaddress(address2, "add2", False)
76 self.nodes[1].importprunedfunds(rawtxn2, proof2)
77 balance2 = self.nodes[1].getbalance("add2", 0, True)
78 assert_equal(balance2, Decimal('0.05'))
80 #Import with private key with no rescan
81 self.nodes[1].importprivkey(privkey=address3_privkey, label="add3", rescan=False)
82 self.nodes[1].importprunedfunds(rawtxn3, proof3)
83 balance3 = self.nodes[1].getbalance("add3", 0, False)
84 assert_equal(balance3, Decimal('0.025'))
85 balance3 = self.nodes[1].getbalance("*", 0, True)
86 assert_equal(balance3, Decimal('0.075'))
88 #Addresses Test - after import
89 address_info = self.nodes[1].validateaddress(address1)
90 assert_equal(address_info['iswatchonly'], False)
91 assert_equal(address_info['ismine'], False)
92 address_info = self.nodes[1].validateaddress(address2)
93 assert_equal(address_info['iswatchonly'], True)
94 assert_equal(address_info['ismine'], False)
95 address_info = self.nodes[1].validateaddress(address3)
96 assert_equal(address_info['iswatchonly'], False)
97 assert_equal(address_info['ismine'], True)
99 #Remove transactions
100 assert_raises_rpc_error(-8, "Transaction does not exist in wallet.", self.nodes[1].removeprunedfunds, txnid1)
102 balance1 = self.nodes[1].getbalance("*", 0, True)
103 assert_equal(balance1, Decimal('0.075'))
105 self.nodes[1].removeprunedfunds(txnid2)
106 balance2 = self.nodes[1].getbalance("*", 0, True)
107 assert_equal(balance2, Decimal('0.025'))
109 self.nodes[1].removeprunedfunds(txnid3)
110 balance3 = self.nodes[1].getbalance("*", 0, True)
111 assert_equal(balance3, Decimal('0.0'))
113 if __name__ == '__main__':
114 ImportPrunedFundsTest().main()