Test gettxout as part of the wallet test. Sanity-checks the utxo generated from coinbase.
[test] Add test for gettxout to wallet.py #10256
pull jimmysong wants to merge 1 commits into bitcoin:master from jimmysong:test_gettxout changing 1 files +24 −4-
jimmysong commented at 1:11 AM on April 22, 2017: contributor
- fanquake added the label Tests on Apr 22, 2017
- jimmysong renamed this:
[test] Add gettxout call to wallet.py
[test] Add test for gettxout to wallet.py
on Apr 22, 2017 -
TheBlueMatt commented at 12:45 AM on April 26, 2017: member
utACK. It would be cool to also test the include_mempool flag to gettxout to check that a) things which are spent in the mempool arent visible via gettxout (even though they are without include_mempool) and b) things which are only available in the mempool are inversely visible.
- jimmysong force-pushed on Apr 26, 2017
-
jimmysong commented at 1:24 AM on April 26, 2017: contributor
@TheBlueMatt Thank you for your excellent suggestion. I've made the changes as you suggested, squashed and rebased.
- jimmysong force-pushed on Apr 26, 2017
-
in test/functional/wallet.py:64 in 697af1899a outdated
61 | # Send 21 BTC from 0 to 2 using sendtoaddress call. 62 | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11) 63 | - self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10) 64 | + mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10) 65 | + 66 | + # test gettxout
jnewbery commented at 9:28 PM on April 28, 2017:nit: my personal preference is to make this kind of 'heading' comment into a log, so test runners have some feedback as they're running the test.
in test/functional/wallet.py:65 in 697af1899a outdated
62 | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11) 63 | - self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10) 64 | + mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10) 65 | + 66 | + # test gettxout 67 | + # confirmed tx should be visible if you exclude mempool
jnewbery commented at 9:29 PM on April 28, 2017:This comment isn't quite right. We're not looking at a confirmed transaction here, we're looking at a transaction output who's spend is unconfirmed. That's why if include_mempool is set to False, we still think we own this output
in test/functional/wallet.py:71 in 697af1899a outdated
68 | + # but invisible if you include mempool 69 | + confirmed_txid, confirmed_index = utxos[0]["txid"], utxos[0]["vout"] 70 | + txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, False) 71 | + assert_equal(txout['value'], 50) 72 | + txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, True) 73 | + assert(txout is None)
jnewbery commented at 9:31 PM on April 28, 2017:no need for brackets here. assert is a statement, not a function.
This should just be:
assert not txoutin test/functional/wallet.py:81 in 697af1899a outdated
78 | + assert(txout is None) 79 | + txout = self.nodes[0].gettxout(mempool_txid, mempool_index, True) 80 | + # note the mempool tx will have randomly assigned indices 81 | + # but 10 will go to node2 and the rest will go to node0 82 | + balance = self.nodes[0].getbalance() 83 | + assert(txout['value'] in (10, balance))
jnewbery commented at 9:34 PM on April 28, 2017:I think the intent is clearer if you collect both txouts above, and then test that one of them is equal to 10 and the other is equal to balance. Something like:
txout0 = self.nodes[0].gettxout(mempool_txid, 0, True) txout1 = self.nodes[0].gettxout(mempool_txid, 1, True) balance = self.nodes[0].getbalance() assert_equal(set(10, balance), set(txout0['value'], txout1['value']))
jimmysong commented at 9:49 PM on April 28, 2017:good idea
in test/functional/wallet.py:68 in 697af1899a outdated
65 | + 66 | + # test gettxout 67 | + # confirmed tx should be visible if you exclude mempool 68 | + # but invisible if you include mempool 69 | + confirmed_txid, confirmed_index = utxos[0]["txid"], utxos[0]["vout"] 70 | + txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, False)
jnewbery commented at 9:36 PM on April 28, 2017:consider using named arguments when the positional arguments are just bools. It makes it difficult for the reader to know what the argument is for (alright, I know you've explained it in the comment above, but the reader still needs to trust that you're right!)
jnewbery commented at 9:36 PM on April 28, 2017: memberGreat. Thanks for adding this.
A few nits, but otherwise looks good.
dd1ea59624[test] Add gettxout call
Test gettxout as part of the wallet test. Tests gettxout with a confirmed/unconfirmed tx with include_mempool flag on and off
jimmysong force-pushed on Apr 28, 2017jimmysong commented at 9:54 PM on April 28, 2017: contributornits addressed, rebased and squashed.
in test/functional/wallet.py:77 in dd1ea59624
74 | + # new utxo from mempool should be invisible if you exclude mempool 75 | + # but visible if you include mempool 76 | + txout = self.nodes[0].gettxout(mempool_txid, 0, False) 77 | + assert txout is None 78 | + txout1 = self.nodes[0].gettxout(mempool_txid, 0, True) 79 | + txout2 = self.nodes[0].gettxout(mempool_txid, 1, True)
MarcoFalke commented at 12:45 PM on April 29, 2017:nit: In the future you might use named args for arguments that are unnamed boolean or integers of a function that takes more than one arg.
gettxout(txid=mempool_txid, n=1,include_mempool= True)MarcoFalke merged this on Apr 29, 2017MarcoFalke closed this on Apr 29, 2017MarcoFalke referenced this in commit 80c3a73429 on Apr 29, 2017attilaaf referenced this in commit 9184637847 on May 25, 2019PastaPastaPasta referenced this in commit 966026f79c on Jun 10, 2019PastaPastaPasta referenced this in commit 07ac9dd3ad on Jun 10, 2019PastaPastaPasta referenced this in commit 5326f5b920 on Jun 11, 2019PastaPastaPasta referenced this in commit 9aa09e76d2 on Jun 11, 2019PastaPastaPasta referenced this in commit ac4da7526f on Jun 12, 2019PastaPastaPasta referenced this in commit d6161e8ce9 on Jun 14, 2019PastaPastaPasta referenced this in commit 8013d853f9 on Jun 14, 2019PastaPastaPasta referenced this in commit c2dd5cd339 on Jun 14, 2019PastaPastaPasta referenced this in commit 6093282c50 on Jun 15, 2019PastaPastaPasta referenced this in commit e668b88fc0 on Jun 19, 2019barrystyle referenced this in commit dc093d8b2c on Jan 22, 2020MarcoFalke locked this on Sep 8, 2021ContributorsLabels
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-27 15:16 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me