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.
6 from test_framework
.test_framework
import ComparisonTestFramework
7 from test_framework
.comptool
import TestManager
, TestInstance
, RejectResult
8 from test_framework
.blocktools
import *
13 In this test we connect to one node over p2p, and test tx requests.
16 # Use the ComparisonTestFramework with 1 node: only use --testbinary.
17 class InvalidTxRequestTest(ComparisonTestFramework
):
19 ''' Can either run this test as 1 node with expected answers, or two and compare them.
20 Change the "outcome" variable from each TestInstance object to only do the comparison. '''
26 test
= TestManager(self
, self
.options
.tmpdir
)
27 test
.add_all_connections(self
.nodes
)
29 self
.block_time
= None
30 NetworkThread().start() # Start up network handling in another thread
35 self
.tip
= int("0x" + self
.nodes
[0].getbestblockhash(), 0)
36 self
.block_time
= int(time
.time())+1
39 Create a new block with an anyone-can-spend coinbase
42 block
= create_block(self
.tip
, create_coinbase(height
), self
.block_time
)
45 # Save the coinbase for later
47 self
.tip
= block
.sha256
49 yield TestInstance([[block
, True]])
52 Now we need that block to mature so we can spend the coinbase.
54 test
= TestInstance(sync_every_block
=False)
56 block
= create_block(self
.tip
, create_coinbase(height
), self
.block_time
)
58 self
.tip
= block
.sha256
60 test
.blocks_and_transactions
.append([block
, True])
65 # Transaction will be rejected with code 16 (REJECT_INVALID)
66 tx1
= create_transaction(self
.block1
.vtx
[0], 0, b
'\x64', 50 * COIN
- 12000)
67 yield TestInstance([[tx1
, RejectResult(16, b
'mandatory-script-verify-flag-failed')]])
69 # TODO: test further transactions...
71 if __name__
== '__main__':
72 InvalidTxRequestTest().main()