mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
Fix recoverNoScriptTxnWithKey regression, add to more tests.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2021-2024 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -170,7 +170,11 @@ class TestFunctions(BaseTest):
|
||||
bid_id = swap_clients[id_bidder].postXmrBid(offer_id, offer.amount_from)
|
||||
|
||||
wait_for_bid(
|
||||
test_delay_event, swap_clients[id_offerer], bid_id, BidStates.BID_RECEIVED
|
||||
test_delay_event,
|
||||
swap_clients[id_offerer],
|
||||
bid_id,
|
||||
BidStates.BID_RECEIVED,
|
||||
wait_for=(self.extra_wait_time + 40),
|
||||
)
|
||||
|
||||
bid0 = read_json_api(1800 + id_offerer, f"bids/{bid_id.hex()}")
|
||||
@@ -392,7 +396,7 @@ class TestFunctions(BaseTest):
|
||||
)
|
||||
|
||||
swap_clients[id_follower].ci(
|
||||
coin_from if reverse_bid else coin_to
|
||||
coin_to if reverse_bid else coin_from
|
||||
)._altruistic = with_mercy
|
||||
|
||||
amt_swap = ci_from.make_int(random.uniform(0.1, 2.0), r=1)
|
||||
@@ -415,17 +419,10 @@ class TestFunctions(BaseTest):
|
||||
test_delay_event, swap_clients[id_offerer], bid_id, BidStates.BID_RECEIVED
|
||||
)
|
||||
|
||||
debug_type = (
|
||||
DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND2
|
||||
if with_mercy
|
||||
else DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND
|
||||
)
|
||||
swap_clients[id_leader].setBidDebugInd(bid_id, debug_type)
|
||||
debug_type = (
|
||||
DebugTypes.BID_DONT_SPEND_COIN_B_LOCK
|
||||
if with_mercy
|
||||
else DebugTypes.BID_STOP_AFTER_COIN_A_LOCK
|
||||
swap_clients[id_leader].setBidDebugInd(
|
||||
bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND2
|
||||
)
|
||||
debug_type = DebugTypes.BID_DONT_SPEND_COIN_B_LOCK
|
||||
swap_clients[id_follower].setBidDebugInd(bid_id, debug_type)
|
||||
|
||||
swap_clients[id_leader].setBidDebugInd(
|
||||
@@ -442,7 +439,7 @@ class TestFunctions(BaseTest):
|
||||
expect_state = (
|
||||
(BidStates.XMR_SWAP_NOSCRIPT_TX_REDEEMED, BidStates.SWAP_COMPLETED)
|
||||
if with_mercy
|
||||
else BidStates.BID_STALLED_FOR_TEST
|
||||
else (BidStates.BID_STALLED_FOR_TEST, BidStates.XMR_SWAP_FAILED_SWIPED)
|
||||
)
|
||||
wait_for_bid(
|
||||
test_delay_event,
|
||||
@@ -473,6 +470,19 @@ class TestFunctions(BaseTest):
|
||||
wait_for_none_active(test_delay_event, 1800 + id_offerer)
|
||||
wait_for_none_active(test_delay_event, 1800 + id_bidder)
|
||||
|
||||
if with_mercy is False:
|
||||
# Test manually redeeming the no-script lock tx
|
||||
offerer_key = read_json_api(
|
||||
1800 + id_offerer,
|
||||
"bids/{}".format(bid_id.hex()),
|
||||
{"chainbkeysplit": True},
|
||||
)["splitkey"]
|
||||
data = {"spendchainblocktx": True, "remote_key": offerer_key}
|
||||
redeemed_txid = read_json_api(
|
||||
1800 + id_bidder, "bids/{}".format(bid_id.hex()), data
|
||||
)["txid"]
|
||||
assert len(redeemed_txid) == 64
|
||||
|
||||
def do_test_04_follower_recover_b_lock_tx(
|
||||
self, coin_from, coin_to, lock_value: int = 32
|
||||
):
|
||||
@@ -1601,7 +1611,13 @@ class BasicSwapTest(TestFunctions):
|
||||
offer = swap_clients[1].getOffer(offer_id)
|
||||
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
|
||||
|
||||
wait_for_bid(test_delay_event, swap_clients[2], bid_id, BidStates.BID_RECEIVED)
|
||||
wait_for_bid(
|
||||
test_delay_event,
|
||||
swap_clients[2],
|
||||
bid_id,
|
||||
BidStates.BID_RECEIVED,
|
||||
wait_for=(self.extra_wait_time + 40),
|
||||
)
|
||||
swap_clients[2].acceptBid(bid_id)
|
||||
|
||||
wait_for_bid(
|
||||
@@ -1662,7 +1678,13 @@ class BasicSwapTest(TestFunctions):
|
||||
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
|
||||
bid_id = swap_clients[1].postXmrBid(offer_id, amt_swap)
|
||||
swap_clients[1].abandonBid(bid_id)
|
||||
wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.BID_ACCEPTED)
|
||||
wait_for_bid(
|
||||
test_delay_event,
|
||||
swap_clients[0],
|
||||
bid_id,
|
||||
BidStates.BID_ACCEPTED,
|
||||
wait_for=(self.extra_wait_time + 40),
|
||||
)
|
||||
|
||||
try:
|
||||
swap_clients[0].setMockTimeOffset(7200)
|
||||
|
||||
@@ -2,16 +2,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2021-2023 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import json
|
||||
import random
|
||||
import logging
|
||||
import unittest
|
||||
from urllib import parse
|
||||
from urllib.request import urlopen
|
||||
|
||||
from basicswap.basicswap import (
|
||||
Coins,
|
||||
@@ -27,7 +24,6 @@ from basicswap.util import (
|
||||
format_amount,
|
||||
)
|
||||
from tests.basicswap.util import (
|
||||
post_json_req,
|
||||
read_json_api,
|
||||
)
|
||||
from tests.basicswap.common import (
|
||||
@@ -61,9 +57,7 @@ class Test(BaseTest):
|
||||
"subfee": False,
|
||||
"type_to": "blind",
|
||||
}
|
||||
json_rv = json.loads(
|
||||
post_json_req("http://127.0.0.1:1800/json/wallets/part/withdraw", post_json)
|
||||
)
|
||||
json_rv = read_json_api(1800, "wallets/part/withdraw", post_json)
|
||||
assert len(json_rv["txid"]) == 64
|
||||
|
||||
logging.info("Waiting for blind balance")
|
||||
@@ -388,7 +382,7 @@ class Test(BaseTest):
|
||||
|
||||
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.CREATE_INVALID_COIN_B_LOCK)
|
||||
swap_clients[0].setBidDebugInd(
|
||||
bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND
|
||||
bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND2
|
||||
)
|
||||
|
||||
swap_clients[0].acceptXmrBid(bid_id)
|
||||
@@ -397,7 +391,7 @@ class Test(BaseTest):
|
||||
test_delay_event,
|
||||
swap_clients[0],
|
||||
bid_id,
|
||||
BidStates.BID_STALLED_FOR_TEST,
|
||||
(BidStates.BID_STALLED_FOR_TEST, BidStates.XMR_SWAP_FAILED_SWIPED),
|
||||
wait_for=180,
|
||||
)
|
||||
wait_for_bid(
|
||||
@@ -422,21 +416,14 @@ class Test(BaseTest):
|
||||
wait_for_none_active(test_delay_event, 1800)
|
||||
wait_for_none_active(test_delay_event, 1801)
|
||||
|
||||
data = parse.urlencode({"chainbkeysplit": True}).encode()
|
||||
offerer_key = json.loads(
|
||||
urlopen(
|
||||
"http://127.0.0.1:1800/json/bids/{}".format(bid_id.hex()), data=data
|
||||
).read()
|
||||
offerer_key = read_json_api(
|
||||
1800, "bids/{}".format(bid_id.hex()), {"chainbkeysplit": True}
|
||||
)["splitkey"]
|
||||
|
||||
data = parse.urlencode(
|
||||
{"spendchainblocktx": True, "remote_key": offerer_key}
|
||||
).encode()
|
||||
redeemed_txid = json.loads(
|
||||
urlopen(
|
||||
"http://127.0.0.1:1801/json/bids/{}".format(bid_id.hex()), data=data
|
||||
).read()
|
||||
)["txid"]
|
||||
data = {"spendchainblocktx": True, "remote_key": offerer_key}
|
||||
redeemed_txid = read_json_api(1801, "bids/{}".format(bid_id.hex()), data)[
|
||||
"txid"
|
||||
]
|
||||
assert len(redeemed_txid) == 64
|
||||
|
||||
def do_test_04_follower_recover_b_lock_tx(self, coin_from, coin_to):
|
||||
|
||||
Reference in New Issue
Block a user