changeset 29710:6a307530110a

tests: update rpc index tests for 0.13
author Braydon Fuller <braydon@bitpay.com>
date Wed, 05 Oct 2016 18:39:57 -0400
parents a66a7a8297b4
children effc7073b9ca
files qa/rpc-tests/addressindex.py qa/rpc-tests/spentindex.py qa/rpc-tests/timestampindex.py
diffstat 3 files changed, 52 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/qa/rpc-tests/addressindex.py	Wed Oct 05 18:39:13 2016 -0400
+++ b/qa/rpc-tests/addressindex.py	Wed Oct 05 18:39:57 2016 -0400
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # Copyright (c) 2014-2015 The Bitcoin Core developers
 # Distributed under the MIT software license, see the accompanying
 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -36,7 +36,7 @@
         self.sync_all()
 
     def run_test(self):
-        print "Mining blocks..."
+        print("Mining blocks...")
         self.nodes[0].generate(105)
         self.sync_all()
 
@@ -50,7 +50,7 @@
         assert_equal(balance0["balance"], 0)
 
         # Check p2pkh and p2sh address indexes
-        print "Testing p2pkh and p2sh address index..."
+        print("Testing p2pkh and p2sh address index...")
 
         txid0 = self.nodes[0].sendtoaddress("mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs", 10)
         self.nodes[0].generate(1)
@@ -85,7 +85,7 @@
         assert_equal(txidsb[2], txidb2)
 
         # Check that limiting by height works
-        print "Testing querying txids by range of block heights.."
+        print("Testing querying txids by range of block heights..")
         height_txids = self.nodes[1].getaddresstxids({
             "addresses": ["2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br"],
             "start": 105,
@@ -110,8 +110,8 @@
         assert_equal(balance0["balance"], 45 * 100000000)
 
         # Check that outputs with the same address will only return one txid
-        print "Testing for txid uniqueness..."
-        addressHash = "6349a418fc4578d10a372b54b45c280cc8c4382f".decode("hex")
+        print("Testing for txid uniqueness...")
+        addressHash = bytes([99,73,164,24,252,69,120,209,10,55,43,84,180,92,40,12,200,196,56,47])
         scriptPubKey = CScript([OP_HASH160, addressHash, OP_EQUAL])
         unspent = self.nodes[0].listunspent()
         tx = CTransaction()
@@ -130,22 +130,22 @@
         assert_equal(txidsmany[3], sent_txid)
 
         # Check that balances are correct
-        print "Testing balances..."
+        print("Testing balances...")
         balance0 = self.nodes[1].getaddressbalance("2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br")
         assert_equal(balance0["balance"], 45 * 100000000 + 21)
 
         # Check that balances are correct after spending
-        print "Testing balances after spending..."
+        print("Testing balances after spending...")
         privkey2 = "cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG"
         address2 = "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW"
-        addressHash2 = "0b2f0a0c31bfe0406b0ccc1381fdbe311946dadc".decode("hex")
+        addressHash2 = bytes([11,47,10,12,49,191,224,64,107,12,204,19,129,253,190,49,25,70,218,220])
         scriptPubKey2 = CScript([OP_DUP, OP_HASH160, addressHash2, OP_EQUALVERIFY, OP_CHECKSIG])
         self.nodes[0].importprivkey(privkey2)
 
         unspent = self.nodes[0].listunspent()
         tx = CTransaction()
         tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
-        amount = unspent[0]["amount"] * 100000000
+        amount = int(unspent[0]["amount"] * 100000000 - 100000)
         tx.vout = [CTxOut(amount, scriptPubKey2)]
         tx.rehash()
         signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
@@ -188,13 +188,13 @@
         assert_equal(len(deltas), 1)
 
         # Check that unspent outputs can be queried
-        print "Testing utxos..."
+        print("Testing utxos...")
         utxos = self.nodes[1].getaddressutxos({"addresses": [address2]})
         assert_equal(len(utxos), 1)
         assert_equal(utxos[0]["satoshis"], change_amount)
 
         # Check that indexes will be updated with a reorg
-        print "Testing reorg..."
+        print("Testing reorg...")
 
         best_hash = self.nodes[0].getbestblockhash()
         self.nodes[0].invalidateblock(best_hash)
@@ -226,11 +226,11 @@
         assert_equal(utxos3[2]["height"], 265)
 
         # Check mempool indexing
-        print "Testing mempool indexing..."
+        print("Testing mempool indexing...")
 
         privKey3 = "cVfUn53hAbRrDEuMexyfgDpZPhF7KqXpS8UZevsyTDaugB7HZ3CD"
         address3 = "mw4ynwhS7MmrQ27hr82kgqu7zryNDK26JB"
-        addressHash3 = "aa9872b5bbcdb511d89e0e11aa27da73fd2c3f50".decode("hex")
+        addressHash3 = bytes([170,152,114,181,187,205,181,17,216,158,14,17,170,39,218,115,253,44,63,80])
         scriptPubKey3 = CScript([OP_DUP, OP_HASH160, addressHash3, OP_EQUALVERIFY, OP_CHECKSIG])
         address4 = "2N8oFVB2vThAKury4vnLquW2zVjsYjjAkYQ"
         scriptPubKey4 = CScript([OP_HASH160, addressHash3, OP_EQUAL])
@@ -238,7 +238,7 @@
 
         tx = CTransaction()
         tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
-        amount = unspent[0]["amount"] * 100000000
+        amount = int(unspent[0]["amount"] * 100000000 - 100000)
         tx.vout = [CTxOut(amount, scriptPubKey3)]
         tx.rehash()
         signed_tx = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
@@ -247,12 +247,12 @@
 
         tx2 = CTransaction()
         tx2.vin = [CTxIn(COutPoint(int(unspent[1]["txid"], 16), unspent[1]["vout"]))]
-        amount = unspent[1]["amount"] * 100000000
+        amount = int(unspent[1]["amount"] * 100000000 - 100000)
         tx2.vout = [
-            CTxOut(amount / 4, scriptPubKey3),
-            CTxOut(amount / 4, scriptPubKey3),
-            CTxOut(amount / 4, scriptPubKey4),
-            CTxOut(amount / 4, scriptPubKey4)
+            CTxOut(int(amount / 4), scriptPubKey3),
+            CTxOut(int(amount / 4), scriptPubKey3),
+            CTxOut(int(amount / 4), scriptPubKey4),
+            CTxOut(int(amount / 4), scriptPubKey4)
         ]
         tx2.rehash()
         signed_tx2 = self.nodes[2].signrawtransaction(binascii.hexlify(tx2.serialize()).decode("utf-8"))
@@ -269,7 +269,7 @@
         assert_equal(mempool[2]["txid"], memtxid2)
         assert_equal(mempool[2]["index"], 1)
 
-        self.nodes[2].generate(1);
+        blk_hashes = self.nodes[2].generate(1);
         self.sync_all();
         mempool2 = self.nodes[2].getaddressmempool({"addresses": [address3]})
         assert_equal(len(mempool2), 0)
@@ -279,7 +279,7 @@
             CTxIn(COutPoint(int(memtxid2, 16), 0)),
             CTxIn(COutPoint(int(memtxid2, 16), 1))
         ]
-        tx.vout = [CTxOut(amount / 2 - 10000, scriptPubKey2)]
+        tx.vout = [CTxOut(int(amount / 2 - 10000), scriptPubKey2)]
         tx.rehash()
         self.nodes[2].importprivkey(privKey3)
         signed_tx3 = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
@@ -296,7 +296,7 @@
         # sending and receiving to the same address
         privkey1 = "cQY2s58LhzUCmEXN8jtAp1Etnijx78YRZ466w4ikX1V4UpTpbsf8"
         address1 = "myAUWSHnwsQrhuMWv4Br6QsCnpB41vFwHn"
-        address1hash = "c192bff751af8efec15135d42bfeedf91a6f3e34".decode("hex")
+        address1hash = bytes([193,146,191,247,81,175,142,254,193,81,53,212,43,254,237,249,26,111,62,52])
         address1script = CScript([OP_DUP, OP_HASH160, address1hash, OP_EQUALVERIFY, OP_CHECKSIG])
 
         self.nodes[0].sendtoaddress(address1, 10)
@@ -310,7 +310,7 @@
         tx.vin = [
             CTxIn(COutPoint(int(utxos[0]["txid"], 16), utxos[0]["outputIndex"]))
         ]
-        amount = utxos[0]["satoshis"] - 1000
+        amount = int(utxos[0]["satoshis"] - 1000)
         tx.vout = [CTxOut(amount, address1script)]
         tx.rehash()
         self.nodes[0].importprivkey(privkey1)
@@ -322,7 +322,7 @@
         assert_equal(len(mempool_deltas), 2)
 
         # Include chaininfo in results
-        print "Testing results with chain info..."
+        print("Testing results with chain info...")
 
         deltas_with_info = self.nodes[1].getaddressdeltas({
             "addresses": [address2],
@@ -342,7 +342,7 @@
         assert_equal(utxos_with_info["height"], 267)
         assert_equal(utxos_with_info["hash"], expected_tip_block_hash)
 
-        print "Passed\n"
+        print("Passed\n")
 
 
 if __name__ == '__main__':
--- a/qa/rpc-tests/spentindex.py	Wed Oct 05 18:39:13 2016 -0400
+++ b/qa/rpc-tests/spentindex.py	Wed Oct 05 18:39:57 2016 -0400
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # Copyright (c) 2014-2015 The Bitcoin Core developers
 # Distributed under the MIT software license, see the accompanying
 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -36,7 +36,7 @@
         self.sync_all()
 
     def run_test(self):
-        print "Mining blocks..."
+        print("Mining blocks...")
         self.nodes[0].generate(105)
         self.sync_all()
 
@@ -44,15 +44,16 @@
         assert_equal(chain_height, 105)
 
         # Check that
-        print "Testing spent index..."
+        print("Testing spent index...")
 
+        feeSatoshis = 10000
         privkey = "cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG"
         address = "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW"
-        addressHash = "0b2f0a0c31bfe0406b0ccc1381fdbe311946dadc".decode("hex")
+        addressHash = bytes([11,47,10,12,49,191,224,64,107,12,204,19,129,253,190,49,25,70,218,220])
         scriptPubKey = CScript([OP_DUP, OP_HASH160, addressHash, OP_EQUALVERIFY, OP_CHECKSIG])
         unspent = self.nodes[0].listunspent()
         tx = CTransaction()
-        amount = unspent[0]["amount"] * 100000000
+        amount = int(unspent[0]["amount"] * 100000000 - feeSatoshis)
         tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
         tx.vout = [CTxOut(amount, scriptPubKey)]
         tx.rehash()
@@ -62,7 +63,7 @@
         self.nodes[0].generate(1)
         self.sync_all()
 
-        print "Testing getspentinfo method..."
+        print("Testing getspentinfo method...")
 
         # Check that the spentinfo works standalone
         info = self.nodes[1].getspentinfo({"txid": unspent[0]["txid"], "index": unspent[0]["vout"]})
@@ -70,7 +71,7 @@
         assert_equal(info["index"], 0)
         assert_equal(info["height"], 106)
 
-        print "Testing getrawtransaction method..."
+        print("Testing getrawtransaction method...")
 
         # Check that verbose raw transaction includes spent info
         txVerbose = self.nodes[3].getrawtransaction(unspent[0]["txid"], 1)
@@ -80,16 +81,17 @@
 
         # Check that verbose raw transaction includes input values
         txVerbose2 = self.nodes[3].getrawtransaction(txid, 1)
-        assert_equal(txVerbose2["vin"][0]["value"], Decimal(unspent[0]["amount"]))
-        assert_equal(txVerbose2["vin"][0]["valueSat"], amount)
+        assert_equal(float(txVerbose2["vin"][0]["value"]), (amount + feeSatoshis) / 100000000)
+        assert_equal(txVerbose2["vin"][0]["valueSat"], amount + feeSatoshis)
 
         # Check that verbose raw transaction includes address values and input values
         privkey2 = "cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG"
         address2 = "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW"
-        addressHash2 = "0b2f0a0c31bfe0406b0ccc1381fdbe311946dadc".decode("hex")
+        addressHash2 = bytes([11,47,10,12,49,191,224,64,107,12,204,19,129,253,190,49,25,70,218,220])
         scriptPubKey2 = CScript([OP_DUP, OP_HASH160, addressHash2, OP_EQUALVERIFY, OP_CHECKSIG])
         tx2 = CTransaction()
         tx2.vin = [CTxIn(COutPoint(int(txid, 16), 0))]
+        amount = int(amount - feeSatoshis);
         tx2.vout = [CTxOut(amount, scriptPubKey2)]
         tx.rehash()
         self.nodes[0].importprivkey(privkey)
@@ -100,8 +102,9 @@
         self.sync_all()
         txVerbose3 = self.nodes[1].getrawtransaction(txid2, 1)
         assert_equal(txVerbose3["vin"][0]["address"], address2)
-        assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]))
-        assert_equal(txVerbose3["vin"][0]["valueSat"], amount)
+        assert_equal(txVerbose3["vin"][0]["valueSat"], amount + feeSatoshis)
+        assert_equal(float(txVerbose3["vin"][0]["value"]), (amount + feeSatoshis) / 100000000)
+
 
         # Check the database index
         block_hash = self.nodes[0].generate(1)
@@ -109,12 +112,11 @@
 
         txVerbose4 = self.nodes[3].getrawtransaction(txid2, 1)
         assert_equal(txVerbose4["vin"][0]["address"], address2)
-        assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
-        assert_equal(txVerbose4["vin"][0]["valueSat"], amount)
-
+        assert_equal(txVerbose4["vin"][0]["valueSat"], amount + feeSatoshis)
+        assert_equal(float(txVerbose4["vin"][0]["value"]), (amount + feeSatoshis) / 100000000)
 
         # Check block deltas
-        print "Testing getblockdeltas..."
+        print("Testing getblockdeltas...")
 
         block = self.nodes[3].getblockdeltas(block_hash[0])
         assert_equal(len(block["deltas"]), 2)
@@ -125,14 +127,14 @@
         assert_equal(block["deltas"][1]["txid"], txid2)
         assert_equal(block["deltas"][1]["inputs"][0]["index"], 0)
         assert_equal(block["deltas"][1]["inputs"][0]["address"], "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW")
-        assert_equal(block["deltas"][1]["inputs"][0]["satoshis"], amount * -1)
+        assert_equal(block["deltas"][1]["inputs"][0]["satoshis"], (amount + feeSatoshis) * -1)
         assert_equal(block["deltas"][1]["inputs"][0]["prevtxid"], txid)
         assert_equal(block["deltas"][1]["inputs"][0]["prevout"], 0)
         assert_equal(block["deltas"][1]["outputs"][0]["index"], 0)
         assert_equal(block["deltas"][1]["outputs"][0]["address"], "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW")
         assert_equal(block["deltas"][1]["outputs"][0]["satoshis"], amount)
 
-        print "Passed\n"
+        print("Passed\n")
 
 
 if __name__ == '__main__':
--- a/qa/rpc-tests/timestampindex.py	Wed Oct 05 18:39:13 2016 -0400
+++ b/qa/rpc-tests/timestampindex.py	Wed Oct 05 18:39:57 2016 -0400
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # Copyright (c) 2014-2015 The Bitcoin Core developers
 # Distributed under the MIT software license, see the accompanying
 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -35,26 +35,26 @@
         self.sync_all()
 
     def run_test(self):
-        print "Mining 25 blocks..."
+        print("Mining 25 blocks...")
         blockhashes = self.nodes[0].generate(25)
         time.sleep(3)
-        print "Mining 25 blocks..."
+        print("Mining 25 blocks...")
         blockhashes.extend(self.nodes[0].generate(25))
         time.sleep(3)
-        print "Mining 25 blocks..."
+        print("Mining 25 blocks...")
         blockhashes.extend(self.nodes[0].generate(25))
         self.sync_all()
         low = self.nodes[1].getblock(blockhashes[0])["time"]
         high = low + 76
 
-        print "Checking timestamp index..."
+        print("Checking timestamp index...")
         hashes = self.nodes[1].getblockhashes(high, low)
 
         assert_equal(len(hashes), len(blockhashes))
 
         assert_equal(hashes, blockhashes)
 
-        print "Passed\n"
+        print("Passed\n")
 
 
 if __name__ == '__main__':