randomize offer amount, min amount, and trade amount for range test

This commit is contained in:
woodser 2025-01-18 18:15:15 -05:00
parent 6a17b27fb9
commit e45c14cf92

View File

@ -1745,14 +1745,13 @@ test("Can complete a trade within a range and without a buyer deposit (Test, CI)
const tradeStatisticsPre = await arbitrator.getTradeStatistics(); const tradeStatisticsPre = await arbitrator.getTradeStatistics();
// execute trade // execute trade
const offerAmount = HavenoUtils.xmrToAtomicUnits(1); const offerAmount = getRandomBigIntWithinPercent(HavenoUtils.xmrToAtomicUnits(1), 0.15);
const offerMinAmount = HavenoUtils.xmrToAtomicUnits(.15); const offerMinAmount = getRandomBigIntWithinPercent(HavenoUtils.xmrToAtomicUnits(0.3), 0.15);
const tradeAmount = getRandomBigIntWithinRange(offerMinAmount, offerAmount);
const ctx: Partial<TradeContext> = { const ctx: Partial<TradeContext> = {
price: 142.23, price: 142.23,
offerAmount: offerAmount, offerAmount: offerAmount,
offerMinAmount: offerMinAmount, offerMinAmount: offerMinAmount,
tradeAmount: tradeAmount, tradeAmount: getRandomBigIntWithinRange(offerMinAmount, offerAmount),
testPayoutUnlocked: true, // override to test unlock testPayoutUnlocked: true, // override to test unlock
makerPaymentAccountId: makerPaymentAccount.getId(), makerPaymentAccountId: makerPaymentAccount.getId(),
takerPaymentAccountId: takerPaymentAccount.getId(), takerPaymentAccountId: takerPaymentAccount.getId(),
@ -2371,11 +2370,9 @@ test("Can bootstrap a network", async () => {
if (ctxP.maker.havenod === undefined) ctxP.maker.havenod = user1AsMaker ? user1 : user2; if (ctxP.maker.havenod === undefined) ctxP.maker.havenod = user1AsMaker ? user1 : user2;
if (ctxP.taker.havenod === undefined) ctxP.taker.havenod = user1AsMaker ? user2 : user1; if (ctxP.taker.havenod === undefined) ctxP.taker.havenod = user1AsMaker ? user2 : user1;
if (ctxP.direction === undefined) ctxP.direction = getRandomOutcome(1/2) ? OfferDirection.BUY : OfferDirection.SELL; if (ctxP.direction === undefined) ctxP.direction = getRandomOutcome(1/2) ? OfferDirection.BUY : OfferDirection.SELL;
const offerAmountAnchor = HavenoUtils.xmrToAtomicUnits(1.5);
const minAmountAnchor = HavenoUtils.xmrToAtomicUnits(0.3);
const isRangeOffer = getRandomOutcome(1/2); const isRangeOffer = getRandomOutcome(1/2);
if (ctxP.offerAmount === undefined) ctxP.offerAmount = getRandomBigIntWithinPercent(offerAmountAnchor, 0.15); if (ctxP.offerAmount === undefined) ctxP.offerAmount = getRandomBigIntWithinPercent(HavenoUtils.xmrToAtomicUnits(1), 0.15);
if (isRangeOffer && ctxP.offerMinAmount === undefined) ctxP.offerMinAmount = getRandomBigIntWithinPercent(minAmountAnchor, 0.15); if (isRangeOffer && ctxP.offerMinAmount === undefined) ctxP.offerMinAmount = getRandomBigIntWithinPercent(HavenoUtils.xmrToAtomicUnits(0.3), 0.15);
if (ctxP.reserveExactAmount === undefined) ctxP.reserveExactAmount = getRandomOutcome(3/4); if (ctxP.reserveExactAmount === undefined) ctxP.reserveExactAmount = getRandomOutcome(3/4);
// randomize payment method and asset code // randomize payment method and asset code