Skip to content

Commit

Permalink
Port python tests part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Aug 13, 2024
1 parent 2aea7e8 commit a47fbc7
Show file tree
Hide file tree
Showing 32 changed files with 503 additions and 299 deletions.
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
48 changes: 26 additions & 22 deletions test/functional/rpc_invalid_address_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,42 @@
"""Test error messages for 'getaddressinfo' and 'validateaddress' RPC commands."""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.qtum import convert_btc_bech32_address_to_qtum

from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)

BECH32_VALID = 'bcrt1qtmp74ayg7p24uslctssvjm06q5phz4yrxucgnv'
BECH32_VALID_CAPITALS = 'BCRT1QPLMTZKC2XHARPPZDLNPAQL78RSHJ68U33RAH7R'
BECH32_VALID_MULTISIG = 'bcrt1qdg3myrgvzw7ml9q0ejxhlkyxm7vl9r56yzkfgvzclrf4hkpx9yfqhpsuks'

BECH32_INVALID_BECH32 = 'bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqdmchcc'
BECH32_INVALID_BECH32M = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7k35mrzd'
BECH32_INVALID_VERSION = 'bcrt130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqynjegk'
BECH32_INVALID_SIZE = 'bcrt1s0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav25430mtr'
BECH32_INVALID_V0_SIZE = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kqqq5k3my'
BECH32_INVALID_PREFIX = 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx'
BECH32_TOO_LONG = 'bcrt1q049edschfnwystcqnsvyfpj23mpsg3jcedq9xv049edschfnwystcqnsvyfpj23mpsg3jcedq9xv049edschfnwystcqnsvyfpj23m'
BECH32_ONE_ERROR = 'bcrt1q049edschfnwystcqnsvyfpj23mpsg3jcedq9xv'
BECH32_ONE_ERROR_CAPITALS = 'BCRT1QPLMTZKC2XHARPPZDLNPAQL78RSHJ68U32RAH7R'
BECH32_TWO_ERRORS = 'bcrt1qax9suht3qv95sw33xavx8crpxduefdrsvgsklu' # should be bcrt1qax9suht3qv95sw33wavx8crpxduefdrsvgsklx
BECH32_NO_SEPARATOR = 'bcrtq049ldschfnwystcqnsvyfpj23mpsg3jcedq9xv'
BECH32_INVALID_CHAR = 'bcrt1q04oldschfnwystcqnsvyfpj23mpsg3jcedq9xv'
BECH32_MULTISIG_TWO_ERRORS = 'bcrt1qdg3myrgvzw7ml8q0ejxhlkyxn7vl9r56yzkfgvzclrf4hkpx9yfqhpsuks'
BECH32_WRONG_VERSION = 'bcrt1ptmp74ayg7p24uslctssvjm06q5phz4yrxucgnv'

BASE58_VALID = 'mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn'
import test_framework.segwit_addr

BECH32_VALID = convert_btc_bech32_address_to_qtum('bcrt1qtmp74ayg7p24uslctssvjm06q5phz4yrxucgnv')
BECH32_VALID_CAPITALS = convert_btc_bech32_address_to_qtum('BCRT1QPLMTZKC2XHARPPZDLNPAQL78RSHJ68U33RAH7R')
BECH32_VALID_MULTISIG = convert_btc_bech32_address_to_qtum('bcrt1qdg3myrgvzw7ml9q0ejxhlkyxm7vl9r56yzkfgvzclrf4hkpx9yfqhpsuks')

BECH32_INVALID_BECH32 = convert_btc_bech32_address_to_qtum('bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqdmchcc')
BECH32_INVALID_BECH32M = convert_btc_bech32_address_to_qtum('bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7k35mrzd')
BECH32_INVALID_VERSION = convert_btc_bech32_address_to_qtum('bcrt130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqynjegk')
BECH32_INVALID_SIZE = convert_btc_bech32_address_to_qtum('bcrt1s0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav25430mtr')
BECH32_INVALID_V0_SIZE = convert_btc_bech32_address_to_qtum('bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kqqq5k3my')
BECH32_INVALID_PREFIX = 'qc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx'
BECH32_TOO_LONG = 'qcrt1q049edschfnwystcqnsvyfpj23mpsg3jcedq9xv049edschfnwystcqnsvyfpj23mpsg3jcedq9xv049edschfnwystcqnsvyfpj23m'
BECH32_ONE_ERROR = 'qcrt1qkkcddf3qa8s7k65uc9rn8pz3jsjxfl4wqel08t'
BECH32_ONE_ERROR_CAPITALS = 'QCRT1QKKCFDF3QA8S7K65UC9RN8PZ3JSJXFL4WEEL08T'
BECH32_TWO_ERRORS = 'qcrt1qkkcfdf3qa8s7k65uf9rn8pz3jsjxfl4wqel088' # should be bcrt1qax9suht3qv95sw33wavx8crpxduefdrsvgsklx
BECH32_NO_SEPARATOR = 'qcrtq049ldschfnwystcqnsvyfpj23mpsg3jcedq9xv'
BECH32_INVALID_CHAR = 'qcrt1q04oldschfnwystcqnsvyfpj23mpsg3jcedq9xv'
BECH32_MULTISIG_TWO_ERRORS = 'qcrt1q7j7t9yc7jkmfa3h0285lju666d8jwahafu3vwl6hcfdeuxj7xwzsd3yamp'
BECH32_WRONG_VERSION = 'qcrt1p6crvu0zcfn0mag6drc03ufg6n49sfel08grxx7'


BASE58_VALID = 'qVU2jTzGzLgT6PdEd2iBynRFDs8jRP4Kmv'
BASE58_INVALID_PREFIX = '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem'
BASE58_INVALID_CHECKSUM = 'mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJJfn'
BASE58_INVALID_LENGTH = '2VKf7XKMrp4bVNVmuRbyCewkP8FhGLP2E54LHDPakr9Sq5mtU2'

INVALID_ADDRESS = 'asfah14i8fajz0123f'
INVALID_ADDRESS_2 = '1q049ldschfnwystcqnsvyfpj23mpsg3jcedq9xv'
INVALID_ADDRESS_2 = '1qkkcddf3qa8s7k65uc9rn8pz3jsjxfl4wqel08t'

class InvalidAddressErrorMessageTest(BitcoinTestFramework):
def add_options(self, parser):
Expand Down Expand Up @@ -98,7 +102,7 @@ def test_validateaddress(self):
node = self.nodes[0]

# Missing arg returns the help text
assert_raises_rpc_error(-1, "Return information about the given bitcoin address.", node.validateaddress)
assert_raises_rpc_error(-1, "Return information about the given qtum address.", node.validateaddress)
# Explicit None is not allowed for required parameters
assert_raises_rpc_error(-3, "JSON value of type null is not of expected type string", node.validateaddress, None)

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
Loading

0 comments on commit a47fbc7

Please sign in to comment.