Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the role field of Trades #297

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/HavenoClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2600,6 +2600,14 @@ async function executeTrade(ctxP: Partial<TradeContext>): Promise<string> {
ctx.taker.balancesAfterPayout = await ctx.taker.havenod?.getBalances();
}

const tradesForUser1 = await user1.getTrades();
const tradesForUser2 = await user2.getTrades();
assert(tradesForUser1.find( (x) => x.getTradeId() === ctx.offerId));
assert(tradesForUser2.find( (x) => x.getTradeId() === ctx.offerId));
for (const trade of tradesForUser1.concat(tradesForUser2).filter( (x) => x.getTradeId() === ctx.offerId)) {
testTrade(trade, ctx);
}

// test balances after payout tx unless other trades can interfere
if (ctx.isStopped) return ctx.offerId!;
if (!ctx.concurrentTrades) await testAmountsAfterComplete(ctx);
Expand Down Expand Up @@ -2815,9 +2823,6 @@ async function takeOffer(ctxP: Partial<TradeContext>): Promise<TradeInfo> {
ctx.getSeller().securityDepositActual = BigInt(trade.getSellerSecurityDeposit()!);
}

// test trade model
await testTrade(trade, ctx);

// test buyer and seller balances after offer taken
if (!ctx.concurrentTrades) {
ctx.arbitrator!.trade = await ctx.arbitrator.havenod!.getTrade(ctx.offerId!);
Expand Down Expand Up @@ -2877,6 +2882,12 @@ async function testTrade(trade: TradeInfo, ctx: TradeContext) {
expect(BigInt(trade.getBuyerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getBuyer().depositTxFee);
expect(BigInt(trade.getSellerSecurityDeposit())).toEqual(expectedSecurityDeposit - ctx.getSeller().depositTxFee);

assert(trade.getRole().length > 0);
assert(trade.getRole() === "XMR buyer as maker"
|| trade.getRole() === "XMR seller as taker"
|| trade.getRole() === "XMR seller as maker"
|| trade.getRole() === "XMR buyer as taker");

// TODO: test more fields
}

Expand Down
Loading