mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-08-02 19:46:20 -04:00
test trade role and getting all trades
Co-authored-by: fa2a5qj3 <174058787+fa2a5qj3@users.noreply.github.com>
This commit is contained in:
parent
c13398e8cd
commit
46aa6b7648
1 changed files with 34 additions and 16 deletions
|
@ -2824,7 +2824,7 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
|
||||||
expect(tradeNotifications[0].getTitle()).toEqual("Offer Taken");
|
expect(tradeNotifications[0].getTitle()).toEqual("Offer Taken");
|
||||||
expect(tradeNotifications[0].getMessage()).toEqual("Your offer " + ctx.offerId + " has been accepted");
|
expect(tradeNotifications[0].getMessage()).toEqual("Your offer " + ctx.offerId + " has been accepted");
|
||||||
|
|
||||||
// record context after offer taken, once
|
// set context after offer taken, once
|
||||||
if (ctx.getBuyer().balancesAfterTake === undefined) {
|
if (ctx.getBuyer().balancesAfterTake === undefined) {
|
||||||
|
|
||||||
// wait to observe deposit txs
|
// wait to observe deposit txs
|
||||||
|
@ -2884,32 +2884,25 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
|
||||||
expect(takerBalanceDiffReservedOffer).toEqual(0n);
|
expect(takerBalanceDiffReservedOffer).toEqual(0n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// maker is notified of balance change
|
// test getting trade for all parties
|
||||||
|
await testGetTrade(ctx);
|
||||||
// taker can get trade
|
|
||||||
let fetchedTrade: TradeInfo = await ctx.taker.havenod!.getTrade(trade.getTradeId());
|
|
||||||
await testTrade(fetchedTrade, ctx);
|
|
||||||
assert(moneroTs.GenUtils.arrayContains(["DEPOSITS_PUBLISHED", "DEPOSITS_CONFIRMED", "DEPOSITS_UNLOCKED"], fetchedTrade.getPhase()), "Unexpected trade phase: " + fetchedTrade.getPhase());
|
|
||||||
// TODO: more fetched trade tests
|
|
||||||
|
|
||||||
// market-priced offer amounts are unadjusted, fixed-priced offer amounts are adjusted (e.g. cash at atm is $10 increments)
|
// market-priced offer amounts are unadjusted, fixed-priced offer amounts are adjusted (e.g. cash at atm is $10 increments)
|
||||||
// TODO: adjustments are based on payment method, not fixed-price
|
// TODO: adjustments are based on payment method, not fixed-price
|
||||||
if (fetchedTrade.getOffer()!.getUseMarketBasedPrice()) {
|
if (trade.getOffer()!.getUseMarketBasedPrice()) {
|
||||||
assert.equal(ctx.tradeAmount, BigInt(fetchedTrade.getAmount()));
|
assert.equal(ctx.tradeAmount, BigInt(trade.getAmount()));
|
||||||
} else {
|
} else {
|
||||||
expect(Math.abs(HavenoUtils.percentageDiff(ctx.tradeAmount!, BigInt(fetchedTrade.getAmount())))).toBeLessThan(TestConfig.maxAdjustmentPct);
|
expect(Math.abs(HavenoUtils.percentageDiff(ctx.tradeAmount!, BigInt(trade.getAmount())))).toBeLessThan(TestConfig.maxAdjustmentPct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// maker is notified of balance change
|
||||||
|
|
||||||
// taker is notified of balance change
|
// taker is notified of balance change
|
||||||
|
|
||||||
// maker can get trade
|
|
||||||
fetchedTrade = await ctx.maker.havenod!.getTrade(trade.getTradeId());
|
|
||||||
await testTrade(fetchedTrade, ctx);
|
|
||||||
assert(moneroTs.GenUtils.arrayContains(["DEPOSITS_PUBLISHED", "DEPOSITS_CONFIRMED", "DEPOSITS_UNLOCKED"], fetchedTrade.getPhase()), "Unexpected trade phase: " + fetchedTrade.getPhase());
|
|
||||||
return trade;
|
return trade;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testTrade(trade: TradeInfo, ctx: TradeContext) {
|
async function testTrade(trade: TradeInfo, ctx: TradeContext, havenod?: HavenoClient): Promise<void> {
|
||||||
expect(BigInt(trade.getAmount())).toEqual(ctx!.tradeAmount);
|
expect(BigInt(trade.getAmount())).toEqual(ctx!.tradeAmount);
|
||||||
|
|
||||||
// test security deposit = max(.1, trade amount * security deposit pct)
|
// test security deposit = max(.1, trade amount * security deposit pct)
|
||||||
|
@ -2917,9 +2910,34 @@ async function testTrade(trade: TradeInfo, ctx: TradeContext) {
|
||||||
expect(BigInt(trade.getBuyerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getBuyer().depositTxFee);
|
expect(BigInt(trade.getBuyerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getBuyer().depositTxFee);
|
||||||
expect(BigInt(trade.getSellerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getSeller().depositTxFee);
|
expect(BigInt(trade.getSellerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getSeller().depositTxFee);
|
||||||
|
|
||||||
|
// test phase
|
||||||
|
if (!ctx.isPaymentSent) {
|
||||||
|
assert(moneroTs.GenUtils.arrayContains(["DEPOSITS_PUBLISHED", "DEPOSITS_CONFIRMED", "DEPOSITS_UNLOCKED"], trade.getPhase()), "Unexpected trade phase: " + trade.getPhase());
|
||||||
|
}
|
||||||
|
|
||||||
|
// test role
|
||||||
|
const role = trade.getRole();
|
||||||
|
assert(role.length > 0); // TODO: test role string based on context
|
||||||
|
|
||||||
|
|
||||||
// TODO: test more fields
|
// TODO: test more fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function testGetTrade(ctx: TradeContext, havenod?: HavenoClient): Promise<void> {
|
||||||
|
if (havenod) {
|
||||||
|
const trade = await havenod.getTrade(ctx.offerId!);
|
||||||
|
await testTrade(trade, ctx);
|
||||||
|
const trades = await havenod.getTrades();
|
||||||
|
const foundTrade = trades.find((trade) => trade.getTradeId() === ctx.offerId);
|
||||||
|
assert(foundTrade);
|
||||||
|
await testTrade(foundTrade, ctx, havenod);
|
||||||
|
} else {
|
||||||
|
await testGetTrade(ctx, ctx.maker.havenod);
|
||||||
|
await testGetTrade(ctx, ctx.taker.havenod);
|
||||||
|
await testGetTrade(ctx, ctx.arbitrator.havenod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function testOpenDispute(ctxP: Partial<TradeContext>) {
|
async function testOpenDispute(ctxP: Partial<TradeContext>) {
|
||||||
let ctx = TradeContext.init(ctxP);
|
let ctx = TradeContext.init(ctxP);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue