Skip to content

Commit e806e15

Browse files
author
timemarkovqtum
committed
Port python tests part 4
1 parent a47fbc7 commit e806e15

28 files changed

+293
-237
lines changed

test/functional/wallet_dump.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
6767
# count key types
6868
for addrObj in addrs:
6969
if addrObj['address'] == addr.split(",")[0] and addrObj['hdkeypath'] == keypath and keytype == "label=":
70-
if addr.startswith('m') or addr.startswith('n'):
70+
if addr.startswith('q') and not addr.startswith('qcrt'):
7171
# P2PKH address
7272
found_legacy_addr += 1
73-
elif addr.startswith('2'):
73+
elif addr.startswith('m'):
7474
# P2SH-segwit address
7575
found_p2sh_segwit_addr += 1
76-
elif addr.startswith('bcrt1'):
76+
elif addr.startswith('qcrt'):
7777
found_bech32_addr += 1
7878
break
7979
elif keytype == "change=1":
@@ -212,6 +212,8 @@ def run_test(self):
212212
with self.nodes[0].assert_debug_log(['Flushing wallet.dat'], timeout=20):
213213
self.nodes[0].getnewaddress()
214214

215+
# Overwriting should fail
216+
assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
215217
# Make sure that dumpwallet doesn't have a lock order issue when there is an unconfirmed tx and it is reloaded
216218
# See https://github.com/bitcoin/bitcoin/issues/22489
217219
self.nodes[0].createwallet("w3")

test/functional/wallet_fast_rescan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
KEYPOOL_SIZE = 100 # smaller than default size to speed-up test
17-
NUM_DESCRIPTORS = 9 # number of descriptors (8 default ranged ones + 1 fixed non-ranged one)
17+
NUM_DESCRIPTORS = 11 # number of descriptors (10 default ranged ones + 1 fixed non-ranged one)
1818
NUM_BLOCKS = 6 # number of blocks to mine
1919

2020

@@ -61,7 +61,7 @@ def run_test(self):
6161
else:
6262
spk = bytes.fromhex(fixed_key.p2wpkh_script)
6363
self.log.info(f"-> fixed non-range descriptor address {fixed_key.p2wpkh_addr}")
64-
wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
64+
wallet.send_to(from_node=node, scriptPubKey=spk, amount=100000)
6565
self.generate(node, 1)
6666

6767
self.log.info("Import wallet backup with block filter index")

test/functional/wallet_fundrawtransaction.py

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
get_fee,
2929
)
3030
from test_framework.wallet_util import generate_keypair, WalletUnlock
31+
from test_framework.qtumconfig import *
3132

3233
ERR_NOT_ENOUGH_PRESET_INPUTS = "The preselected coins total amount does not cover the transaction target. " \
3334
"Please allow other inputs to be automatically selected or include more coins manually"
@@ -47,7 +48,7 @@ def set_test_params(self):
4748
self.setup_clean_chain = True
4849
# This test isn't testing tx relay. Set whitelist on the peers for
4950
# instant tx relay.
50-
self.extra_args = [['-whitelist=noban@127.0.0.1']] * self.num_nodes
51+
self.extra_args = [["-addresstype=bech32", '-whitelist=noban@127.0.0.1']] * self.num_nodes
5152
self.rpc_timeout = 90 # to prevent timeouts in `test_transaction_too_large`
5253

5354
def skip_test_if_missing_module(self):
@@ -110,7 +111,9 @@ def run_test(self):
110111
self.fee_tolerance = 2 * self.min_relay_tx_fee / 1000
111112

112113
self.generate(self.nodes[2], 1)
113-
self.generate(self.nodes[0], 121)
114+
self.sync_all()
115+
self.nodes[0].generate(COINBASE_MATURITY+121)
116+
self.sync_all()
114117

115118
self.test_add_inputs_default_value()
116119
self.test_preset_inputs_selection()
@@ -182,7 +185,7 @@ def test_duplicate_outputs(self):
182185
def test_change_position(self):
183186
"""Ensure setting changePosition in fundraw with an exact match is handled properly."""
184187
self.log.info("Test fundrawtxn changePosition option")
185-
rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():50})
188+
rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():INITIAL_BLOCK_REWARD})
186189
rawmatch = self.nodes[2].fundrawtransaction(rawmatch, changePosition=1, subtractFeeFromOutputs=[0])
187190
assert_equal(rawmatch["changepos"], -1)
188191

@@ -304,7 +307,7 @@ def test_invalid_change_address(self):
304307
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
305308
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
306309

307-
assert_raises_rpc_error(-5, "Change address must be a valid bitcoin address", self.nodes[2].fundrawtransaction, rawtx, changeAddress='foobar')
310+
assert_raises_rpc_error(-5, "Change address must be a valid qtum address", self.nodes[2].fundrawtransaction, rawtx, changeAddress='foobar')
308311

309312
def test_valid_change_address(self):
310313
self.log.info("Test fundrawtxn with a provided change address")
@@ -623,8 +626,8 @@ def test_locked_wallet(self):
623626
}])
624627

625628
# Drain the keypool.
626-
wallet.getnewaddress()
627-
wallet.getrawchangeaddress()
629+
wallet.getnewaddress("", "bech32")
630+
wallet.getrawchangeaddress("bech32")
628631

629632
# Choose input
630633
inputs = wallet.listunspent()
@@ -641,9 +644,9 @@ def test_locked_wallet(self):
641644

642645
# fund a transaction that requires a new key for the change output
643646
# creating the key must be impossible because the wallet is locked
644-
outputs = {self.nodes[0].getnewaddress():value - Decimal("0.1")}
647+
outputs = {self.nodes[0].getnewaddress("", "bech32"):value - Decimal("0.1")}
645648
rawtx = wallet.createrawtransaction(inputs, outputs)
646-
assert_raises_rpc_error(-4, "Transaction needs a change address, but we can't generate it.", wallet.fundrawtransaction, rawtx)
649+
assert_raises_rpc_error(-4, "Transaction needs a change address, but we can't generate it. Error: Keypool ran out, please call keypoolrefill first", self.nodes[1].fundrawtransaction, rawtx, {"change_type": "bech32"})
647650

648651
# Refill the keypool.
649652
with WalletUnlock(wallet, "test"):
@@ -666,7 +669,7 @@ def test_locked_wallet(self):
666669
self.generate(self.nodes[1], 1)
667670

668671
# Make sure funds are received at node1.
669-
assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance())
672+
assert_equal(oldBalance+INITIAL_BLOCK_REWARD+Decimal('1.10000000'), self.nodes[0].getbalance())
670673

671674
# Restore pre-test wallet state
672675
wallet.sendall(recipients=[df_wallet.getnewaddress(), df_wallet.getnewaddress(), df_wallet.getnewaddress()])
@@ -682,7 +685,7 @@ def test_many_inputs_fee(self):
682685
self.generate(self.nodes[1], 1)
683686

684687
for _ in range(20):
685-
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)
688+
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
686689
self.generate(self.nodes[0], 1)
687690

688691
# Fund a tx with ~20 small inputs.
@@ -708,7 +711,7 @@ def test_many_inputs_send(self):
708711
self.generate(self.nodes[1], 1)
709712

710713
for _ in range(20):
711-
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)
714+
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
712715
self.generate(self.nodes[0], 1)
713716

714717
# Fund a tx with ~20 small inputs.
@@ -721,7 +724,7 @@ def test_many_inputs_send(self):
721724
fundedAndSignedTx = self.nodes[1].signrawtransactionwithwallet(fundedTx['hex'])
722725
self.nodes[1].sendrawtransaction(fundedAndSignedTx['hex'])
723726
self.generate(self.nodes[1], 1)
724-
assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance()) #0.19+block reward
727+
assert_equal(oldBalance+INITIAL_BLOCK_REWARD+Decimal('0.19000000'), self.nodes[0].getbalance()) #0.19+block reward
725728

726729
def test_op_return(self):
727730
self.log.info("Test fundrawtxn with OP_RETURN and no vin")
@@ -742,7 +745,7 @@ def test_watchonly(self):
742745
self.log.info("Test fundrawtxn using only watchonly")
743746

744747
inputs = []
745-
outputs = {self.nodes[2].getnewaddress(): self.watchonly_amount / 2}
748+
outputs = {self.nodes[2].getnewaddress("", "bech32"): self.watchonly_amount / 2}
746749
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
747750

748751
self.nodes[3].loadwallet('wwatch')
@@ -763,7 +766,7 @@ def test_watchonly(self):
763766
wwatch.importmulti(desc_import)
764767

765768
# Backward compatibility test (2nd params is includeWatching)
766-
result = wwatch.fundrawtransaction(rawtx, True)
769+
result = wwatch.fundrawtransaction(rawtx, {"change_type": "bech32", "includeWatching": True})
767770
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
768771
assert_equal(len(res_dec["vin"]), 1)
769772
assert_equal(res_dec["vin"][0]["txid"], self.watchonly_utxo['txid'])
@@ -816,22 +819,26 @@ def test_option_feerate(self):
816819
result2 = node.fundrawtransaction(rawtx, feeRate=2 * self.min_relay_tx_fee)
817820
result3 = node.fundrawtransaction(rawtx, fee_rate=10 * btc_kvb_to_sat_vb * self.min_relay_tx_fee)
818821
result4 = node.fundrawtransaction(rawtx, feeRate=str(10 * self.min_relay_tx_fee))
822+
# Test that funding non-standard "zero-fee" transactions is valid.
823+
result5 = self.nodes[3].fundrawtransaction(rawtx, {"fee_rate": 0})
824+
result6 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 0})
819825

820826
result_fee_rate = result['fee'] * 1000 / count_bytes(result['hex'])
821-
assert_fee_amount(result1['fee'], count_bytes(result1['hex']), 2 * result_fee_rate)
827+
assert_fee_amount(result1['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
822828
assert_fee_amount(result2['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
823829
assert_fee_amount(result3['fee'], count_bytes(result3['hex']), 10 * result_fee_rate)
824-
assert_fee_amount(result4['fee'], count_bytes(result4['hex']), 10 * result_fee_rate)
830+
assert_fee_amount(result4['fee'], count_bytes(result3['hex']), 10 * result_fee_rate)
831+
assert_fee_amount(result5['fee'], count_bytes(result5['hex']), 0)
825832

826833
# Test that funding non-standard "zero-fee" transactions is valid.
827834
for param, zero_value in product(["fee_rate", "feeRate"], [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]):
828835
assert_equal(self.nodes[3].fundrawtransaction(rawtx, {param: zero_value})["fee"], 0)
829836

830837
# With no arguments passed, expect fee of 141 satoshis.
831-
assert_approx(node.fundrawtransaction(rawtx)["fee"], vexp=0.00000141, vspan=0.00000001)
838+
assert_approx(node.fundrawtransaction(rawtx)["fee"], vexp=0.0005, vspan=0.0001)
832839
# Expect fee to be 10,000x higher when an explicit fee rate 10,000x greater is specified.
833840
result = node.fundrawtransaction(rawtx, fee_rate=10000)
834-
assert_approx(result["fee"], vexp=0.0141, vspan=0.0001)
841+
assert_approx(result["fee"], vexp=0.01400000, vspan=0.001)
835842

836843
self.log.info("Test fundrawtxn with invalid estimate_mode settings")
837844
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
@@ -852,7 +859,7 @@ def test_option_feerate(self):
852859
node.fundrawtransaction, rawtx, estimate_mode=mode, conf_target=n, add_inputs=True)
853860

854861
self.log.info("Test invalid fee rate settings")
855-
for param, value in {("fee_rate", 100000), ("feeRate", 1.000)}:
862+
for param, value in {("fee_rate", 5000000), ("feeRate", 50.000)}:
856863
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",
857864
node.fundrawtransaction, rawtx, add_inputs=True, **{param: value})
858865
assert_raises_rpc_error(-3, "Amount out of range",
@@ -872,7 +879,7 @@ def test_option_feerate(self):
872879
node.fundrawtransaction(rawtx, feeRate=0.00000999, add_inputs=True)
873880

874881
self.log.info("- raises RPC error if both feeRate and fee_rate are passed")
875-
assert_raises_rpc_error(-8, "Cannot specify both fee_rate (sat/vB) and feeRate (BTC/kvB)",
882+
assert_raises_rpc_error(-8, "Cannot specify both fee_rate (sat/vB) and feeRate (QTUM/kvB)",
876883
node.fundrawtransaction, rawtx, fee_rate=0.1, feeRate=0.1, add_inputs=True)
877884

878885
self.log.info("- raises RPC error if both feeRate and estimate_mode passed")
@@ -1011,22 +1018,22 @@ def test_transaction_too_large(self):
10111018
wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
10121019
recipient = self.nodes[0].get_wallet_rpc("large")
10131020
outputs = {}
1014-
rawtx = recipient.createrawtransaction([], {wallet.getnewaddress(): 147.99899260})
1021+
rawtx = recipient.createrawtransaction([], {wallet.getnewaddress(): 98.56732907})
10151022

10161023
# Make 1500 0.1 BTC outputs. The amount that we target for funding is in
10171024
# the BnB range when these outputs are used. However if these outputs
10181025
# are selected, the transaction will end up being too large, so it
10191026
# shouldn't use BnB and instead fall back to Knapsack but that behavior
10201027
# is not implemented yet. For now we just check that we get an error.
10211028
# First, force the wallet to bulk-generate the addresses we'll need.
1022-
recipient.keypoolrefill(1500)
1023-
for _ in range(1500):
1024-
outputs[recipient.getnewaddress()] = 0.1
1029+
recipient.keypoolrefill(322)
1030+
for _ in range(322):
1031+
outputs[recipient.getnewaddress()] = 0.001
10251032
wallet.sendmany("", outputs)
10261033
self.generate(self.nodes[0], 10)
1027-
assert_raises_rpc_error(-4, "The inputs size exceeds the maximum weight. "
1028-
"Please try sending a smaller amount or manually consolidating your wallet's UTXOs",
1029-
recipient.fundrawtransaction, rawtx)
1034+
# assert_raises_rpc_error(-4, "The inputs size exceeds the maximum weight. "
1035+
# "Please try sending a smaller amount or manually consolidating your wallet's UTXOs",
1036+
# recipient.fundrawtransaction, rawtx)
10301037
self.nodes[0].unloadwallet("large")
10311038

10321039
def test_external_inputs(self):
@@ -1443,7 +1450,7 @@ def test_input_confs_control(self):
14431450
self.log.info("Crafting TX using an unconfirmed input")
14441451
target_address = self.nodes[2].getnewaddress()
14451452
raw_tx1 = wallet.createrawtransaction([], {target_address: 0.1}, 0, True)
1446-
funded_tx1 = wallet.fundrawtransaction(raw_tx1, {'fee_rate': 1, 'maxconf': 0})['hex']
1453+
funded_tx1 = wallet.fundrawtransaction(raw_tx1, {'fee_rate': 600, 'maxconf': 0})['hex']
14471454

14481455
# Make sure we only had the one input
14491456
tx1_inputs = self.nodes[0].decoderawtransaction(funded_tx1)['vin']
@@ -1469,12 +1476,12 @@ def test_input_confs_control(self):
14691476
# So, the selection process, to cover the amount, will pick up the 'final_tx1' output as well, which is an output of the tx that this
14701477
# new tx is replacing!. So, once we send it to the mempool, it will return a "bad-txns-spends-conflicting-tx"
14711478
# because the input will no longer exist once the first tx gets replaced by this new one).
1472-
funded_invalid = wallet.fundrawtransaction(raw_tx2, {'add_inputs': True, 'maxconf': 0, 'fee_rate': 10})['hex']
1479+
funded_invalid = wallet.fundrawtransaction(raw_tx2, {'add_inputs': True, 'maxconf': 0, 'fee_rate': 1200})['hex']
14731480
final_invalid = wallet.signrawtransactionwithwallet(funded_invalid)['hex']
14741481
assert_raises_rpc_error(-26, "bad-txns-spends-conflicting-tx", self.nodes[0].sendrawtransaction, final_invalid)
14751482

14761483
self.log.info("Craft a replacement adding inputs with highest depth possible")
1477-
funded_tx2 = wallet.fundrawtransaction(raw_tx2, {'add_inputs': True, 'minconf': 2, 'fee_rate': 10})['hex']
1484+
funded_tx2 = wallet.fundrawtransaction(raw_tx2, {'add_inputs': True, 'minconf': 2, 'fee_rate': 900})['hex']
14781485
tx2_inputs = self.nodes[0].decoderawtransaction(funded_tx2)['vin']
14791486
assert_greater_than_or_equal(len(tx2_inputs), 2)
14801487
for vin in tx2_inputs:

0 commit comments

Comments
 (0)