Skip to content

Commit dbbb3f9

Browse files
committed
Merge branch '0.12-bitcore-valuesat' into 0.12-bitcore
2 parents 45acaaf + 858fb8a commit dbbb3f9

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

qa/rpc-tests/txindex.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
17+
class TxIndexTest(BitcoinTestFramework):
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 = "cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG"
49+
address = "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW"
50+
addressHash = "0b2f0a0c31bfe0406b0ccc1381fdbe311946dadc".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()

src/rpcrawtransaction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
8888
const CTxOut& txout = tx.vout[i];
8989
UniValue out(UniValue::VOBJ);
9090
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
91+
out.push_back(Pair("valueSat", txout.nValue));
9192
out.push_back(Pair("n", (int64_t)i));
9293
UniValue o(UniValue::VOBJ);
9394
ScriptPubKeyToJSON(txout.scriptPubKey, o, true);

0 commit comments

Comments
 (0)