Skip to content

Commit 95e2e9a

Browse files
committed
[tests] Change invalidtxrequest to use BitcoinTestFramework
1 parent 359d067 commit 95e2e9a

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

test/functional/p2p_invalid_tx.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,49 @@
55
"""Test node responses to invalid transactions.
66
77
In this test we connect to one node over p2p, and test tx requests."""
8-
import time
9-
108
from test_framework.blocktools import create_block, create_coinbase, create_transaction
11-
from test_framework.comptool import RejectResult, TestInstance, TestManager
129
from test_framework.messages import COIN
13-
from test_framework.mininode import network_thread_start
14-
from test_framework.test_framework import ComparisonTestFramework
10+
from test_framework.mininode import network_thread_start, P2PDataStore
11+
from test_framework.test_framework import BitcoinTestFramework
1512

16-
class InvalidTxRequestTest(ComparisonTestFramework):
13+
class InvalidTxRequestTest(BitcoinTestFramework):
1714

1815
def set_test_params(self):
1916
self.num_nodes = 1
2017
self.setup_clean_chain = True
18+
self.extra_args = [["-whitelist=127.0.0.1"]]
2119

2220
def run_test(self):
23-
test = TestManager(self, self.options.tmpdir)
24-
test.add_all_connections(self.nodes)
25-
self.tip = None
26-
self.block_time = None
21+
# Add p2p connection to node0
22+
node = self.nodes[0] # convenience reference to the node
23+
node.add_p2p_connection(P2PDataStore())
24+
2725
network_thread_start()
28-
test.run()
26+
node.p2p.wait_for_verack()
2927

30-
def get_tests(self):
31-
self.tip = int("0x" + self.nodes[0].getbestblockhash(), 0)
32-
self.block_time = int(time.time()) + 1
28+
best_block = self.nodes[0].getbestblockhash()
29+
tip = int(best_block, 16)
30+
best_block_time = self.nodes[0].getblock(best_block)['time']
31+
block_time = best_block_time + 1
3332

3433
self.log.info("Create a new block with an anyone-can-spend coinbase.")
3534
height = 1
36-
block = create_block(self.tip, create_coinbase(height), self.block_time)
37-
self.block_time += 1
35+
block = create_block(tip, create_coinbase(height), block_time)
36+
block_time += 1
3837
block.solve()
3938
# Save the coinbase for later
40-
self.block1 = block
41-
self.tip = block.sha256
39+
block1 = block
40+
tip = block.sha256
4241
height += 1
43-
yield TestInstance([[block, True]])
42+
node.p2p.send_blocks_and_test([block], node, success=True)
4443

4544
self.log.info("Mature the block.")
46-
test = TestInstance(sync_every_block=False)
47-
for i in range(100):
48-
block = create_block(self.tip, create_coinbase(height), self.block_time)
49-
block.solve()
50-
self.tip = block.sha256
51-
self.block_time += 1
52-
test.blocks_and_transactions.append([block, True])
53-
height += 1
54-
yield test
45+
self.nodes[0].generate(100)
5546

5647
# b'\x64' is OP_NOTIF
5748
# Transaction will be rejected with code 16 (REJECT_INVALID)
58-
tx1 = create_transaction(self.block1.vtx[0], 0, b'\x64', 50 * COIN - 12000)
59-
yield TestInstance([[tx1, RejectResult(16, b'mandatory-script-verify-flag-failed')]])
49+
tx1 = create_transaction(block1.vtx[0], 0, b'\x64', 50 * COIN - 12000)
50+
node.p2p.send_txs_and_test([tx1], node, success=False, reject_code=16, reject_reason=b'mandatory-script-verify-flag-failed (Invalid OP_IF construction)')
6051

6152
# TODO: test further transactions...
6253

0 commit comments

Comments
 (0)