|
5 | 5 | """Test node responses to invalid transactions.
|
6 | 6 |
|
7 | 7 | In this test we connect to one node over p2p, and test tx requests."""
|
8 |
| -import time |
9 |
| - |
10 | 8 | from test_framework.blocktools import create_block, create_coinbase, create_transaction
|
11 |
| -from test_framework.comptool import RejectResult, TestInstance, TestManager |
12 | 9 | 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 |
15 | 12 |
|
16 |
| -class InvalidTxRequestTest(ComparisonTestFramework): |
| 13 | +class InvalidTxRequestTest(BitcoinTestFramework): |
17 | 14 |
|
18 | 15 | def set_test_params(self):
|
19 | 16 | self.num_nodes = 1
|
20 | 17 | self.setup_clean_chain = True
|
| 18 | + self.extra_args = [["-whitelist=127.0.0.1"]] |
21 | 19 |
|
22 | 20 | 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 | + |
27 | 25 | network_thread_start()
|
28 |
| - test.run() |
| 26 | + node.p2p.wait_for_verack() |
29 | 27 |
|
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 |
33 | 32 |
|
34 | 33 | self.log.info("Create a new block with an anyone-can-spend coinbase.")
|
35 | 34 | 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 |
38 | 37 | block.solve()
|
39 | 38 | # Save the coinbase for later
|
40 |
| - self.block1 = block |
41 |
| - self.tip = block.sha256 |
| 39 | + block1 = block |
| 40 | + tip = block.sha256 |
42 | 41 | height += 1
|
43 |
| - yield TestInstance([[block, True]]) |
| 42 | + node.p2p.send_blocks_and_test([block], node, success=True) |
44 | 43 |
|
45 | 44 | 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) |
55 | 46 |
|
56 | 47 | # b'\x64' is OP_NOTIF
|
57 | 48 | # 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)') |
60 | 51 |
|
61 | 52 | # TODO: test further transactions...
|
62 | 53 |
|
|
0 commit comments