diff --git a/test/functional/abc-mempool-coherence-on-activations.py b/test/functional/abc-mempool-coherence-on-activations.py --- a/test/functional/abc-mempool-coherence-on-activations.py +++ b/test/functional/abc-mempool-coherence-on-activations.py @@ -25,7 +25,6 @@ create_transaction, make_conform_to_ctor, ) -from test_framework.comptool import TestInstance, TestManager from test_framework.key import CECKey from test_framework.messages import ( COIN, @@ -35,7 +34,7 @@ CTxOut, ToHex, ) -from test_framework.mininode import network_thread_start +from test_framework.mininode import network_thread_start, P2PDataStore from test_framework.script import ( CScript, OP_CHECKSIG, @@ -44,7 +43,7 @@ SIGHASH_FORKID, SignatureHashForkId, ) -from test_framework.test_framework import ComparisonTestFramework +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error @@ -121,7 +120,7 @@ self.n = n -class MempoolCoherenceOnActivationsTest(ComparisonTestFramework): +class MempoolCoherenceOnActivationsTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 @@ -132,13 +131,6 @@ self.extra_args = [['-whitelist=127.0.0.1', EXTRA_ARG]] - def run_test(self): - self.test = TestManager(self, self.options.tmpdir) - self.test.add_all_connections(self.nodes) - network_thread_start() - self.nodes[0].setmocktime(ACTIVATION_TIME) - self.test.run() - def next_block(self, number): if self.tip == None: base_block_hash = self.genesis_hash @@ -160,8 +152,14 @@ self.blocks[number] = block return block - def get_tests(self): - self.genesis_hash = int(self.nodes[0].getbestblockhash(), 16) + def run_test(self): + node = self.nodes[0] + node.add_p2p_connection(P2PDataStore()) + network_thread_start() + node.p2p.wait_for_verack() + node.setmocktime(ACTIVATION_TIME) + + self.genesis_hash = int(node.getbestblockhash(), 16) self.block_heights[self.genesis_hash] = 0 spendable_outputs = [] @@ -173,17 +171,6 @@ def get_spendable_output(): return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) - # returns a test case that asserts that the current tip was accepted - def accepted(): - return TestInstance([[self.tip, True]]) - - # returns a test case that asserts that the current tip was rejected - def rejected(reject=None): - if reject is None: - return TestInstance([[self.tip, False]]) - else: - return TestInstance([[self.tip, reject]]) - # move the tip back to a previous block def tip(number): self.tip = self.blocks[number] @@ -225,20 +212,19 @@ # shorthand block = self.next_block - node = self.nodes[0] # Create a new block block(0) save_spendable_output() - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) # Now we need that block to mature so we can spend the coinbase. - test = TestInstance(sync_every_block=False) + maturity_blocks = [] for i in range(110): block(5000 + i) - test.blocks_and_transactions.append([self.tip, True]) + maturity_blocks.append(self.tip) save_spendable_output() - yield test + node.p2p.send_blocks_and_test(maturity_blocks, node) # collect spendable outputs now to avoid cluttering the code later on out = [] @@ -259,12 +245,10 @@ bfork = block(5555) bfork.nTime = ACTIVATION_TIME - 1 update_block(5555, [txfund0, txfund1, txfund2, txfund3]) - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) for i in range(5): - block(5200 + i) - test.blocks_and_transactions.append([self.tip, True]) - yield test + node.p2p.send_blocks_and_test([block(5200 + i)], node) # Check we are just before the activation time assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], @@ -290,7 +274,7 @@ # pre-fork-only txn. block(5556) update_block(5556, [tx_chain0, tx_pre0]) - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) forkblockid = node.getbestblockhash() # Check we just activated the fork @@ -315,7 +299,7 @@ # Mine the 2nd always-valid chained txn and a post-fork-only txn. block(5557) update_block(5557, [tx_chain1, tx_post0]) - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) postforkblockid = node.getbestblockhash() # The mempool contains the 3rd chained txn and a post-fork-only txn. check_mempool_equal([tx_chain2, tx_post1]) @@ -369,13 +353,12 @@ # This starts after 5204, so it contains neither the forkblockid nor # the postforkblockid from above. tip(5204) - test = TestInstance(sync_every_block=False) + reorg_blocks = [] for i in range(3): - block(5900 + i) - test.blocks_and_transactions.append([self.tip, True]) + reorg_blocks.append(block(5900 + i)) # Perform the reorg - yield test + node.p2p.send_blocks_and_test(reorg_blocks, node) # reorg finishes after the fork assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], ACTIVATION_TIME+2)