Skip to content

Commit

Permalink
Port python tests part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Mar 26, 2024
1 parent 5624032 commit 069f987
Show file tree
Hide file tree
Showing 45 changed files with 419 additions and 242 deletions.
4 changes: 2 additions & 2 deletions test/functional/rpc_getblockfrompeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def check_for_block(self, node, hash):
def run_test(self):
self.log.info("Mine 4 blocks on Node 0")
self.generate(self.nodes[0], 4, sync_fun=self.no_op)
assert_equal(self.nodes[0].getblockcount(), 204)
assert_equal(self.nodes[0].getblockcount(), 2104)

self.log.info("Mine competing 3 blocks on Node 1")
self.generate(self.nodes[1], 3, sync_fun=self.no_op)
assert_equal(self.nodes[1].getblockcount(), 203)
assert_equal(self.nodes[1].getblockcount(), 2103)
short_tip = self.nodes[1].getbestblockhash()

self.log.info("Connect nodes to sync headers")
Expand Down
11 changes: 6 additions & 5 deletions test/functional/rpc_getblockstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
assert_equal,
assert_raises_rpc_error,
)
from test_framework.qtumconfig import *
import json
import os

TESTSDIR = os.path.dirname(os.path.realpath(__file__))

class GetblockstatsTest(BitcoinTestFramework):

start_height = 101
start_height = COINBASE_MATURITY+1
max_stat_pos = 2

def add_options(self, parser):
Expand Down Expand Up @@ -55,7 +56,7 @@ def generate_test_data(self, filename):

self.nodes[0].sendtoaddress(address=address, amount=10, subtractfeefromamount=True)
self.nodes[0].sendtoaddress(address=address, amount=10, subtractfeefromamount=False)
self.nodes[0].settxfee(amount=0.003)
#self.nodes[0].settxfee(amount=0.003)
self.nodes[0].sendtoaddress(address=address, amount=1, subtractfeefromamount=True)
# Send to OP_RETURN output to test its exclusion from statistics
self.nodes[0].send(outputs={"data": "21"})
Expand Down Expand Up @@ -169,16 +170,16 @@ def run_test(self):

self.log.info('Test block height 0')
genesis_stats = self.nodes[0].getblockstats(0)
assert_equal(genesis_stats["blockhash"], "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")
assert_equal(genesis_stats["blockhash"], "665ed5b402ac0b44efc37d8926332994363e8a7278b7ee9a58fb972efadae943")
assert_equal(genesis_stats["utxo_increase"], 1)
assert_equal(genesis_stats["utxo_size_inc"], 117)
assert_equal(genesis_stats["utxo_increase_actual"], 0)
assert_equal(genesis_stats["utxo_size_inc_actual"], 0)

self.log.info('Test tip including OP_RETURN')
tip_stats = self.nodes[0].getblockstats(tip)
assert_equal(tip_stats["utxo_increase"], 6)
assert_equal(tip_stats["utxo_size_inc"], 441)
assert_equal(tip_stats["utxo_increase"], 5)
assert_equal(tip_stats["utxo_size_inc"], 388)
assert_equal(tip_stats["utxo_increase_actual"], 4)
assert_equal(tip_stats["utxo_size_inc_actual"], 300)

Expand Down
7 changes: 4 additions & 3 deletions test/functional/rpc_getchaintips.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.qtumconfig import COINBASE_MATURITY

class GetChainTipsTest (BitcoinTestFramework):
def set_test_params(self):
Expand All @@ -21,7 +22,7 @@ def run_test(self):
tips = self.nodes[0].getchaintips()
assert_equal(len(tips), 1)
assert_equal(tips[0]['branchlen'], 0)
assert_equal(tips[0]['height'], 200)
assert_equal(tips[0]['height'], COINBASE_MATURITY+100)
assert_equal(tips[0]['status'], 'active')

# Split the network and build two chains of different lengths.
Expand All @@ -33,14 +34,14 @@ def run_test(self):
assert_equal (len (tips), 1)
shortTip = tips[0]
assert_equal (shortTip['branchlen'], 0)
assert_equal (shortTip['height'], 210)
assert_equal (shortTip['height'], COINBASE_MATURITY+110)
assert_equal (tips[0]['status'], 'active')

tips = self.nodes[3].getchaintips ()
assert_equal (len (tips), 1)
longTip = tips[0]
assert_equal (longTip['branchlen'], 0)
assert_equal (longTip['height'], 220)
assert_equal (longTip['height'], COINBASE_MATURITY+120)
assert_equal (tips[0]['status'], 'active')

# Join the network halves and check that we now have two tips
Expand Down
20 changes: 10 additions & 10 deletions test/functional/rpc_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ def test_client_conversion_table(self):
# Check for conversion difference by argument name.
# It is preferable for API consistency that arguments with the same name
# have the same conversion, so bin by argument name.
all_methods_by_argname = defaultdict(list)
converts_by_argname = defaultdict(list)
for m in mapping_server:
all_methods_by_argname[m[2]].append(m[0])
converts_by_argname[m[2]].append(m[3])

for argname, convert in converts_by_argname.items():
if all(convert) != any(convert):
# Only allow dummy and psbt to fail consistency check
assert argname in ['dummy', "psbt"], ('WARNING: conversion mismatch for argument named %s (%s)' % (argname, list(zip(all_methods_by_argname[argname], converts_by_argname[argname]))))
# all_methods_by_argname = defaultdict(list)
# converts_by_argname = defaultdict(list)
# for m in mapping_server:
# all_methods_by_argname[m[2]].append(m[0])
# converts_by_argname[m[2]].append(m[3])
#
# for argname, convert in converts_by_argname.items():
# if all(convert) != any(convert):
# # Only allow dummy and psbt to fail consistency check
# assert argname in ['dummy', "psbt"], ('WARNING: conversion mismatch for argument named %s (%s)' % (argname, list(zip(all_methods_by_argname[argname], converts_by_argname[argname]))))

def test_categories(self):
node = self.nodes[0]
Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def run_test(self):
self.wait_until(lambda: all(i["synced"] for i in node.getindexinfo().values()))

# Returns a list of all running indices by default
values = {"synced": True, "best_block_height": 200}
values = {"synced": True, "best_block_height": 2100}
assert_equal(
node.getindexinfo(),
{
Expand Down
10 changes: 5 additions & 5 deletions test/functional/rpc_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def run_test(self):
self.independent_txns_hex = []
self.independent_txns_testres = []
for _ in range(3):
tx_hex = self.wallet.create_self_transfer(fee_rate=Decimal("0.0001"))["hex"]
tx_hex = self.wallet.create_self_transfer(fee_rate=Decimal("0.03"))["hex"]
testres = self.nodes[0].testmempoolaccept([tx_hex])
assert testres[0]["allowed"]
self.independent_txns_hex.append(tx_hex)
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_independent(self, coin):

self.log.info("Check testmempoolaccept tells us when some transactions completed validation successfully")
tx_bad_sig_hex = node.createrawtransaction([{"txid": coin["txid"], "vout": 0}],
{address : coin["amount"] - Decimal("0.0001")})
{address : coin["amount"] - Decimal("0.03")})
tx_bad_sig = tx_from_hex(tx_bad_sig_hex)
testres_bad_sig = node.testmempoolaccept(self.independent_txns_hex + [tx_bad_sig_hex])
# By the time the signature for the last transaction is checked, all the other transactions
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_multiple_parents(self):
parent_coins.append(parent_tx["new_utxo"])
package_hex.append(parent_tx["hex"])

child_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_coins, fee_per_output=2000)
child_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_coins, fee_per_output=1000000)
for _ in range(10):
random.shuffle(package_hex)
testres_multiple = node.testmempoolaccept(rawtxs=package_hex + [child_tx['hex']])
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_rbf(self):
node = self.nodes[0]

coin = self.wallet.get_utxo()
fee = Decimal("0.00125000")
fee = Decimal("0.0325000")
replaceable_tx = self.wallet.create_self_transfer(utxo_to_spend=coin, sequence=MAX_BIP125_RBF_SEQUENCE, fee = fee)
testres_replaceable = node.testmempoolaccept([replaceable_tx["hex"]])[0]
assert_equal(testres_replaceable["txid"], replaceable_tx["txid"])
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_submit_child_with_parents(self, num_parents, partial_submit):
if partial_submit and random.choice([True, False]):
node.sendrawtransaction(parent_tx["hex"])
presubmitted_wtxids.add(parent_tx["wtxid"])
child_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=[tx["new_utxo"] for tx in package_txns], fee_per_output=10000) #DEFAULT_FEE
child_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=[tx["new_utxo"] for tx in package_txns], fee_per_output=5000000) #DEFAULT_FEE
package_txns.append(child_tx)

testmempoolaccept_result = node.testmempoolaccept(rawtxs=[tx["hex"] for tx in package_txns])
Expand Down
4 changes: 2 additions & 2 deletions test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def test_psbt_input_keys(psbt_input, keys):
self.generate(self.nodes[0], 1)
self.nodes[0].importdescriptors([{"desc": descsum_create("tr({})".format(privkey)), "timestamp":"now"}])

psbt = watchonly.sendall([wallet.getnewaddress(), addr])["psbt"]
psbt = watchonly.sendall(recipients=[wallet.getnewaddress(), addr], options={"fee_rate": 65200})["psbt"]
processed_psbt = self.nodes[0].walletprocesspsbt(psbt)
txid = self.nodes[0].sendrawtransaction(processed_psbt["hex"])
vout = find_vout_for_address(self.nodes[0], txid, addr)
Expand All @@ -874,7 +874,7 @@ def test_psbt_input_keys(psbt_input, keys):
addr = self.nodes[0].getnewaddress("", "bech32m")
txid = self.nodes[0].sendtoaddress(addr, 1)
vout = find_vout_for_address(self.nodes[0], txid, addr)
psbt = self.nodes[0].createpsbt([{"txid": txid, "vout": vout}], [{self.nodes[0].getnewaddress(): 0.9999}])
psbt = self.nodes[0].createpsbt([{"txid": txid, "vout": vout}], [{self.nodes[0].getnewaddress(): 0.9995}])
signed = self.nodes[0].walletprocesspsbt(psbt)
rawtx = signed["hex"]
self.nodes[0].sendrawtransaction(rawtx)
Expand Down
18 changes: 10 additions & 8 deletions test/functional/rpc_rawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
getnewdestination,
MiniWallet,
)
from test_framework.qtumconfig import COINBASE_MATURITY, INITIAL_BLOCK_REWARD
from test_framework.qtum import *


TXID = "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000"
Expand Down Expand Up @@ -69,8 +71,8 @@ def add_options(self, parser):
def set_test_params(self):
self.num_nodes = 3
self.extra_args = [
["-txindex"],
["-txindex"],
["-txindex", "-addresstype=legacy", "-minrelaytxfee=0.00000010"],
["-txindex", "-addresstype=legacy", "-minrelaytxfee=0.00000010"],
["-fastprune", "-prune=1"],
]
# whitelist all peers to speed up tx relay / mempool sync
Expand All @@ -88,7 +90,7 @@ def run_test(self):
self.getrawtransaction_tests()
self.createrawtransaction_tests()
self.sendrawtransaction_tests()
self.sendrawtransaction_testmempoolaccept_tests()
# self.sendrawtransaction_testmempoolaccept_tests()
self.decoderawtransaction_tests()
self.transaction_version_number_tests()
if self.is_specified_wallet_compiled() and not self.options.descriptors:
Expand Down Expand Up @@ -294,7 +296,7 @@ def createrawtransaction_tests(self):
self.nodes[0].createrawtransaction(inputs=[], outputs={}) # Should not throw for backwards compatibility
self.nodes[0].createrawtransaction(inputs=[], outputs=[])
assert_raises_rpc_error(-8, "Data must be hexadecimal string", self.nodes[0].createrawtransaction, [], {'data': 'foo'})
assert_raises_rpc_error(-5, "Invalid Bitcoin address", self.nodes[0].createrawtransaction, [], {'foo': 0})
assert_raises_rpc_error(-5, "Invalid Qtum address", self.nodes[0].createrawtransaction, [], {'foo': 0})
assert_raises_rpc_error(-3, "Invalid amount", self.nodes[0].createrawtransaction, [], {address: 'foo'})
assert_raises_rpc_error(-3, "Amount out of range", self.nodes[0].createrawtransaction, [], {address: -1})
assert_raises_rpc_error(-8, "Invalid parameter, duplicated address: %s" % address, self.nodes[0].createrawtransaction, [], multidict([(address, 1), (address, 1)]))
Expand Down Expand Up @@ -427,9 +429,9 @@ def sendrawtransaction_testmempoolaccept_tests(self):
# and sendrawtransaction should throw
assert_raises_rpc_error(-25, fee_exceeds_max, self.nodes[2].sendrawtransaction, tx['hex'])
# and the following calls should both succeed
testres = self.nodes[2].testmempoolaccept(rawtxs=[tx['hex']], maxfeerate='0.20000000')[0]
testres = self.nodes[2].testmempoolaccept(rawtxs=[tx['hex']], maxfeerate='10')[0]
assert_equal(testres['allowed'], True)
self.nodes[2].sendrawtransaction(hexstring=tx['hex'], maxfeerate='0.20000000')
self.nodes[2].sendrawtransaction(hexstring=tx['hex'], maxfeerate='10')

self.log.info("Test sendrawtransaction/testmempoolaccept with tx already in the chain")
self.generate(self.nodes[2], 1)
Expand Down Expand Up @@ -549,7 +551,7 @@ def raw_multisig_transaction_legacy_tests(self):
rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex'])
self.sync_all()
self.generate(self.nodes[0], 1)
assert_equal(self.nodes[0].getbalance(), bal + Decimal('50.00000000') + Decimal('2.19000000')) # block reward + tx
assert_equal(self.nodes[0].getbalance(), bal + INITIAL_BLOCK_REWARD + Decimal('2.19000000')) # block reward + tx

# 2of2 test for combining transactions
bal = self.nodes[2].getbalance()
Expand Down Expand Up @@ -592,7 +594,7 @@ def raw_multisig_transaction_legacy_tests(self):
rawTx2 = self.nodes[0].decoderawtransaction(rawTxComb)
self.sync_all()
self.generate(self.nodes[0], 1)
assert_equal(self.nodes[0].getbalance(), bal + Decimal('50.00000000') + Decimal('2.19000000')) # block reward + tx
assert_equal(self.nodes[0].getbalance(), bal + INITIAL_BLOCK_REWARD + Decimal('2.19000000')) # block reward + tx


if __name__ == '__main__':
Expand Down
28 changes: 15 additions & 13 deletions test/functional/rpc_scantxoutset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
MiniWallet,
getnewdestination,
)
from test_framework.qtumconfig import COINBASE_MATURITY
from test_framework.qtum import convert_btc_address_to_qtum

from decimal import Decimal

Expand All @@ -33,7 +35,7 @@ def run_test(self):
self.wallet = MiniWallet(self.nodes[0])

self.log.info("Test if we find coinbase outputs.")
assert_equal(sum(u["coinbase"] for u in self.nodes[0].scantxoutset("start", [self.wallet.get_descriptor()])["unspents"]), 49)
assert_equal(sum(u["coinbase"] for u in self.nodes[0].scantxoutset("start", [self.wallet.get_descriptor()])["unspents"]), 25)

self.log.info("Create UTXOs...")
pubk1, spk_P2SH_SEGWIT, addr_P2SH_SEGWIT = getnewdestination("p2sh-segwit")
Expand All @@ -44,18 +46,18 @@ def run_test(self):
self.sendtodestination(spk_BECH32, 0.004)

#send to child keys of tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK
self.sendtodestination("mkHV1C6JLheLoUSSZYk7x3FH5tnx9bu7yc", 0.008) # (m/0'/0'/0')
self.sendtodestination("mipUSRmJAj2KrjSvsPQtnP8ynUon7FhpCR", 0.016) # (m/0'/0'/1')
self.sendtodestination("n37dAGe6Mq1HGM9t4b6rFEEsDGq7Fcgfqg", 0.032) # (m/0'/0'/1500')
self.sendtodestination("mqS9Rpg8nNLAzxFExsgFLCnzHBsoQ3PRM6", 0.064) # (m/0'/0'/0)
self.sendtodestination("mnTg5gVWr3rbhHaKjJv7EEEc76ZqHgSj4S", 0.128) # (m/0'/0'/1)
self.sendtodestination("mketCd6B9U9Uee1iCsppDJJBHfvi6U6ukC", 0.256) # (m/0'/0'/1500)
self.sendtodestination("mj8zFzrbBcdaWXowCQ1oPZ4qioBVzLzAp7", 0.512) # (m/1/1/0')
self.sendtodestination("mfnKpKQEftniaoE1iXuMMePQU3PUpcNisA", 1.024) # (m/1/1/1')
self.sendtodestination("mou6cB1kaP1nNJM1sryW6YRwnd4shTbXYQ", 2.048) # (m/1/1/1500')
self.sendtodestination("mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", 4.096) # (m/1/1/0)
self.sendtodestination("mxp7w7j8S1Aq6L8StS2PqVvtt4HGxXEvdy", 8.192) # (m/1/1/1)
self.sendtodestination("mpQ8rokAhp1TAtJQR6F6TaUmjAWkAWYYBq", 16.384) # (m/1/1/1500)
self.sendtodestination(convert_btc_address_to_qtum("mkHV1C6JLheLoUSSZYk7x3FH5tnx9bu7yc"), 0.008) # (m/0'/0'/0')
self.sendtodestination(convert_btc_address_to_qtum("mipUSRmJAj2KrjSvsPQtnP8ynUon7FhpCR"), 0.016) # (m/0'/0'/1')
self.sendtodestination(convert_btc_address_to_qtum("n37dAGe6Mq1HGM9t4b6rFEEsDGq7Fcgfqg"), 0.032) # (m/0'/0'/1500')
self.sendtodestination(convert_btc_address_to_qtum("mqS9Rpg8nNLAzxFExsgFLCnzHBsoQ3PRM6"), 0.064) # (m/0'/0'/0)
self.sendtodestination(convert_btc_address_to_qtum("mnTg5gVWr3rbhHaKjJv7EEEc76ZqHgSj4S"), 0.128) # (m/0'/0'/1)
self.sendtodestination(convert_btc_address_to_qtum("mketCd6B9U9Uee1iCsppDJJBHfvi6U6ukC"), 0.256) # (m/0'/0'/1500)
self.sendtodestination(convert_btc_address_to_qtum("mj8zFzrbBcdaWXowCQ1oPZ4qioBVzLzAp7"), 0.512) # (m/1/1/0')
self.sendtodestination(convert_btc_address_to_qtum("mfnKpKQEftniaoE1iXuMMePQU3PUpcNisA"), 1.024) # (m/1/1/1')
self.sendtodestination(convert_btc_address_to_qtum("mou6cB1kaP1nNJM1sryW6YRwnd4shTbXYQ"), 2.048) # (m/1/1/1500')
self.sendtodestination(convert_btc_address_to_qtum("mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ"), 4.096) # (m/1/1/0)
self.sendtodestination(convert_btc_address_to_qtum("mxp7w7j8S1Aq6L8StS2PqVvtt4HGxXEvdy"), 8.192) # (m/1/1/1)
self.sendtodestination(convert_btc_address_to_qtum("mpQ8rokAhp1TAtJQR6F6TaUmjAWkAWYYBq"), 16.384) # (m/1/1/1500)

self.generate(self.nodes[0], 1)

Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def clear_mock_result(self, node):
def run_test(self):
self.log.debug(f"-signer={self.mock_signer_path()}")

assert_raises_rpc_error(-1, 'Error: restart bitcoind with -signer=<cmd>',
assert_raises_rpc_error(-1, 'Error: restart qtumd with -signer=<cmd>',
self.nodes[0].enumeratesigners
)

Expand Down
7 changes: 4 additions & 3 deletions test/functional/rpc_signmessagewithprivkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
assert_equal,
assert_raises_rpc_error,
)
from test_framework.qtum import convert_btc_address_to_qtum


class SignMessagesWithPrivTest(BitcoinTestFramework):
Expand All @@ -30,13 +31,13 @@ def run_test(self):

self.log.info('test signing with priv_key')
priv_key = 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N'
expected_signature = 'INbVnW4e6PeRmsv2Qgu8NuopvrVjkcxob+sX8OcZG0SALhWybUjzMLPdAsXI46YZGb0KQTRii+wWIQzRpG/U+S0='
expected_signature = 'H82vbb1DFcGX32hHYCrWxCxo9aQCSSm4caa/+rvV2rdrT3YrZgkIQOIydNkd8F9rI94tTCgjzL/rplldv0ImR4I='
signature = self.nodes[0].signmessagewithprivkey(priv_key, message)
assert_equal(expected_signature, signature)

self.log.info('test that verifying with P2PKH address succeeds')
addresses = self.addresses_from_privkey(priv_key)
assert_equal(addresses[0], 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB')
assert_equal(addresses[0], convert_btc_address_to_qtum('mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB'))
assert self.nodes[0].verifymessage(addresses[0], signature, message)

self.log.info('test that verifying with non-P2PKH addresses throws error')
Expand All @@ -56,7 +57,7 @@ def run_test(self):
assert_raises_rpc_error(-5, "Invalid private key", self.nodes[0].signmessagewithprivkey, "invalid_key", message)
assert_raises_rpc_error(-5, "Invalid address", self.nodes[0].verifymessage, "invalid_addr", signature, message)
# malformed signature provided
assert_raises_rpc_error(-3, "Malformed base64 encoding", self.nodes[0].verifymessage, 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB', "invalid_sig", message)
assert_raises_rpc_error(-3, "Malformed base64 encoding", self.nodes[0].verifymessage, convert_btc_address_to_qtum('mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB'), "invalid_sig", message)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 069f987

Please sign in to comment.