Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Add listunspent() test for spendable/unspendable UTXO #7822
Conversation
laanwj
added
the
Tests
label
Apr 6, 2016
joaopaulofonseca
referenced this pull request
in uphold/bitcoin
Apr 6, 2016
Closed
Added test to listunspent RPC #7
MarcoFalke
commented on an outdated diff
Apr 6, 2016
| + # since the only available UTXO was spent, there sould be none after the transaction | ||
| + assert_equal(len(self.nodes[0].listunspent()), 0) | ||
| + | ||
| + # mine one more block to generate some more UTXOs | ||
| + self.nodes[0].generate(1) | ||
| + self.sync_all() | ||
| + | ||
| + # list unspents after the transaction | ||
| + list_unspent_after = self.nodes[0].listunspent() | ||
| + | ||
| + # retrieve that transaction and check if the transaction inputs are not among the unspents | ||
| + rawtx = self.nodes[0].getrawtransaction(txid, 1) | ||
| + for txin in rawtx["vin"]: | ||
| + for utxo in list_unspent_after: | ||
| + if (txin["txid"] == utxo["txid"] and txin["vout"] == utxo["vout"]): | ||
| + raise AssertionError("Fount used output on UTXOs list") |
|
|
MarcoFalke
commented on an outdated diff
Apr 6, 2016
| + assert_equal(len(self.nodes[1].listunspent()), 0) | ||
| + | ||
| + # import address from another node | ||
| + self.nodes[1].importaddress(send_to_address) | ||
| + | ||
| + # making sure this address is watch-only | ||
| + assert(self.nodes[1].validateaddress(send_to_address)["iswatchonly"]) | ||
| + | ||
| + # there should be only one unspendable unspent, from the imported address | ||
| + assert_equal(len(self.nodes[1].listunspent()), 1) | ||
| + assert(not self.nodes[1].listunspent()[0]["spendable"]) | ||
| + | ||
| + try: | ||
| + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1) | ||
| + except JSONRPCException: | ||
| + print("Impossible to send coins. Available output is unspendable.") |
|
|
MarcoFalke
commented on an outdated diff
Apr 6, 2016
| + ####################################################################### | ||
| + # Test case 3 # | ||
| + # Import private key and check for updated unspents (now spendable) # | ||
| + ####################################################################### | ||
| + | ||
| + # import private key, so this node can spend the available UTXO | ||
| + priv_key = self.nodes[2].dumpprivkey(send_to_address) | ||
| + self.nodes[1].importprivkey(priv_key) | ||
| + | ||
| + # there should be only one spendable unspent, after importing private key | ||
| + assert_equal(len(self.nodes[1].listunspent()), 1) | ||
| + assert(self.nodes[1].listunspent()[0]["spendable"]) | ||
| + | ||
| + try: | ||
| + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 0.1) | ||
| + except JSONRPCException, e: |
|
|
MarcoFalke
and 1 other
commented on an outdated diff
Apr 6, 2016
| + # Test case 3 # | ||
| + # Import private key and check for updated unspents (now spendable) # | ||
| + ####################################################################### | ||
| + | ||
| + # import private key, so this node can spend the available UTXO | ||
| + priv_key = self.nodes[2].dumpprivkey(send_to_address) | ||
| + self.nodes[1].importprivkey(priv_key) | ||
| + | ||
| + # there should be only one spendable unspent, after importing private key | ||
| + assert_equal(len(self.nodes[1].listunspent()), 1) | ||
| + assert(self.nodes[1].listunspent()[0]["spendable"]) | ||
| + | ||
| + try: | ||
| + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 0.1) | ||
| + except JSONRPCException, e: | ||
| + raise AssertionError("Not possible to send coins. Possible unsufficient funds.") |
MarcoFalke
Member
|
|
Thanks, Concept ACK. |
joaopaulofonseca
changed the title from
[qa] Add test to RPC listunspent
to
Add test to RPC listunspent
Apr 7, 2016
|
I'm a bit divided whether I should propose to add this into the wallet test, which already uses |
I think such overhead is rather small. (Note that disablewallet.py runs in less than a second) The overhead probably is caused by setting up the bidirectional connections and sync_all() calls. I have not yet looked closely at the test (I try to avoid large diffs right now in the /qa subfolder as each patch may or may not silently conflict with the python3 refactoring work.) @jpdffonseca Would you mind to take a look if this can be neatly squashed into the wallet.py test, as suggested by @laanwj ? |
|
@MarcoFalke and @laanwj yes that makes sense. I will try to squash this verifications into |
joaopaulofonseca
changed the title from
Add test to RPC listunspent
to
Add wallet test to check spendable/unspendable UTXO on RPC listunspent
Apr 18, 2016
|
@MarcoFalke, after checking that |
joaopaulofonseca
changed the title from
Add wallet test to check spendable/unspendable UTXO on RPC listunspent
to
Add listunspent test for spendable/unspendable UTXO
Apr 18, 2016
joaopaulofonseca
changed the title from
Add listunspent test for spendable/unspendable UTXO
to
Add listunspent() test for spendable/unspendable UTXO
Apr 18, 2016
|
Thanks. Looks better now. utACK 3b2eedc |
MarcoFalke
and 2 others
commented on an outdated diff
Apr 18, 2016
| @@ -6,6 +6,27 @@ | ||
| from test_framework.test_framework import BitcoinTestFramework | ||
| from test_framework.util import * | ||
| +def check_array_result(object_array, to_match, expected): |
MarcoFalke
Member
|
joaopaulofonseca
added some commits
Apr 19, 2016
|
Moved I noticed that the previous method on |
|
utACK 5d217de |
joaopaulofonseca commentedApr 6, 2016
•
Edited 1 time
-
joaopaulofonseca
Apr 18, 2016
This PR adds a test on
wallet.pycovering the behavior of spendable/unspendable value for UTXO, when calling RPClistunspent.This value should be different for address or private key import.