[CoinControl] Allow non-wallet owned change addresses
[bitcoinplatinum.git] / qa / rpc-tests / invalidtxrequest.py
blob93205d79dee5bddd8e5e3d0862374dd72d1fdcb1
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.
6 from test_framework.test_framework import ComparisonTestFramework
7 from test_framework.comptool import TestManager, TestInstance, RejectResult
8 from test_framework.blocktools import *
9 import time
12 '''
13 In this test we connect to one node over p2p, and test tx requests.
14 '''
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. '''
21 def __init__(self):
22 super().__init__()
23 self.num_nodes = 1
25 def run_test(self):
26 test = TestManager(self, self.options.tmpdir)
27 test.add_all_connections(self.nodes)
28 self.tip = None
29 self.block_time = None
30 NetworkThread().start() # Start up network handling in another thread
31 test.run()
33 def get_tests(self):
34 if self.tip is None:
35 self.tip = int("0x" + self.nodes[0].getbestblockhash(), 0)
36 self.block_time = int(time.time())+1
38 '''
39 Create a new block with an anyone-can-spend coinbase
40 '''
41 height = 1
42 block = create_block(self.tip, create_coinbase(height), self.block_time)
43 self.block_time += 1
44 block.solve()
45 # Save the coinbase for later
46 self.block1 = block
47 self.tip = block.sha256
48 height += 1
49 yield TestInstance([[block, True]])
51 '''
52 Now we need that block to mature so we can spend the coinbase.
53 '''
54 test = TestInstance(sync_every_block=False)
55 for i in range(100):
56 block = create_block(self.tip, create_coinbase(height), self.block_time)
57 block.solve()
58 self.tip = block.sha256
59 self.block_time += 1
60 test.blocks_and_transactions.append([block, True])
61 height += 1
62 yield test
64 # b'\x64' is OP_NOTIF
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()