mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
tests: Improve test_02_leader_recover_a_lock_tx
This commit is contained in:
@@ -5125,6 +5125,13 @@ class BasicSwap(BaseApp):
|
|||||||
|
|
||||||
if TxTypes.XMR_SWAP_A_LOCK_REFUND_SWIPE not in bid.txns:
|
if TxTypes.XMR_SWAP_A_LOCK_REFUND_SWIPE not in bid.txns:
|
||||||
try:
|
try:
|
||||||
|
if self.haveDebugInd(
|
||||||
|
bid.bid_id,
|
||||||
|
DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND2,
|
||||||
|
):
|
||||||
|
raise TemporaryError(
|
||||||
|
"Debug: BID_DONT_SPEND_COIN_A_LOCK_REFUND2"
|
||||||
|
)
|
||||||
txid = ci_from.publishTx(xmr_swap.a_lock_refund_swipe_tx)
|
txid = ci_from.publishTx(xmr_swap.a_lock_refund_swipe_tx)
|
||||||
self.logBidEvent(
|
self.logBidEvent(
|
||||||
bid.bid_id,
|
bid.bid_id,
|
||||||
@@ -6193,6 +6200,13 @@ class BasicSwap(BaseApp):
|
|||||||
self.logBidEvent(
|
self.logBidEvent(
|
||||||
bid.bid_id, EventLogTypes.LOCK_TX_A_REFUND_TX_SEEN, "", use_cursor
|
bid.bid_id, EventLogTypes.LOCK_TX_A_REFUND_TX_SEEN, "", use_cursor
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TxTypes.XMR_SWAP_A_LOCK_REFUND not in bid.txns:
|
||||||
|
bid.txns[TxTypes.XMR_SWAP_A_LOCK_REFUND] = SwapTx(
|
||||||
|
bid_id=bid.bid_id,
|
||||||
|
tx_type=TxTypes.XMR_SWAP_A_LOCK_REFUND,
|
||||||
|
txid=xmr_swap.a_lock_refund_tx_id,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.setBidError(
|
self.setBidError(
|
||||||
bid.bid_id,
|
bid.bid_id,
|
||||||
@@ -8814,8 +8828,10 @@ class BasicSwap(BaseApp):
|
|||||||
b_fee_rate: int = xmr_offer.a_fee_rate if reverse_bid else xmr_offer.b_fee_rate
|
b_fee_rate: int = xmr_offer.a_fee_rate if reverse_bid else xmr_offer.b_fee_rate
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chain_height = ci_to.getChainHeight()
|
if bid.xmr_b_lock_tx is None:
|
||||||
lock_tx_depth = chain_height - bid.xmr_b_lock_tx.chain_height
|
raise TemporaryError("Chain B lock tx not found.")
|
||||||
|
chain_height: int = ci_to.getChainHeight()
|
||||||
|
lock_tx_depth: int = chain_height - bid.xmr_b_lock_tx.chain_height
|
||||||
if lock_tx_depth < ci_to.depth_spendable():
|
if lock_tx_depth < ci_to.depth_spendable():
|
||||||
raise TemporaryError(
|
raise TemporaryError(
|
||||||
f"Chain B lock tx still confirming {lock_tx_depth} / {ci_to.depth_spendable()}."
|
f"Chain B lock tx still confirming {lock_tx_depth} / {ci_to.depth_spendable()}."
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ def stopDaemons(daemons):
|
|||||||
def wait_for_bid(
|
def wait_for_bid(
|
||||||
delay_event, swap_client, bid_id, state=None, sent: bool = False, wait_for: int = 20
|
delay_event, swap_client, bid_id, state=None, sent: bool = False, wait_for: int = 20
|
||||||
) -> None:
|
) -> None:
|
||||||
logging.info("wait_for_bid %s", bid_id.hex())
|
swap_client.log.debug(f"TEST: wait_for_bid {bid_id.hex()}")
|
||||||
for i in range(wait_for):
|
for i in range(wait_for):
|
||||||
if delay_event.is_set():
|
if delay_event.is_set():
|
||||||
raise ValueError("Test stopped.")
|
raise ValueError("Test stopped.")
|
||||||
@@ -161,6 +161,10 @@ def wait_for_bid(
|
|||||||
assert len(bids) < 2
|
assert len(bids) < 2
|
||||||
for bid in bids:
|
for bid in bids:
|
||||||
if bid[2] == bid_id:
|
if bid[2] == bid_id:
|
||||||
|
if i > 0 and i % 10 == 0:
|
||||||
|
swap_client.log.debug(
|
||||||
|
f"TEST: wait_for_bid {bid_id.hex()}: Bid state {bid[5]}, target {state}."
|
||||||
|
)
|
||||||
if isinstance(state, (list, tuple)):
|
if isinstance(state, (list, tuple)):
|
||||||
if bid[5] in state:
|
if bid[5] in state:
|
||||||
return
|
return
|
||||||
@@ -169,6 +173,11 @@ def wait_for_bid(
|
|||||||
elif state is not None and state != bid[5]:
|
elif state is not None and state != bid[5]:
|
||||||
continue
|
continue
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
if i > 0 and i % 10 == 0:
|
||||||
|
swap_client.log.debug(
|
||||||
|
f"TEST: wait_for_bid {bid_id.hex()}: Bid not found."
|
||||||
|
)
|
||||||
raise ValueError("wait_for_bid timed out.")
|
raise ValueError("wait_for_bid timed out.")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1503,7 +1503,7 @@ class Test(BaseTest):
|
|||||||
101 * COIN,
|
101 * COIN,
|
||||||
SwapTypes.XMR_SWAP,
|
SwapTypes.XMR_SWAP,
|
||||||
lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS,
|
lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS,
|
||||||
lock_value=12,
|
lock_value=16,
|
||||||
)
|
)
|
||||||
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
|
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
|
||||||
offer = swap_clients[1].getOffer(offer_id)
|
offer = swap_clients[1].getOffer(offer_id)
|
||||||
@@ -1522,6 +1522,9 @@ class Test(BaseTest):
|
|||||||
assert xmr_swap
|
assert xmr_swap
|
||||||
|
|
||||||
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.BID_STOP_AFTER_COIN_A_LOCK)
|
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.BID_STOP_AFTER_COIN_A_LOCK)
|
||||||
|
swap_clients[1].setBidDebugInd(
|
||||||
|
bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND2, False
|
||||||
|
)
|
||||||
|
|
||||||
swap_clients[0].acceptXmrBid(bid_id)
|
swap_clients[0].acceptXmrBid(bid_id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user