From 6562b9fc304128b36f95816e52c94b57fa4a69df Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 19 Sep 2024 19:34:55 +0530 Subject: [PATCH] Update balance checks in authority auction tests --- src/auction.test.ts | 19 ++++++++++++------- src/authority-auction.test.ts | 6 ++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/auction.test.ts b/src/auction.test.ts index d8c5f64..4094953 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -113,8 +113,9 @@ const auctionTests = () => { expect(bid.status).toEqual('reveal'); }); + const expectedBidAmounts = bidAmounts.map(bidAmount => { return { quantity: bidAmount.amount, type: bidAmount.denom }; }); const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount); - expect(actualBidAmounts).toEqual(expect.arrayContaining(bidAmounts)); + expect(actualBidAmounts).toEqual(expect.arrayContaining(expectedBidAmounts)); }); test('Wait for auction completion.', (done) => { @@ -241,8 +242,9 @@ const providerAuctionTests = () => { expect(bid.status).toEqual('reveal'); }); + const expectedBidAmounts = bidAmounts.map(bidAmount => { return { quantity: bidAmount.amount, type: bidAmount.denom }; }); const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount); - expect(actualBidAmounts).toEqual(expect.arrayContaining(bidAmounts)); + expect(actualBidAmounts).toEqual(expect.arrayContaining(expectedBidAmounts)); }); test('Wait for auction completion.', (done) => { @@ -259,19 +261,22 @@ const providerAuctionTests = () => { const bidWinners = bidderAccounts.slice(0, numProviders); const bidLosers = bidderAccounts.slice(numProviders, numBidders); + // Check winner price is equal to highest winning bid + const winningBidAmount = parseInt(auction.winnerPrice.quantity); + expect(auction.winnerPrice.quantity).toEqual(bidAmounts[numProviders - 1].amount); + // Check balances of auction winners for (let i = 0; i < bidWinners.length; i++) { - const expectedWinner = bidWinners[i]; + const bidWinner = bidWinners[i]; - expect(auction.winnerAddresses[i]).toEqual(expectedWinner.address); - expect(expectedWinner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`); + expect(auction.winnerAddresses[i]).toEqual(bidWinner.address); + expect(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`).toEqual(bidWinner.bid.reveal.bidAmount); - const [winnerAccountObj] = await registry.getAccounts([expectedWinner.address]); + const [winnerAccountObj] = await registry.getAccounts([bidWinner.address]); expect(winnerAccountObj).toBeDefined(); const [{ type, quantity }] = winnerAccountObj.balance; const actualBalance = parseInt(quantity); - const winningBidAmount = parseInt(auction.winnerPrice.quantity); // Balance should be more than bidder's initial balance but // less than initial balance + winning price as tx fees also gets deducted diff --git a/src/authority-auction.test.ts b/src/authority-auction.test.ts index 2624c81..190347e 100644 --- a/src/authority-auction.test.ts +++ b/src/authority-auction.test.ts @@ -97,9 +97,11 @@ const auctionTests = (numBidders = 3) => { const highestBidder = accounts[accounts.length - 1]; const secondHighestBidder = (accounts.length > 1 ? accounts[accounts.length - 2] : highestBidder); + expect(auction.winnerAddresses).toHaveLength(1); + expect(auction.winnerAddresses[0]).toEqual(highestBidder.address); - expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBid.quantity}${auction.winnerBid.type}`); - expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`); + expect(`${auction.winnerBids[0].quantity}${auction.winnerBids[0].type}`).toEqual(highestBidder.bid.reveal.bidAmount); + expect(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`).toEqual(secondHighestBidder.bid.reveal.bidAmount); const [record] = await registry.lookupAuthorities([authorityName], true); expect(record.ownerAddress).toEqual(highestBidder.address);