This PR adds a test on wallet.py covering the behavior of spendable/unspendable value for UTXO, when calling RPC listunspent.
This value should be different for address or private key import.
This PR adds a test on wallet.py covering the behavior of spendable/unspendable value for UTXO, when calling RPC listunspent.
This value should be different for address or private key import.
63 | + # retrieve that transaction and check if the transaction inputs are not among the unspents 64 | + rawtx = self.nodes[0].getrawtransaction(txid, 1) 65 | + for txin in rawtx["vin"]: 66 | + for utxo in list_unspent_after: 67 | + if (txin["txid"] == utxo["txid"] and txin["vout"] == utxo["vout"]): 68 | + raise AssertionError("Fount used output on UTXOs list")
Nit: typo
87 | + assert(not self.nodes[1].listunspent()[0]["spendable"]) 88 | + 89 | + try: 90 | + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1) 91 | + except JSONRPCException: 92 | + print("Impossible to send coins. Available output is unspendable.")
You may want to try assert_raises instead.
105 | + assert_equal(len(self.nodes[1].listunspent()), 1) 106 | + assert(self.nodes[1].listunspent()[0]["spendable"]) 107 | + 108 | + try: 109 | + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 0.1) 110 | + except JSONRPCException, e:
Please use py3 syntax here: as e:
106 | + assert(self.nodes[1].listunspent()[0]["spendable"]) 107 | + 108 | + try: 109 | + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 0.1) 110 | + except JSONRPCException, e: 111 | + raise AssertionError("Not possible to send coins. Possible unsufficient funds.")
Nit: No need to shadow the original exception. You can just remove the try-except block altogether and only leave the sendtoaddress
Thanks for the tips. Fixed and rebased.
Thanks, Concept ACK.
I'm a bit divided whether I should propose to add this into the wallet test, which already uses listunspent. This currently adds some startup/teardown overhead (test takes ~9 seconds) just to test one call.
I don't feel strongly about that though.
What do you think @MarcoFalke?
startup/teardown overhead
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 wallet.py.
@MarcoFalke, after checking that wallet.py already covers some of the tests for listuspent(), I discarded the separate test file and merged the tests regarding the import of bitcoin addresses and private keys into wallet.py. The test execution time should remain the same.
Thanks. Looks better now.
utACK 3b2eedc
5 | @@ -6,6 +6,27 @@ 6 | from test_framework.test_framework import BitcoinTestFramework 7 | from test_framework.util import * 8 | 9 | +def check_array_result(object_array, to_match, expected):
If you copied this function from elsewhere, wouldn't it make sense to move it instead to test_framework/util.py, so the utility function can be used in other tests as well?
Indeed.. It is used by multiple tests. I think it comes in handy for current and future test cases. If you guys agree I guess this could be moved to test_framework/util.py to be reused whenever needed..
Sure, go ahead.
Do you intend to do so in this pull? If so I'll wait with merging.
Yes, since we are on this topic.
Moved assert_array_result() to test_framework/util.py.
I noticed that the previous method on receivedby.py had a bug when using the flag should_not_find.
If the flag is set to True, the validation wouldn't work correctly when the values passed as to_match are indeed found inside object_array, and no assertion is raised.
utACK 5d217de