Skip to content

Commit 1077c93

Browse files
author
MarcoFalke
committed
Merge #20692: test: run mempool_resurrect.py even with wallet disabled
11a3272 test: run mempool_resurrect.py even with wallet disabled (Michael Dietz) Pull request description: Another functional test rewritten as proposed in #20078 **Request for help:** `node.gettransaction(txid)` fails for transactions sent with `wallet.send_self_transfer`. Even though the `txid`s look correct, are added to the mempool correctly, and removed from the mempool when a block is mined - all as expected. However, `node.gettransaction(txid)` throws the error: ```sh Traceback (most recent call last): File "/Users/michaeldietz/Documents/bitcoin/test/functional/test_framework/test_framework.py", line 126, in main self.run_test() File "/Users/michaeldietz/Documents/bitcoin/test/functional/mempool_resurrect.py", line 43, in run_test assert_equal(len(list(filter(lambda txid: node.gettransaction(txid)["confirmations"] > 0, spends_ids))), len(spends_ids)) File "/Users/michaeldietz/Documents/bitcoin/test/functional/mempool_resurrect.py", line 43, in <lambda> assert_equal(len(list(filter(lambda txid: node.gettransaction(txid)["confirmations"] > 0, spends_ids))), len(spends_ids)) File "/Users/michaeldietz/Documents/bitcoin/test/functional/test_framework/coverage.py", line 47, in __call__ return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs) File "/Users/michaeldietz/Documents/bitcoin/test/functional/test_framework/authproxy.py", line 146, in __call__ raise JSONRPCException(response['error'], status) test_framework.authproxy.JSONRPCException: Invalid or non-wallet transaction id (-5) ``` Anyone know what's going wrong / can point me in the right direction if I'm making a mistake, or `MiniWallet` needs to be improved for this to work correctly? ACKs for top commit: MarcoFalke: ACK 11a3272 Tree-SHA512: 13d83a13ec23920db716e99b68670e61329d1cc73b12063d85bc1679ee6425a9951da4d2e392ca1f27760be7be049ccdc6f504e192ed5cd24ed0ba003b66fab3
2 parents 68c7acf + 11a3272 commit 1077c93

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

test/functional/mempool_resurrect.py

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,59 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test resurrection of mined transactions when the blockchain is re-organized."""
66

7-
from test_framework.blocktools import create_raw_transaction
87
from test_framework.test_framework import BitcoinTestFramework
98
from test_framework.util import assert_equal
9+
from test_framework.wallet import MiniWallet
1010

1111

1212
class MempoolCoinbaseTest(BitcoinTestFramework):
1313
def set_test_params(self):
1414
self.num_nodes = 1
15-
16-
def skip_test_if_missing_module(self):
17-
self.skip_if_no_wallet()
15+
self.setup_clean_chain = True
1816

1917
def run_test(self):
20-
node0_address = self.nodes[0].getnewaddress()
18+
node = self.nodes[0]
19+
wallet = MiniWallet(node)
20+
21+
# Add enough mature utxos to the wallet so that all txs spend confirmed coins
22+
wallet.generate(3)
23+
node.generate(100)
24+
2125
# Spend block 1/2/3's coinbase transactions
22-
# Mine a block.
26+
# Mine a block
2327
# Create three more transactions, spending the spends
24-
# Mine another block.
28+
# Mine another block
2529
# ... make sure all the transactions are confirmed
2630
# Invalidate both blocks
2731
# ... make sure all the transactions are put back in the mempool
2832
# Mine a new block
29-
# ... make sure all the transactions are confirmed again.
30-
31-
b = [self.nodes[0].getblockhash(n) for n in range(1, 4)]
32-
coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b]
33-
spends1_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, amount=49.99) for txid in coinbase_txids]
34-
spends1_id = [self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw]
35-
33+
# ... make sure all the transactions are confirmed again
3634
blocks = []
37-
blocks.extend(self.nodes[0].generate(1))
38-
39-
spends2_raw = [create_raw_transaction(self.nodes[0], txid, node0_address, amount=49.98) for txid in spends1_id]
40-
spends2_id = [self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw]
35+
spends1_ids = [wallet.send_self_transfer(from_node=node)['txid'] for _ in range(3)]
36+
blocks.extend(node.generate(1))
37+
spends2_ids = [wallet.send_self_transfer(from_node=node)['txid'] for _ in range(3)]
38+
blocks.extend(node.generate(1))
4139

42-
blocks.extend(self.nodes[0].generate(1))
40+
spends_ids = set(spends1_ids + spends2_ids)
4341

4442
# mempool should be empty, all txns confirmed
45-
assert_equal(set(self.nodes[0].getrawmempool()), set())
46-
for txid in spends1_id+spends2_id:
47-
tx = self.nodes[0].gettransaction(txid)
48-
assert tx["confirmations"] > 0
43+
assert_equal(set(node.getrawmempool()), set())
44+
confirmed_txns = set(node.getblock(blocks[0])['tx'] + node.getblock(blocks[1])['tx'])
45+
# Checks that all spend txns are contained in the mined blocks
46+
assert(spends_ids < confirmed_txns)
4947

5048
# Use invalidateblock to re-org back
51-
for node in self.nodes:
52-
node.invalidateblock(blocks[0])
49+
node.invalidateblock(blocks[0])
5350

5451
# All txns should be back in mempool with 0 confirmations
55-
assert_equal(set(self.nodes[0].getrawmempool()), set(spends1_id+spends2_id))
56-
for txid in spends1_id+spends2_id:
57-
tx = self.nodes[0].gettransaction(txid)
58-
assert tx["confirmations"] == 0
52+
assert_equal(set(node.getrawmempool()), spends_ids)
5953

6054
# Generate another block, they should all get mined
61-
self.nodes[0].generate(1)
55+
node.generate(1)
6256
# mempool should be empty, all txns confirmed
63-
assert_equal(set(self.nodes[0].getrawmempool()), set())
64-
for txid in spends1_id+spends2_id:
65-
tx = self.nodes[0].gettransaction(txid)
66-
assert tx["confirmations"] > 0
57+
assert_equal(set(node.getrawmempool()), set())
58+
confirmed_txns = set(node.getblock(blocks[0])['tx'] + node.getblock(blocks[1])['tx'])
59+
assert(spends_ids < confirmed_txns)
6760

6861

6962
if __name__ == '__main__':

0 commit comments

Comments
 (0)