diff --git a/test/functional/abc-replay-protection.py b/test/functional/abc-replay-protection.py --- a/test/functional/abc-replay-protection.py +++ b/test/functional/abc-replay-protection.py @@ -17,7 +17,6 @@ create_transaction, make_conform_to_ctor, ) -from test_framework.comptool import RejectResult, TestInstance, TestManager from test_framework.key import CECKey from test_framework.messages import ( COIN, @@ -27,7 +26,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, @@ -36,7 +35,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 # far into the future @@ -53,7 +52,7 @@ self.n = n -class ReplayProtectionTest(ComparisonTestFramework): +class ReplayProtectionTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 @@ -64,13 +63,6 @@ self.extra_args = [['-whitelist=127.0.0.1', "-replayprotectionactivationtime={}".format(REPLAY_PROTECTION_START_TIME)]] - 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(REPLAY_PROTECTION_START_TIME) - self.test.run() - def next_block(self, number): if self.tip == None: base_block_hash = self.genesis_hash @@ -92,8 +84,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(REPLAY_PROTECTION_START_TIME) + + self.genesis_hash = int(node.getbestblockhash(), 16) self.block_heights[self.genesis_hash] = 0 spendable_outputs = [] @@ -105,17 +103,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] @@ -139,20 +126,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(99): 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 = [] @@ -201,7 +187,7 @@ # And txns get mined in a block properly. block(1) update_block(1, txns) - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) # Replay protected transactions are rejected. replay_txns = create_fund_and_spend_tx(out[1], 0xffdead) @@ -212,7 +198,8 @@ # And block containing them are rejected as well. block(2) update_block(2, replay_txns) - yield rejected(RejectResult(16, b'blk-bad-inputs')) + node.p2p.send_blocks_and_test( + [self.tip], node, success=False, reject_reason='blk-bad-inputs') # Rewind bad block tip(1) @@ -221,12 +208,13 @@ bfork = block(5555) bfork.nTime = REPLAY_PROTECTION_START_TIME - 1 update_block(5555, []) - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) + activation_blocks = [] for i in range(5): block(5100 + i) - test.blocks_and_transactions.append([self.tip, True]) - yield test + activation_blocks.append(self.tip) + node.p2p.send_blocks_and_test(activation_blocks, node) # Check we are just before the activation time assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], @@ -238,7 +226,8 @@ block(3) update_block(3, replay_txns) - yield rejected(RejectResult(16, b'blk-bad-inputs')) + node.p2p.send_blocks_and_test( + [self.tip], node, success=False, reject_reason='blk-bad-inputs') # Rewind bad block tip(5104) @@ -251,7 +240,7 @@ # Activate the replay protection block(5556) - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) # Check we just activated the replay protection assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], @@ -269,7 +258,8 @@ # They also cannot be mined block(4) update_block(4, txns) - yield rejected(RejectResult(16, b'blk-bad-inputs')) + node.p2p.send_blocks_and_test( + [self.tip], node, success=False, reject_reason='blk-bad-inputs') # Rewind bad block tip(5556) @@ -300,7 +290,7 @@ # They also can also be mined block(5) update_block(5, replay_txns) - yield accepted() + node.p2p.send_blocks_and_test([self.tip], node) # Ok, now we check if a reorg work properly across the activation. postforkblockid = node.getbestblockhash()