Test that the initial lock tx can be funded before posting an offer.
Some checks are pending
ci / ci (3.12) (push) Waiting to run

This commit is contained in:
tecnovert 2025-01-10 01:18:32 +02:00
parent bf6d07a726
commit 73ab5e7391
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
2 changed files with 76 additions and 1 deletions

View file

@ -2121,8 +2121,15 @@ class BasicSwap(BaseApp):
ci_from.ensureFunds(msg_buf.amount_from)
else:
proof_of_funds_hash = getOfferProofOfFundsHash(msg_buf, offer_addr)
ensure_balance: int = int(amount)
# If a prefunded txn is not used, check that the wallet balance can cover the tx fee.
if "prefunded_itx" not in extra_options:
pi = self.pi(SwapTypes.XMR_SWAP)
_ = pi.getFundedInitiateTxTemplate(ci_from, ensure_balance, False)
# TODO: Save the prefunded tx so the fee can't change, complicates multiple offers at the same time.
proof_addr, proof_sig, proof_utxos = self.getProofOfFunds(
coin_from_t, int(amount), proof_of_funds_hash
coin_from_t, ensure_balance, proof_of_funds_hash
)
# TODO: For now proof_of_funds is just a client side check, may need to be sent with offers in future however.

View file

@ -1738,6 +1738,7 @@ class Test(BaseTest):
def test_05_btc_xmr(self):
logging.info("---------- Test BTC to XMR")
swap_clients = self.swap_clients
offer_id = swap_clients[0].postOffer(
Coins.BTC,
Coins.XMR,
@ -1784,6 +1785,73 @@ class Test(BaseTest):
swap_clients[1].ci(Coins.XMR).setFeePriority(0)
def test_05b_btc_xmr_withfee(self):
logging.info("---------- Test BTC to XMR")
swap_clients = self.swap_clients
self.prepare_balance(Coins.BTC, 100.0, 1801, 1800)
self.prepare_balance(Coins.XMR, 20.0, 1800, 1801)
js_w1_before = read_json_api(1801, "wallets")
ci1_btc = swap_clients[1].ci(Coins.BTC)
btc_total = ci1_btc.make_int(js_w1_before["BTC"]["balance"]) + ci1_btc.make_int(js_w1_before["BTC"]["unconfirmed"])
try:
offer_id = swap_clients[1].postOffer(
Coins.BTC,
Coins.XMR,
btc_total,
0,
10 * COIN,
SwapTypes.XMR_SWAP,
extra_options={"amount_to": 10 * XMR_COIN}
)
except Exception as e:
assert "Insufficient funds" in str(e)
else:
assert False, "Should fail"
offer_id = swap_clients[1].postOffer(
Coins.BTC,
Coins.XMR,
btc_total - 1 * COIN,
0,
10 * COIN,
SwapTypes.XMR_SWAP,
extra_options={"amount_to": 10 * XMR_COIN}
)
wait_for_offer(test_delay_event, swap_clients[0], offer_id)
offers = swap_clients[0].listOffers(filters={"offer_id": offer_id})
offer = offers[0]
swap_clients[0].ci(Coins.XMR).setFeePriority(3)
bid_id = swap_clients[0].postXmrBid(offer_id, offer.amount_from)
wait_for_bid(
test_delay_event,
swap_clients[1],
bid_id,
BidStates.BID_RECEIVED,
wait_for=(self.extra_wait_time + 40),
)
swap_clients[1].acceptXmrBid(bid_id)
wait_for_bid(
test_delay_event,
swap_clients[1],
bid_id,
BidStates.SWAP_COMPLETED,
wait_for=180,
)
wait_for_bid(
test_delay_event,
swap_clients[0],
bid_id,
BidStates.SWAP_COMPLETED,
sent=True,
)
def test_06_multiple_swaps(self):
logging.info("---------- Test Multiple concurrent swaps")
swap_clients = self.swap_clients