diff options
author | Joao Fonseca <jpdf.fonseca@gmail.com> | 2016-04-19 12:22:11 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2016-04-19 16:37:14 +0200 |
commit | 6862627ce6bc04e68801f026629932987c3ab424 (patch) | |
tree | cbac56de6ad52eebe40e23048a8e3293c6f2ad9d /qa/rpc-tests/wallet.py | |
parent | 28ba22c20209c88a6a903729d3935e836ed0cf1a (diff) | |
download | bitcoin-6862627ce6bc04e68801f026629932987c3ab424.tar.xz |
Add listunspent() test for spendable/unspendable UTXO
Github-Pull: #7822
Rebased-From: fa942c755ab513829dcab27487ba1e7ab5a806ee 5d217decc1145823a3c126658c82c60cf7dbfec8
Diffstat (limited to 'qa/rpc-tests/wallet.py')
-rwxr-xr-x | qa/rpc-tests/wallet.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 3cf0261f13..fd28651678 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -32,6 +32,12 @@ class WalletTest (BitcoinTestFramework): self.sync_all() def run_test (self): + + # Check that there's no UTXO on none of the nodes + assert_equal(len(self.nodes[0].listunspent()), 0) + assert_equal(len(self.nodes[1].listunspent()), 0) + assert_equal(len(self.nodes[2].listunspent()), 0) + print "Mining blocks..." self.nodes[0].generate(1) @@ -48,6 +54,11 @@ class WalletTest (BitcoinTestFramework): assert_equal(self.nodes[1].getbalance(), 50) assert_equal(self.nodes[2].getbalance(), 0) + # Check that only first and second nodes have UTXOs + assert_equal(len(self.nodes[0].listunspent()), 1) + assert_equal(len(self.nodes[1].listunspent()), 1) + assert_equal(len(self.nodes[2].listunspent()), 0) + # Send 21 BTC from 0 to 2 using sendtoaddress call. # Second transaction will be child of first, and will require a fee self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11) @@ -260,6 +271,32 @@ class WalletTest (BitcoinTestFramework): except JSONRPCException as e: assert("not an integer" in e.error['message']) + # Import address and private key to check correct behavior of spendable unspents + # 1. Send some coins to generate new UTXO + address_to_import = self.nodes[2].getnewaddress() + txid = self.nodes[0].sendtoaddress(address_to_import, 1) + self.nodes[0].generate(1) + self.sync_all() + + # 2. Import address from node2 to node1 + self.nodes[1].importaddress(address_to_import) + + # 3. Validate that the imported address is watch-only on node1 + assert(self.nodes[1].validateaddress(address_to_import)["iswatchonly"]) + + # 4. Check that the unspents after import are not spendable + assert_array_result(self.nodes[1].listunspent(), + {"address": address_to_import}, + {"spendable": False}) + + # 5. Import private key of the previously imported address on node1 + priv_key = self.nodes[2].dumpprivkey(address_to_import) + self.nodes[1].importprivkey(priv_key) + + # 6. Check that the unspents are now spendable on node1 + assert_array_result(self.nodes[1].listunspent(), + {"address": address_to_import}, + {"spendable": True}) #check if wallet or blochchain maintenance changes the balance self.sync_all() |