From 216199fe471ec8eaa01ab0580a494f8e0344cab1 Mon Sep 17 00:00:00 2001 From: Isha Venikar Date: Wed, 18 Sep 2024 13:07:28 +0530 Subject: [PATCH] Add check for balance of auction winner --- package.json | 1 - src/auction.test.ts | 45 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 5d9632f..f57c72b 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "scripts": { "test": "jest --runInBand --verbose --testPathPattern=src", "test:authority-auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/authority-auction.test.ts", - "test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts", "test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts", "test:onboarding": "ONBOARDING_ENABLED=1 jest --runInBand --verbose src/onboarding.test.ts", "build": "tsc", diff --git a/src/auction.test.ts b/src/auction.test.ts index 1f743df..4398d77 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -122,7 +122,7 @@ const createAuctionTests = () => { setTimeout(done, waitTime); }); - test('Check auction winner, authority owner and status.', async () => { + test('Check auction winner, status, and balance.', async () => { const [auction] = await registry.getAuctionsByIds([auctionId]); expect(auction.status).toEqual('completed'); @@ -132,6 +132,20 @@ const createAuctionTests = () => { expect(auction.winnerAddresses[0]).toEqual(highestBidder.address); expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[0].quantity}${auction.winnerBids[0].type}`); expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`); + + const initialBalance = 20000000; + const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10); + + const expectedBalance = (initialBalance - winningBidAmount).toString(); + + const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]); + expect(winnerAccountObj).toBeDefined(); + expect(winnerAccountObj.address).toBe(highestBidder.address); + + const [{ type, quantity }] = winnerAccountObj.balance; + + expect(type).toBe(DENOM); + expect(quantity).toBe(expectedBalance); }); }; @@ -231,17 +245,34 @@ const createSPAuctionTests = () => { setTimeout(done, waitTime); }); - test('Check auction winner, authority owner and status.', async () => { + test('Check auction winner, status, and balance.', async () => { const [auction] = await registry.getAuctionsByIds([auctionId]); expect(auction.status).toEqual('completed'); const bidWinners = bidderAccounts.slice(0, 3); - bidWinners.forEach((winner, index) => { - expect(auction.winnerAddresses[index]).toEqual(winner.address); - expect(bidWinners[index].bid.reveal.bidAmount).toEqual(`${auction.winnerBids[index].quantity}${auction.winnerBids[index].type}`); - }); - expect(bidWinners[bidWinners.length - 1].bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`); + for (let i = 0; i < bidWinners.length; i++) { + const winner = bidWinners[i]; + + expect(auction.winnerAddresses[i]).toEqual(winner.address); + + expect(winner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`); + + const initialBalance = 20000000; + + const [winnerAccountObj] = await registry.getAccounts([winner.address]); + expect(winnerAccountObj).toBeDefined(); + expect(winnerAccountObj.address).toBe(winner.address); + + const [{ type, quantity: currentBalance }] = winnerAccountObj.balance; + expect(type).toBe(DENOM); + + const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10); + + const expectedBalance = (parseInt(currentBalance, 10) + winningBidAmount).toString(); + + expect(expectedBalance).toEqual(initialBalance.toString()); + } }); };