Skip to content

Commit 80c3a73

Browse files
author
MarcoFalke
committed
Merge #10256: [test] Add test for gettxout to wallet.py
dd1ea59 [test] Add gettxout call (Jimmy Song) Tree-SHA512: 5cea3763de30ec09b6e28b5a0c70f44d0c72a5b6ce159fdc95c1d43689ccfd21a32002d075c47cf011f66e505d9b97ea679c7c8825081a078543472e3e5083fb
2 parents 4c92401 + dd1ea59 commit 80c3a73

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

test/functional/wallet.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from test_framework.test_framework import BitcoinTestFramework
77
from test_framework.util import *
88

9-
class WalletTest (BitcoinTestFramework):
9+
class WalletTest(BitcoinTestFramework):
1010

1111
def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
1212
"""Return curr_balance after asserting the fee was in range"""
@@ -28,7 +28,7 @@ def setup_network(self, split=False):
2828
self.is_network_split=False
2929
self.sync_all()
3030

31-
def run_test (self):
31+
def run_test(self):
3232

3333
# Check that there's no UTXO on none of the nodes
3434
assert_equal(len(self.nodes[0].listunspent()), 0)
@@ -52,13 +52,33 @@ def run_test (self):
5252
assert_equal(self.nodes[2].getbalance(), 0)
5353

5454
# Check that only first and second nodes have UTXOs
55-
assert_equal(len(self.nodes[0].listunspent()), 1)
55+
utxos = self.nodes[0].listunspent()
56+
assert_equal(len(utxos), 1)
5657
assert_equal(len(self.nodes[1].listunspent()), 1)
5758
assert_equal(len(self.nodes[2].listunspent()), 0)
5859

5960
# Send 21 BTC from 0 to 2 using sendtoaddress call.
6061
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
61-
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
62+
mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
63+
64+
self.log.info("test gettxout")
65+
# utxo spent in mempool should be visible if you exclude mempool
66+
# but invisible if you include mempool
67+
confirmed_txid, confirmed_index = utxos[0]["txid"], utxos[0]["vout"]
68+
txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, False)
69+
assert_equal(txout['value'], 50)
70+
txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, True)
71+
assert txout is None
72+
# new utxo from mempool should be invisible if you exclude mempool
73+
# but visible if you include mempool
74+
txout = self.nodes[0].gettxout(mempool_txid, 0, False)
75+
assert txout is None
76+
txout1 = self.nodes[0].gettxout(mempool_txid, 0, True)
77+
txout2 = self.nodes[0].gettxout(mempool_txid, 1, True)
78+
# note the mempool tx will have randomly assigned indices
79+
# but 10 will go to node2 and the rest will go to node0
80+
balance = self.nodes[0].getbalance()
81+
assert_equal(set([txout1['value'], txout2['value']]), set([10, balance]))
6282

6383
walletinfo = self.nodes[0].getwalletinfo()
6484
assert_equal(walletinfo['immature_balance'], 0)

0 commit comments

Comments
 (0)