Dash Core  0.12.2.1
P2P Digital Currency
invalidtxrequest.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 #
3 # Distributed under the MIT/X11 software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #
6 
7 from test_framework.test_framework import ComparisonTestFramework
8 from test_framework.comptool import TestManager, TestInstance, RejectResult
9 from test_framework.blocktools import *
10 import time
11 
12 
13 '''
14 In this test we connect to one node over p2p, and test tx requests.
15 '''
16 
17 # Use the ComparisonTestFramework with 1 node: only use --testbinary.
19 
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 __init__(self):
23  self.num_nodes = 1
24 
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()
32 
33  def get_tests(self):
34  if self.tip is None:
35  self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
36  self.block_time = int(time.time())+1
37 
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]])
50 
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 xrange(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
63 
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)
67  yield TestInstance([[tx1, RejectResult(16, b'mandatory-script-verify-flag-failed')]])
68 
69  # TODO: test further transactions...
70 
71 if __name__ == '__main__':
def create_block(hashprev, coinbase, nTime=None)
Definition: blocktools.py:11
def create_coinbase(height, pubkey=None)
Definition: blocktools.py:43
def create_transaction(prevtx, n, sig, value)
Definition: blocktools.py:61
UniValue getbestblockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:148