mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-21 06:00:33 -04:00
randomize market depth in bootstrap test
This commit is contained in:
parent
9b5b0ecb29
commit
ffb343ed20
1 changed files with 6 additions and 1 deletions
|
@ -2445,9 +2445,10 @@ test("Can bootstrap a network", async () => {
|
||||||
if (await isFixedPrice(ctxP)) ctxP.price = 142.23;
|
if (await isFixedPrice(ctxP)) ctxP.price = 142.23;
|
||||||
|
|
||||||
// randomize trade config
|
// 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.tradeAmount === undefined) ctxP.tradeAmount = isRangeOffer ? getRandomBigIntWithinRange(ctxP.offerMinAmount!, ctxP.offerAmount) : ctxP.offerAmount;
|
||||||
if (ctxP.buyerSendsPayment === undefined) ctxP.buyerSendsPayment = getRandomOutcome(1/2);
|
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.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_DEPOSITS_UNLOCK : undefined;
|
||||||
if (ctxP.buyerDisputeContext === undefined) ctxP.buyerDisputeContext = getRandomOutcome(1/14) ? DisputeContext.OPEN_AFTER_PAYMENT_SENT : 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;
|
return Math.random() <= percentChance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRandomFloat(min: number, max: number) {
|
||||||
|
return Math.random() * (max - min) + min;
|
||||||
|
}
|
||||||
|
|
||||||
function getRandomBigIntWithinPercent(base: bigint, percent: number): bigint {
|
function getRandomBigIntWithinPercent(base: bigint, percent: number): bigint {
|
||||||
return getRandomBigIntWithinRange(base - multiply(base, percent), base + multiply(base, percent));
|
return getRandomBigIntWithinRange(base - multiply(base, percent), base + multiply(base, percent));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue