From b0c3cf36363f91cd339af9dbf69b29ed762a6a64 Mon Sep 17 00:00:00 2001 From: woodser <13068859+woodser@users.noreply.github.com> Date: Fri, 30 May 2025 19:43:07 -0400 Subject: [PATCH] randomize market depth in bootstrap test --- src/HavenoClient.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/HavenoClient.test.ts b/src/HavenoClient.test.ts index e37251a2..bf28a4e7 100644 --- a/src/HavenoClient.test.ts +++ b/src/HavenoClient.test.ts @@ -2445,9 +2445,10 @@ test("Can bootstrap a network", async () => { if (await isFixedPrice(ctxP)) ctxP.price = 142.23; // randomize trade config - if (ctxP.takeOffer === undefined) ctxP.takeOffer = getRandomOutcome(3/4); + if (ctxP.takeOffer === undefined) ctxP.takeOffer = getRandomOutcome(2/3); if (ctxP.tradeAmount === undefined) ctxP.tradeAmount = isRangeOffer ? getRandomBigIntWithinRange(ctxP.offerMinAmount!, ctxP.offerAmount) : ctxP.offerAmount; if (ctxP.buyerSendsPayment === undefined) ctxP.buyerSendsPayment = getRandomOutcome(1/2); + if (ctxP.priceMargin === undefined && ctxP.price === undefined) ctxP.priceMargin = parseFloat(getRandomFloat(0, .3).toFixed(10)); if (ctxP.sellerReceivesPayment === undefined) ctxP.sellerReceivesPayment = getRandomOutcome(1/2); if (ctxP.buyerDisputeContext === undefined) ctxP.buyerDisputeContext = getRandomOutcome(1/14) ? DisputeContext.OPEN_AFTER_DEPOSITS_UNLOCK : undefined; if (ctxP.buyerDisputeContext === undefined) ctxP.buyerDisputeContext = getRandomOutcome(1/14) ? DisputeContext.OPEN_AFTER_PAYMENT_SENT : undefined; @@ -4177,6 +4178,10 @@ function getRandomOutcome(percentChance: number): boolean { return Math.random() <= percentChance; } +function getRandomFloat(min: number, max: number) { + return Math.random() * (max - min) + min; +} + function getRandomBigIntWithinPercent(base: bigint, percent: number): bigint { return getRandomBigIntWithinRange(base - multiply(base, percent), base + multiply(base, percent)); }