Dash Core  0.12.2.1
P2P Digital Currency
mempool_spendcoinbase.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 # Copyright (c) 2014-2015 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 
6 #
7 # Test spending coinbase transactions.
8 # The coinbase transaction in block N can appear in block
9 # N+100... so is valid in the mempool when the best block
10 # height is N+99.
11 # This test makes sure coinbase spends that will be mature
12 # in the next block are accepted into the memory pool,
13 # but less mature coinbase spends are NOT.
14 #
15 
16 from test_framework.test_framework import BitcoinTestFramework
17 from test_framework.util import *
18 
19 # Create one-input, one-output, no-fee transaction:
21 
22  def setup_network(self):
23  # Just need one node for this test
24  args = ["-checkmempool", "-debug=mempool"]
25  self.nodes = []
26  self.nodes.append(start_node(0, self.options.tmpdir, args))
27  self.is_network_split = False
28 
29  def run_test(self):
30  chain_height = self.nodes[0].getblockcount()
31  assert_equal(chain_height, 200)
32  node0_address = self.nodes[0].getnewaddress()
33 
34  # Coinbase at height chain_height-100+1 ok in mempool, should
35  # get mined. Coinbase at height chain_height-100+2 is
36  # is too immature to spend.
37  b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
38  coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
39  spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 500) for txid in coinbase_txids ]
40 
41  spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])
42 
43  # coinbase at height 102 should be too immature to spend
44  assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, spends_raw[1])
45 
46  # mempool should have just spend_101:
47  assert_equal(self.nodes[0].getrawmempool(), [ spend_101_id ])
48 
49  # mine a block, spend_101 should get confirmed
50  self.nodes[0].generate(1)
51  assert_equal(set(self.nodes[0].getrawmempool()), set())
52 
53  # ... and now height 102 can be spent:
54  spend_102_id = self.nodes[0].sendrawtransaction(spends_raw[1])
55  assert_equal(self.nodes[0].getrawmempool(), [ spend_102_id ])
56 
57 if __name__ == '__main__':
def assert_raises(exc, fun, args, kwds)
Definition: util.py:469
UniValue getblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:483
UniValue getnewaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:113
def create_tx(dashd, fromaddresses, toaddress, amount, fee)
Definition: spendfrom.py:142
UniValue getblockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:311
UniValue getblockcount(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:131
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None)
Definition: util.py:281
UniValue generate(const UniValue &params, bool fHelp)
Definition: mining.cpp:122
UniValue sendrawtransaction(const UniValue &params, bool fHelp)
UniValue getrawmempool(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:234
def assert_equal(thing1, thing2)
Definition: util.py:461