mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Python 3 fixes/porting in rpc tests
This commit is contained in:
parent
2924b34401
commit
69dd8f4a64
@ -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 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
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 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
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("yMNJePdcKvXtWWQnFYHNeJ5u8TF2v1dfK4", 10)
|
||||
self.nodes[0].generate(1)
|
||||
@ -85,7 +85,7 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
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": ["93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB"],
|
||||
"start": 105,
|
||||
@ -110,8 +110,8 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
assert_equal(balance0["balance"], 45 * 100000000)
|
||||
|
||||
# Check that outputs with the same address will only return one txid
|
||||
print "Testing for txid uniqueness..."
|
||||
addressHash = "FE30B718DCF0BF8A2A686BF1820C073F8B2C3B37".decode("hex")
|
||||
print("Testing for txid uniqueness...")
|
||||
addressHash = binascii.unhexlify("FE30B718DCF0BF8A2A686BF1820C073F8B2C3B37")
|
||||
scriptPubKey = CScript([OP_HASH160, addressHash, OP_EQUAL])
|
||||
unspent = self.nodes[0].listunspent()
|
||||
tx = CTransaction()
|
||||
@ -130,22 +130,22 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
assert_equal(txidsmany[3], sent_txid)
|
||||
|
||||
# Check that balances are correct
|
||||
print "Testing balances..."
|
||||
print("Testing balances...")
|
||||
balance0 = self.nodes[1].getaddressbalance("93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB")
|
||||
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 = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
|
||||
address2 = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
|
||||
addressHash2 = "C5E4FB9171C22409809A3E8047A29C83886E325D".decode("hex")
|
||||
addressHash2 = binascii.unhexlify("C5E4FB9171C22409809A3E8047A29C83886E325D")
|
||||
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)
|
||||
tx.vout = [CTxOut(amount, scriptPubKey2)]
|
||||
tx.rehash()
|
||||
signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
|
||||
@ -188,13 +188,13 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
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)
|
||||
@ -228,11 +228,11 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
assert_equal(utxos3[2]["height"], 265)
|
||||
|
||||
# Check mempool indexing
|
||||
print "Testing mempool indexing..."
|
||||
print("Testing mempool indexing...")
|
||||
|
||||
privKey3 = "cRyrMvvqi1dmpiCmjmmATqjAwo6Wu7QTjKu1ABMYW5aFG4VXW99K"
|
||||
address3 = "yWB15aAdpeKuSaQHFVJpBDPbNSLZJSnDLA"
|
||||
addressHash3 = "6C186B3A308A77C779A9BB71C3B5A7EC28232A13".decode("hex")
|
||||
addressHash3 = binascii.unhexlify("6C186B3A308A77C779A9BB71C3B5A7EC28232A13")
|
||||
scriptPubKey3 = CScript([OP_DUP, OP_HASH160, addressHash3, OP_EQUALVERIFY, OP_CHECKSIG])
|
||||
# address4 = "2N8oFVB2vThAKury4vnLquW2zVjsYjjAkYQ"
|
||||
scriptPubKey4 = CScript([OP_HASH160, addressHash3, OP_EQUAL])
|
||||
@ -240,7 +240,7 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
|
||||
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)
|
||||
tx.vout = [CTxOut(amount, scriptPubKey3)]
|
||||
tx.rehash()
|
||||
signed_tx = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
|
||||
@ -249,12 +249,12 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
|
||||
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)
|
||||
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"))
|
||||
@ -281,7 +281,7 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
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"))
|
||||
@ -298,7 +298,7 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
# sending and receiving to the same address
|
||||
privkey1 = "cMvZn1pVWntTEcsK36ZteGQXRAcZ8CoTbMXF1QasxBLdnTwyVQCc"
|
||||
address1 = "yM9Eed1bxjy7tYxD3yZDHxjcVT48WdRoB1"
|
||||
address1hash = "0909C84A817651502E020AAD0FBCAE5F656E7D8A".decode("hex")
|
||||
address1hash = binascii.unhexlify("0909C84A817651502E020AAD0FBCAE5F656E7D8A")
|
||||
address1script = CScript([OP_DUP, OP_HASH160, address1hash, OP_EQUALVERIFY, OP_CHECKSIG])
|
||||
|
||||
self.nodes[0].sendtoaddress(address1, 10)
|
||||
@ -312,7 +312,7 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
tx.vin = [
|
||||
CTxIn(COutPoint(int(utxos[0]["txid"], 16), utxos[0]["outputIndex"]))
|
||||
]
|
||||
amount = utxos[0]["satoshis"] - 10000
|
||||
amount = int(utxos[0]["satoshis"] - 10000)
|
||||
tx.vout = [CTxOut(amount, address1script)]
|
||||
tx.rehash()
|
||||
self.nodes[0].importprivkey(privkey1)
|
||||
@ -323,7 +323,7 @@ class AddressIndexTest(BitcoinTestFramework):
|
||||
mempool_deltas = self.nodes[2].getaddressmempool({"addresses": [address1]})
|
||||
assert_equal(len(mempool_deltas), 2)
|
||||
|
||||
print "Passed\n"
|
||||
print("Passed\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -33,7 +33,7 @@ class DisableWalletTest (BitcoinTestFramework):
|
||||
# Checking mining to an address without a wallet
|
||||
try:
|
||||
self.nodes[0].generatetoaddress(1, 'ycwedq2f3sz2Yf9JqZsBCQPxp18WU3Hp4J')
|
||||
except JSONRPCException,e:
|
||||
except JSONRPCException as e:
|
||||
assert("Invalid address" not in e.error['message'])
|
||||
assert("ProcessNewBlock, block not accepted" not in e.error['message'])
|
||||
assert("Couldn't create new block" not in e.error['message'])
|
||||
@ -41,7 +41,7 @@ class DisableWalletTest (BitcoinTestFramework):
|
||||
try:
|
||||
self.nodes[0].generatetoaddress(1, '7TSBtVu959hGEGPKyHjJz9k55RpWrPffXz')
|
||||
raise AssertionError("Must not mine to invalid address!")
|
||||
except JSONRPCException,e:
|
||||
except JSONRPCException as e:
|
||||
assert("Invalid address" in e.error['message'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -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.
|
||||
@ -25,7 +25,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
|
||||
def run_test(self):
|
||||
print "Mining blocks..."
|
||||
print("Mining blocks...")
|
||||
|
||||
min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee']
|
||||
# This test is not meant to test fee estimation and we'd like
|
||||
|
@ -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.
|
||||
|
@ -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 @@ class SpentIndexTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
|
||||
def run_test(self):
|
||||
print "Mining blocks..."
|
||||
print("Mining blocks...")
|
||||
self.nodes[0].generate(105)
|
||||
self.sync_all()
|
||||
|
||||
@ -44,15 +44,15 @@ class SpentIndexTest(BitcoinTestFramework):
|
||||
assert_equal(chain_height, 105)
|
||||
|
||||
# Check that
|
||||
print "Testing spent index..."
|
||||
print("Testing spent index...")
|
||||
|
||||
privkey = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
|
||||
address = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
|
||||
addressHash = "C5E4FB9171C22409809A3E8047A29C83886E325D".decode("hex")
|
||||
addressHash = binascii.unhexlify("C5E4FB9171C22409809A3E8047A29C83886E325D")
|
||||
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)
|
||||
tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
|
||||
tx.vout = [CTxOut(amount, scriptPubKey)]
|
||||
tx.rehash()
|
||||
@ -62,7 +62,7 @@ class SpentIndexTest(BitcoinTestFramework):
|
||||
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 +70,7 @@ class SpentIndexTest(BitcoinTestFramework):
|
||||
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)
|
||||
@ -86,7 +86,7 @@ class SpentIndexTest(BitcoinTestFramework):
|
||||
# Check that verbose raw transaction includes address values and input values
|
||||
privkey2 = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
|
||||
address2 = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
|
||||
addressHash2 = "C5E4FB9171C22409809A3E8047A29C83886E325D".decode("hex")
|
||||
addressHash2 = binascii.unhexlify("C5E4FB9171C22409809A3E8047A29C83886E325D")
|
||||
scriptPubKey2 = CScript([OP_DUP, OP_HASH160, addressHash2, OP_EQUALVERIFY, OP_CHECKSIG])
|
||||
tx2 = CTransaction()
|
||||
tx2.vin = [CTxIn(COutPoint(int(txid, 16), 0))]
|
||||
@ -112,7 +112,7 @@ class SpentIndexTest(BitcoinTestFramework):
|
||||
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
||||
assert_equal(txVerbose4["vin"][0]["valueSat"], amount)
|
||||
|
||||
print "Passed\n"
|
||||
print("Passed\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -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,16 +35,16 @@ class TimestampIndexTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
|
||||
def run_test(self):
|
||||
print "Mining 5 blocks..."
|
||||
print("Mining 5 blocks...")
|
||||
blockhashes = self.nodes[0].generate(5)
|
||||
low = self.nodes[0].getblock(blockhashes[0])["time"]
|
||||
high = self.nodes[0].getblock(blockhashes[4])["time"]
|
||||
self.sync_all()
|
||||
print "Checking timestamp index..."
|
||||
print("Checking timestamp index...")
|
||||
hashes = self.nodes[1].getblockhashes(high, low)
|
||||
assert_equal(len(hashes), 5)
|
||||
assert_equal(sorted(blockhashes), sorted(hashes))
|
||||
print "Passed\n"
|
||||
print("Passed\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -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,14 +36,14 @@ class TxIndexTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
|
||||
def run_test(self):
|
||||
print "Mining blocks..."
|
||||
print("Mining blocks...")
|
||||
self.nodes[0].generate(105)
|
||||
self.sync_all()
|
||||
|
||||
chain_height = self.nodes[1].getblockcount()
|
||||
assert_equal(chain_height, 105)
|
||||
|
||||
print "Testing transaction index..."
|
||||
print("Testing transaction index...")
|
||||
|
||||
privkey = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
|
||||
address = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
|
||||
@ -66,7 +66,7 @@ class TxIndexTest(BitcoinTestFramework):
|
||||
assert_equal(verbose["vout"][0]["valueSat"], 5000000000);
|
||||
assert_equal(verbose["vout"][0]["value"], 50);
|
||||
|
||||
print "Passed\n"
|
||||
print("Passed\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,6 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
# coding=utf-8
|
||||
# ^^^^^^^^^^^^ TODO remove when supporting only Python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2016 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
Loading…
Reference in New Issue
Block a user