Add BTC type swipe tx mercy outputs.

This commit is contained in:
tecnovert
2024-11-08 14:18:06 +02:00
parent 8d96ea7fcf
commit e05aaeba26
7 changed files with 119 additions and 18 deletions

View File

@@ -268,7 +268,7 @@ class TestFunctions(BaseTest):
logging.info('---------- Test {} to {} follower recovers coin a lock tx{}'.format(coin_from.name, coin_to.name, ' (with mercy tx)' if with_mercy else ''))
# Leader is too slow to recover the coin a lock tx and follower swipes it
# coin b lock tx remains unspent
# Coin B lock tx remains unspent unless a mercy output revealing the follower's keyshare is sent
id_offerer: int = self.node_a_id
id_bidder: int = self.node_b_id
@@ -282,6 +282,8 @@ class TestFunctions(BaseTest):
id_follower: int = id_offerer if reverse_bid else id_bidder
logging.info(f'Offerer, bidder, leader, follower: {id_offerer}, {id_bidder}, {id_leader}, {id_follower}')
swap_clients[id_follower].ci(coin_from if reverse_bid else coin_to)._altruistic = with_mercy
js_w0_before = read_json_api(1800 + id_offerer, 'wallets')
js_w1_before = read_json_api(1800 + id_bidder, 'wallets')
@@ -941,6 +943,17 @@ class BasicSwapTest(TestFunctions):
def test_03_d_follower_recover_a_lock_tx_from_part(self):
self.do_test_03_follower_recover_a_lock_tx(Coins.PART, self.test_coin_from)
def test_03_e_follower_recover_a_lock_tx_mercy_release(self):
if not self.has_segwit:
return
self.do_test_03_follower_recover_a_lock_tx(self.test_coin_from, Coins.XMR, with_mercy=True)
def test_03_f_follower_recover_a_lock_tx_mercy_release_reverse(self):
if not self.has_segwit:
return
self.prepare_balance(Coins.XMR, 100.0, 1800, 1801)
self.do_test_03_follower_recover_a_lock_tx(Coins.XMR, self.test_coin_from, with_mercy=True)
def test_04_a_follower_recover_b_lock_tx(self):
if not self.has_segwit:
return

View File

@@ -1031,6 +1031,8 @@ class Test(BaseTest):
logging.info('---------- Test PART to XMR follower recovers coin a lock tx')
swap_clients = self.swap_clients
swap_clients[1].ci(Coins.PART)._altruistic = False
offer_id = swap_clients[0].postOffer(
Coins.PART, Coins.XMR, 101 * COIN, 0.13 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP,
lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=16)
@@ -1062,6 +1064,39 @@ class Test(BaseTest):
bidder_states = [s for s in bidder_states if s[1] != 'Bid Stalled (debug)']
assert (compare_bid_states(bidder_states, self.states_bidder[2]) is True)
def test_03b_follower_recover_a_lock_tx_with_mercy(self):
logging.info('---------- Test PART to XMR follower recovers coin a lock tx with mercy output')
swap_clients = self.swap_clients
swap_clients[1].ci(Coins.PART)._altruistic = True
offer_id = swap_clients[0].postOffer(
Coins.PART, Coins.XMR, 101 * COIN, 0.13 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP,
lock_type=TxLockTypes.SEQUENCE_LOCK_BLOCKS, lock_value=16)
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
offer = swap_clients[1].getOffer(offer_id)
bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)
wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.BID_RECEIVED)
bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
assert (xmr_swap)
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.BID_DONT_SPEND_COIN_B_LOCK)
swap_clients[0].setBidDebugInd(bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND2)
swap_clients[0].setBidDebugInd(bid_id, DebugTypes.WAIT_FOR_COIN_B_LOCK_BEFORE_REFUND, False)
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.WAIT_FOR_COIN_B_LOCK_BEFORE_REFUND, False)
swap_clients[0].acceptXmrBid(bid_id)
wait_for_bid(test_delay_event, swap_clients[0], bid_id, (BidStates.XMR_SWAP_NOSCRIPT_TX_REDEEMED, BidStates.SWAP_COMPLETED), wait_for=220)
wait_for_bid(test_delay_event, swap_clients[1], bid_id, BidStates.XMR_SWAP_FAILED_SWIPED, wait_for=120, sent=True)
wait_for_none_active(test_delay_event, 1800)
wait_for_none_active(test_delay_event, 1801)
def test_04_follower_recover_b_lock_tx(self):
logging.info('---------- Test PART to XMR follower recovers coin b lock tx')