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")
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.")
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:
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.")
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 ?
wallet.py.
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):
test_framework/util.py, so the utility function can be used in other tests as well?
test_framework/util.py to be reused whenever needed..
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.
joaopaulofonseca
MarcoFalke
laanwj
Labels
Tests