Merge #10845: Remove unreachable code
[bitcoinplatinum.git] / test / functional / invalidtxrequest.py
bloba22bd8f8cdc3db99c95a8b118f1504e898f30bd1
1 #!/usr/bin/env python3
2 # Copyright (c) 2015-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test node responses to invalid transactions.
7 In this test we connect to one node over p2p, and test tx requests.
8 """
10 from test_framework.test_framework import ComparisonTestFramework
11 from test_framework.comptool import TestManager, TestInstance, RejectResult
12 from test_framework.blocktools import *
13 import time
17 # Use the ComparisonTestFramework with 1 node: only use --testbinary.
18 class InvalidTxRequestTest(ComparisonTestFramework):
20 ''' Can either run this test as 1 node with expected answers, or two and compare them.
21 Change the "outcome" variable from each TestInstance object to only do the comparison. '''
22 def set_test_params(self):
23 self.num_nodes = 1
24 self.setup_clean_chain = True
26 def run_test(self):
27 test = TestManager(self, self.options.tmpdir)
28 test.add_all_connections(self.nodes)
29 self.tip = None
30 self.block_time = None
31 NetworkThread().start() # Start up network handling in another thread
32 test.run()
34 def get_tests(self):
35 if self.tip is None:
36 self.tip = int("0x" + self.nodes[0].getbestblockhash(), 0)
37 self.block_time = int(time.time())+1
39 '''
40 Create a new block with an anyone-can-spend coinbase
41 '''
42 height = 1
43 block = create_block(self.tip, create_coinbase(height), self.block_time)
44 self.block_time += 1
45 block.solve()
46 # Save the coinbase for later
47 self.block1 = block
48 self.tip = block.sha256
49 height += 1
50 yield TestInstance([[block, True]])
52 '''
53 Now we need that block to mature so we can spend the coinbase.
54 '''
55 test = TestInstance(sync_every_block=False)
56 for i in range(100):
57 block = create_block(self.tip, create_coinbase(height), self.block_time)
58 block.solve()
59 self.tip = block.sha256
60 self.block_time += 1
61 test.blocks_and_transactions.append([block, True])
62 height += 1
63 yield test
65 # b'\x64' is OP_NOTIF
66 # Transaction will be rejected with code 16 (REJECT_INVALID)
67 tx1 = create_transaction(self.block1.vtx[0], 0, b'\x64', 50 * COIN - 12000)
68 yield TestInstance([[tx1, RejectResult(16, b'mandatory-script-verify-flag-failed')]])
70 # TODO: test further transactions...
72 if __name__ == '__main__':
73 InvalidTxRequestTest().main()