MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / run_test

Method run_test

test/functional/mempool_resurrect.py:19–66  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

17 self.skip_if_no_wallet()
18
19 def run_test(self):
20 node0_address = self.nodes[0].getnewaddress()
21 # Spend block 1/2/3's coinbase transactions
22 # Mine a block.
23 # Create three more transactions, spending the spends
24 # Mine another block.
25 # ... make sure all the transactions are confirmed
26 # Invalidate both blocks
27 # ... make sure all the transactions are put back in the mempool
28 # 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
36 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]
41
42 blocks.extend(self.nodes[0].generate(1))
43
44 # 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)
49
50 # Use invalidateblock to re-org back
51 for node in self.nodes:
52 node.invalidateblock(blocks[0])
53
54 # 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)
59
60 # Generate another block, they should all get mined
61 self.nodes[0].generate(1)
62 # 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)
67
68
69if __name__ == '__main__':

Callers

nothing calls this directly

Calls 2

create_raw_transactionFunction · 0.90
assert_equalFunction · 0.90

Tested by

no test coverage detected