mirror of
https://github.com/basicswap/basicswap.git
synced 2026-06-08 04:01:41 +02:00
fix: get refund tx block info for CSV check
This commit is contained in:
@@ -236,11 +236,17 @@ def wait_for_bid(
|
||||
)
|
||||
if isinstance(state, (list, tuple)):
|
||||
if bid[5] in state:
|
||||
swap_client.log.debug(
|
||||
f"TEST: wait_for_bid found {bid_id.hex()}: Bid state {bid[5]}, target {state}."
|
||||
)
|
||||
return
|
||||
else:
|
||||
continue
|
||||
elif state is not None and state != bid[5]:
|
||||
continue
|
||||
swap_client.log.debug(
|
||||
f"TEST: wait_for_bid found {bid_id.hex()}: Bid state {bid[5]}, target {state}."
|
||||
)
|
||||
return
|
||||
else:
|
||||
if i > 0 and i % 10 == 0:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2024 tecnovert
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -75,24 +75,6 @@ def make_rpc_func(node_id, base_rpc_port):
|
||||
return rpc_func
|
||||
|
||||
|
||||
def wait_for_dcr_height(http_port, num_blocks=3):
|
||||
logging.info("Waiting for DCR chain height %d", num_blocks)
|
||||
for i in range(60):
|
||||
if test_delay_event.is_set():
|
||||
raise ValueError("Test stopped.")
|
||||
try:
|
||||
wallet = read_json_api(http_port, "wallets/dcr")
|
||||
decred_blocks = wallet["blocks"]
|
||||
print("decred_blocks", decred_blocks)
|
||||
if decred_blocks >= num_blocks:
|
||||
return
|
||||
except Exception as e:
|
||||
print("Error reading wallets", str(e))
|
||||
|
||||
test_delay_event.wait(1)
|
||||
raise ValueError(f"wait_for_decred_blocks failed http_port: {http_port}")
|
||||
|
||||
|
||||
def run_test_success_path(self, coin_from: Coins, coin_to: Coins):
|
||||
logging.info(f"---------- Test {coin_from.name} to {coin_to.name}")
|
||||
|
||||
@@ -878,15 +860,16 @@ class Test(BaseTest):
|
||||
"use_csv": True,
|
||||
"use_segwit": True,
|
||||
"blocks_confirmed": 1,
|
||||
"min_relay_fee": 0.00001,
|
||||
}
|
||||
|
||||
def test_0001_decred_address(self):
|
||||
logging.info("---------- Test {}".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name}")
|
||||
|
||||
coin_settings = {"rpcport": 0, "rpcauth": "none"}
|
||||
coin_settings.update(REQUIRED_SETTINGS)
|
||||
|
||||
ci = DCRInterface(coin_settings, "mainnet")
|
||||
ci = DCRInterface(coin_settings, "mainnet", self.swap_clients[0])
|
||||
|
||||
k = ci.getNewRandomKey()
|
||||
K = ci.getPubkey(k)
|
||||
@@ -914,7 +897,7 @@ class Test(BaseTest):
|
||||
assert hash160(masterpubkey_data) == seed_hash
|
||||
|
||||
def test_001_segwit(self):
|
||||
logging.info("---------- Test {} segwit".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} segwit")
|
||||
|
||||
swap_clients = self.swap_clients
|
||||
ci0 = swap_clients[0].ci(self.test_coin)
|
||||
@@ -972,7 +955,7 @@ class Test(BaseTest):
|
||||
assert f_decoded["txid"] == ctx.TxHash().hex()
|
||||
|
||||
def test_003_signature_hash(self):
|
||||
logging.info("---------- Test {} signature_hash".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} signature_hash")
|
||||
# Test that signing a transaction manually produces the same result when signed with the wallet
|
||||
|
||||
swap_clients = self.swap_clients
|
||||
@@ -1047,7 +1030,7 @@ class Test(BaseTest):
|
||||
assert len(sent_txid) == 64
|
||||
|
||||
def test_004_csv(self):
|
||||
logging.info("---------- Test {} csv".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} csv")
|
||||
swap_clients = self.swap_clients
|
||||
ci0 = swap_clients[0].ci(self.test_coin)
|
||||
|
||||
@@ -1161,7 +1144,7 @@ class Test(BaseTest):
|
||||
assert sent_spend_txid is not None
|
||||
|
||||
def test_005_watchonly(self):
|
||||
logging.info("---------- Test {} watchonly".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} watchonly")
|
||||
|
||||
swap_clients = self.swap_clients
|
||||
ci0 = swap_clients[0].ci(self.test_coin)
|
||||
@@ -1261,7 +1244,7 @@ class Test(BaseTest):
|
||||
assert found_txid is not None
|
||||
|
||||
def test_008_gettxout(self):
|
||||
logging.info("---------- Test {} gettxout".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} gettxout")
|
||||
|
||||
ci0 = self.swap_clients[0].ci(self.test_coin)
|
||||
|
||||
@@ -1373,7 +1356,7 @@ class Test(BaseTest):
|
||||
assert amount_proved >= require_amount
|
||||
|
||||
def test_009_wallet_encryption(self):
|
||||
logging.info("---------- Test {} wallet encryption".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} wallet encryption")
|
||||
|
||||
for coin in ("part", "dcr", "xmr"):
|
||||
jsw = read_json_api(1800, f"wallets/{coin}")
|
||||
@@ -1412,7 +1395,7 @@ class Test(BaseTest):
|
||||
assert jsw["locked"] is False
|
||||
|
||||
def test_010_txn_size(self):
|
||||
logging.info("---------- Test {} txn size".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} txn size")
|
||||
|
||||
swap_clients = self.swap_clients
|
||||
ci = swap_clients[0].ci(self.test_coin)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -167,6 +167,7 @@ class TestBCH(BasicSwapTest):
|
||||
|
||||
@classmethod
|
||||
def prepareExtraCoins(cls):
|
||||
super().prepareExtraCoins()
|
||||
cls.bch_addr = callnoderpc(
|
||||
0,
|
||||
"getnewaddress",
|
||||
@@ -197,11 +198,12 @@ class TestBCH(BasicSwapTest):
|
||||
"datadir": os.path.join(datadir, "bch_" + str(node_id)),
|
||||
"bindir": BITCOINCASH_BINDIR,
|
||||
"use_segwit": False,
|
||||
"wallet_name": "bsx_wallet",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def coins_loop(cls):
|
||||
super(TestBCH, cls).coins_loop()
|
||||
super().coins_loop()
|
||||
ci0 = cls.swap_clients[0].ci(cls.test_coin)
|
||||
try:
|
||||
if cls.bch_addr is not None:
|
||||
@@ -212,7 +214,7 @@ class TestBCH(BasicSwapTest):
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
logging.info("Finalising Bitcoincash Test")
|
||||
super(TestBCH, cls).tearDownClass()
|
||||
super().tearDownClass()
|
||||
|
||||
stopDaemons(cls.bch_daemons)
|
||||
cls.bch_daemons.clear()
|
||||
@@ -224,19 +226,15 @@ class TestBCH(BasicSwapTest):
|
||||
return True
|
||||
|
||||
def test_001_nested_segwit(self):
|
||||
logging.info(
|
||||
"---------- Test {} p2sh nested segwit".format(self.test_coin.name)
|
||||
)
|
||||
logging.info(f"---------- Test {self.test_coin.name} p2sh nested segwit")
|
||||
logging.info("Skipped")
|
||||
|
||||
def test_002_native_segwit(self):
|
||||
logging.info(
|
||||
"---------- Test {} p2sh native segwit".format(self.test_coin.name)
|
||||
)
|
||||
logging.info(f"---------- Test {self.test_coin.name} p2sh native segwit")
|
||||
logging.info("Skipped")
|
||||
|
||||
def test_003_cltv(self):
|
||||
logging.info("---------- Test {} cltv".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} cltv")
|
||||
|
||||
ci = self.swap_clients[0].ci(self.test_coin)
|
||||
|
||||
@@ -348,7 +346,7 @@ class TestBCH(BasicSwapTest):
|
||||
assert len(tx_wallet["blockhash"]) == 64
|
||||
|
||||
def test_004_csv(self):
|
||||
logging.info("---------- Test {} csv".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} csv")
|
||||
|
||||
ci = self.swap_clients[0].ci(self.test_coin)
|
||||
|
||||
@@ -451,7 +449,7 @@ class TestBCH(BasicSwapTest):
|
||||
assert len(tx_wallet["blockhash"]) == 64
|
||||
|
||||
def test_005_watchonly(self):
|
||||
logging.info("---------- Test {} watchonly".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} watchonly")
|
||||
ci = self.swap_clients[0].ci(self.test_coin)
|
||||
ci1 = self.swap_clients[1].ci(self.test_coin)
|
||||
|
||||
@@ -482,7 +480,7 @@ class TestBCH(BasicSwapTest):
|
||||
super().test_006_getblock_verbosity()
|
||||
|
||||
def test_007_hdwallet(self):
|
||||
logging.info("---------- Test {} hdwallet".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} hdwallet")
|
||||
|
||||
test_seed = "8e54a313e6df8918df6d758fafdbf127a115175fdd2238d0e908dd8093c9ac3b"
|
||||
test_wif = (
|
||||
@@ -506,10 +504,10 @@ class TestBCH(BasicSwapTest):
|
||||
super().test_009_scantxoutset()
|
||||
|
||||
def test_010_txn_size(self):
|
||||
logging.info("---------- Test {} txn_size".format(Coins.BCH))
|
||||
logging.info(f"---------- Test {self.test_coin.name} txn_size")
|
||||
|
||||
swap_clients = self.swap_clients
|
||||
ci = swap_clients[0].ci(Coins.BCH)
|
||||
ci = swap_clients[0].ci(self.test_coin)
|
||||
pi = swap_clients[0].pi(SwapTypes.XMR_SWAP)
|
||||
|
||||
amount: int = ci.make_int(random.uniform(0.1, 2.0), r=1)
|
||||
@@ -627,7 +625,7 @@ class TestBCH(BasicSwapTest):
|
||||
|
||||
def test_011_p2sh(self):
|
||||
# Not used in bsx for native-segwit coins
|
||||
logging.info("---------- Test {} p2sh".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} p2sh")
|
||||
|
||||
ci = self.swap_clients[0].ci(self.test_coin)
|
||||
|
||||
@@ -717,7 +715,7 @@ class TestBCH(BasicSwapTest):
|
||||
|
||||
def test_011_p2sh32(self):
|
||||
# Not used in bsx for native-segwit coins
|
||||
logging.info("---------- Test {} p2sh32".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} p2sh32")
|
||||
|
||||
ci = self.swap_clients[0].ci(self.test_coin)
|
||||
|
||||
@@ -806,7 +804,7 @@ class TestBCH(BasicSwapTest):
|
||||
assert len(tx_wallet["blockhash"]) == 64
|
||||
|
||||
def test_012_p2sh_p2wsh(self):
|
||||
logging.info("---------- Test {} p2sh-p2wsh".format(self.test_coin.name))
|
||||
logging.info(f"---------- Test {self.test_coin.name} p2sh-p2wsh")
|
||||
logging.info("Skipped")
|
||||
|
||||
def test_01_a_full_swap(self):
|
||||
@@ -877,7 +875,7 @@ class TestBCH(BasicSwapTest):
|
||||
|
||||
def test_06_preselect_inputs(self):
|
||||
tla_from = self.test_coin.name
|
||||
logging.info("---------- Test {} Preselected inputs".format(tla_from))
|
||||
logging.info(f"---------- Test {tla_from} Preselected inputs")
|
||||
logging.info("Skipped")
|
||||
|
||||
def test_07_expire_stuck_accepted(self):
|
||||
|
||||
@@ -74,6 +74,7 @@ class TestFunctions(BaseTest):
|
||||
|
||||
@classmethod
|
||||
def prepareExtraCoins(cls):
|
||||
# Save sent messages so tests can count them
|
||||
for sc in cls.swap_clients:
|
||||
sc._smsg_add_to_outbox = True
|
||||
|
||||
@@ -113,7 +114,7 @@ class TestFunctions(BaseTest):
|
||||
)
|
||||
|
||||
def do_test_01_full_swap(self, coin_from: Coins, coin_to: Coins) -> None:
|
||||
logging.info("---------- Test {} to {}".format(coin_from.name, coin_to.name))
|
||||
logging.info(f"---------- Test {coin_from.name} to {coin_to.name}")
|
||||
|
||||
# Offerer sends the offer
|
||||
# Bidder sends the bid
|
||||
@@ -459,6 +460,12 @@ class TestFunctions(BaseTest):
|
||||
if with_mercy
|
||||
else (BidStates.BID_STALLED_FOR_TEST, BidStates.XMR_SWAP_FAILED_SWIPED)
|
||||
)
|
||||
|
||||
chain_a_coin = coin_to if reverse_bid else coin_from
|
||||
if with_mercy is False and chain_a_coin == Coins.BCH:
|
||||
# When using BCH, can't set XMR_SWAP_FAILED_SWIPED as should wait for mercy tx
|
||||
expect_state = expect_state + (BidStates.XMR_SWAP_SCRIPT_TX_PREREFUND,)
|
||||
|
||||
wait_for_bid(
|
||||
test_delay_event,
|
||||
swap_clients[id_leader],
|
||||
@@ -920,7 +927,7 @@ class BasicSwapTest(TestFunctions):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(BasicSwapTest, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
|
||||
@classmethod
|
||||
def addCoinSettings(cls, settings, datadir, node_id):
|
||||
@@ -2480,11 +2487,6 @@ class BasicSwapTest(TestFunctions):
|
||||
def test_09_expire_accepted_rev(self):
|
||||
self.do_test_09_expire_accepted(Coins.XMR, self.test_coin_from)
|
||||
|
||||
def test_10_presigned_txns(self):
|
||||
raise RuntimeError(
|
||||
"TODO"
|
||||
) # Build without xmr first for quicker test iterations
|
||||
|
||||
def test_11_fee_validation(self):
|
||||
coin_from, coin_to = (self.test_coin_from, Coins.XMR)
|
||||
logging.info(
|
||||
@@ -2822,7 +2824,7 @@ class TestBTC_PARTB(TestFunctions):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestBTC_PARTB, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
if False:
|
||||
for client in cls.swap_clients:
|
||||
client.log.safe_logs = True
|
||||
|
||||
@@ -115,6 +115,10 @@ def modify_config(test_path, i):
|
||||
with open(config_path, "w") as fp:
|
||||
json.dump(settings, fp, indent=4)
|
||||
|
||||
btc_config_path = os.path.join(test_path, f"client{i}", "bitcoin", "bitcoin.conf")
|
||||
with open(btc_config_path, "a") as fp:
|
||||
fp.write("minrelaytxfee=0.00001\n")
|
||||
|
||||
|
||||
def wait_for_bid_state(
|
||||
delay_event, node_port: int, bid_id: str, state=None, wait_for: int = 30
|
||||
@@ -641,7 +645,7 @@ class Test(TestFunctions):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.addElectrumxDaemon("bitcoin", 32793, 50001)
|
||||
super(Test, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
|
||||
@classmethod
|
||||
def modifyConfig(cls, test_path, i):
|
||||
@@ -754,14 +758,6 @@ class Test(TestFunctions):
|
||||
self.delay_event,
|
||||
self.test_coin_b,
|
||||
100,
|
||||
self.port_node_1,
|
||||
self.port_node_0,
|
||||
True,
|
||||
)
|
||||
prepare_balance(
|
||||
self.delay_event,
|
||||
self.test_coin_xmr,
|
||||
100,
|
||||
self.port_node_0,
|
||||
self.port_node_1,
|
||||
True,
|
||||
@@ -788,7 +784,7 @@ class Test(TestFunctions):
|
||||
True,
|
||||
)
|
||||
self.do_test_03_follower_recover_a_lock_tx(
|
||||
self.test_coin_b, self.test_coin_xmr, self.port_node_1, self.port_node_0
|
||||
self.test_coin_b, self.test_coin_xmr, self.port_node_0, self.port_node_1
|
||||
)
|
||||
|
||||
def test_03_b_follower_recover_a_lock_tx_reverse(self):
|
||||
|
||||
@@ -48,15 +48,11 @@ class TestLTC(BasicSwapTest):
|
||||
assert deploymentinfo["softforks"][feature_name]["active"] is True
|
||||
|
||||
def test_001_nested_segwit(self):
|
||||
logging.info(
|
||||
"---------- Test {} p2sh nested segwit".format(self.test_coin_from.name)
|
||||
)
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} p2sh nested segwit")
|
||||
logging.info("Skipped")
|
||||
|
||||
def test_002_native_segwit(self):
|
||||
logging.info(
|
||||
"---------- Test {} p2sh native segwit".format(self.test_coin_from.name)
|
||||
)
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} p2sh native segwit")
|
||||
|
||||
ci = self.swap_clients[0].ci(self.test_coin_from)
|
||||
addr_segwit = ci.rpc_wallet("getnewaddress", ["segwit test", "bech32"])
|
||||
@@ -120,7 +116,7 @@ class TestLTC(BasicSwapTest):
|
||||
assert tx_funded_decoded["txid"] == tx_signed_decoded["txid"]
|
||||
|
||||
def test_007_hdwallet(self):
|
||||
logging.info("---------- Test {} hdwallet".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test {self.test_coin_from.name} hdwallet")
|
||||
|
||||
test_seed = "8e54a313e6df8918df6d758fafdbf127a115175fdd2238d0e908dd8093c9ac3b"
|
||||
test_wif = (
|
||||
@@ -136,7 +132,7 @@ class TestLTC(BasicSwapTest):
|
||||
assert addr == "rltc1qps7hnjd866e9ynxadgseprkc2l56m00djr82la"
|
||||
|
||||
def test_20_btc_coin(self):
|
||||
logging.info("---------- Test BTC to {}".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test BTC to {self.test_coin_from.name}")
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
offer_id = swap_clients[0].postOffer(
|
||||
@@ -178,7 +174,7 @@ class TestLTC(BasicSwapTest):
|
||||
assert js_1["num_swapping"] == 0 and js_1["num_watched_outputs"] == 0
|
||||
|
||||
def test_21_mweb(self):
|
||||
logging.info("---------- Test MWEB {}".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test MWEB {self.test_coin_from.name}")
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
ci0 = swap_clients[0].ci(self.test_coin_from)
|
||||
@@ -327,7 +323,7 @@ class TestLTC(BasicSwapTest):
|
||||
# TODO
|
||||
|
||||
def test_22_mweb_balance(self):
|
||||
logging.info("---------- Test MWEB balance {}".format(self.test_coin_from.name))
|
||||
logging.info(f"---------- Test MWEB balance {self.test_coin_from.name}")
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
ci_mweb = swap_clients[0].ci(Coins.LTC_MWEB)
|
||||
|
||||
Reference in New Issue
Block a user