Dash Core  0.12.2.1
P2P Digital Currency
txindex.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 txindex generation and fetching
8 #
9 
10 import time
11 from test_framework.test_framework import BitcoinTestFramework
12 from test_framework.util import *
13 from test_framework.script import *
14 from test_framework.mininode import *
15 import binascii
16 
18 
19  def setup_chain(self):
20  print("Initializing test directory "+self.options.tmpdir)
21  initialize_chain_clean(self.options.tmpdir, 4)
22 
23  def setup_network(self):
24  self.nodes = []
25  # Nodes 0/1 are "wallet" nodes
26  self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"]))
27  self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-txindex"]))
28  # Nodes 2/3 are used for testing
29  self.nodes.append(start_node(2, self.options.tmpdir, ["-debug", "-txindex"]))
30  self.nodes.append(start_node(3, self.options.tmpdir, ["-debug", "-txindex"]))
31  connect_nodes(self.nodes[0], 1)
32  connect_nodes(self.nodes[0], 2)
33  connect_nodes(self.nodes[0], 3)
34 
35  self.is_network_split = False
36  self.sync_all()
37 
38  def run_test(self):
39  print "Mining blocks..."
40  self.nodes[0].generate(105)
41  self.sync_all()
42 
43  chain_height = self.nodes[1].getblockcount()
44  assert_equal(chain_height, 105)
45 
46  print "Testing transaction index..."
47 
48  privkey = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
49  address = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
50  addressHash = "C5E4FB9171C22409809A3E8047A29C83886E325D".decode("hex")
51  scriptPubKey = CScript([OP_DUP, OP_HASH160, addressHash, OP_EQUALVERIFY, OP_CHECKSIG])
52  unspent = self.nodes[0].listunspent()
53  tx = CTransaction()
54  amount = unspent[0]["amount"] * 100000000
55  tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
56  tx.vout = [CTxOut(amount, scriptPubKey)]
57  tx.rehash()
58 
59  signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
60  txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)
61  self.nodes[0].generate(1)
62  self.sync_all()
63 
64  # Check verbose raw transaction results
65  verbose = self.nodes[3].getrawtransaction(unspent[0]["txid"], 1)
66  assert_equal(verbose["vout"][0]["valueSat"], 5000000000);
67  assert_equal(verbose["vout"][0]["value"], 50);
68 
69  print "Passed\n"
70 
71 
72 if __name__ == '__main__':
73  TxIndexTest().main()
def setup_network(self)
Definition: txindex.py:23
UniValue getrawtransaction(const UniValue &params, bool fHelp)
UniValue listunspent(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2533
def connect_nodes(from_connection, node_num)
Definition: util.py:343
UniValue getblockcount(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:131
def initialize_chain_clean(test_dir, num_nodes)
Definition: util.py:252
UniValue signrawtransaction(const UniValue &params, bool fHelp)
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)
def run_test(self)
Definition: txindex.py:38
def setup_chain(self)
Definition: txindex.py:19
def assert_equal(thing1, thing2)
Definition: util.py:461