Prefer to set bid amounts from offer amount-to instead of rate.

This commit is contained in:
tecnovert
2024-05-09 01:02:21 +02:00
parent 46d0bdde4b
commit e63014026d
3 changed files with 77 additions and 25 deletions

View File

@@ -731,6 +731,31 @@ class Test(BaseTest):
assert (txin['txid'] == itx_after['vin'][i]['txid'])
assert (txin['vout'] == itx_after['vin'][i]['vout'])
def test_15_variable_amount(self):
logging.info('---------- Test fixed rate variable amount offer')
swap_clients = self.swap_clients
swap_value = 86474957
offer_rate = 996774992
extra_options = {'amount_negotiable': True, 'rate_negotiable': False}
offer_id = swap_clients[1].postOffer(Coins.PART, Coins.BTC, swap_value, offer_rate, swap_value // 2, SwapTypes.SELLER_FIRST, extra_options=extra_options)
wait_for_offer(test_delay_event, swap_clients[0], offer_id)
offer = swap_clients[0].getOffer(offer_id)
bid_amount = 86474842
bid_id = swap_clients[0].postBid(offer_id, bid_amount, extra_options={'bid_rate': offer_rate})
wait_for_bid(test_delay_event, swap_clients[1], bid_id)
bid = swap_clients[1].getBid(bid_id)
assert (bid.amount == 86474828)
swap_clients[1].acceptBid(bid_id)
wait_for_in_progress(test_delay_event, swap_clients[0], bid_id, sent=True)
wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60)
wait_for_bid(test_delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
def pass_99_delay(self):
logging.info('Delay')
for i in range(60 * 10):

View File

@@ -34,8 +34,9 @@ from basicswap.basicswap_util import (
)
from basicswap.util import (
COIN,
make_int,
format_amount,
make_int,
TemporaryError
)
from basicswap.util.address import (
toWIF,
@@ -800,13 +801,23 @@ class Test(BaseTest):
lock_tx_b_txid = ci.publishBLockTx(v, S, amount, fee_rate)
addr_out = ci.getNewAddress(True)
lock_tx_b_spend_txid = ci.spendBLockTx(lock_tx_b_txid, addr_out, v, s, amount, fee_rate, 0)
for i in range(20):
try:
lock_tx_b_spend_txid = ci.spendBLockTx(lock_tx_b_txid, addr_out, v, s, amount, fee_rate, 0)
break
except Exception as e:
if isinstance(e, TemporaryError):
continue
else:
raise (e)
test_delay_event.wait(1)
lock_tx_b_spend = ci.getTransaction(lock_tx_b_spend_txid)
actual_size: int = len(lock_tx_b_spend['txs_as_hex'][0]) // 2
expect_size: int = ci.xmr_swap_b_lock_spend_tx_vsize()
assert (expect_size >= actual_size)
assert (expect_size - actual_size < 10)
assert (expect_size - actual_size < 100) # TODO
def test_01_part_xmr(self):
logging.info('---------- Test PART to XMR')