Check balances for all bidders after auction completion

This commit is contained in:
IshaVenikar 2024-09-19 14:23:38 +05:30
parent 742312b257
commit e6d2a9dac0
2 changed files with 25 additions and 14 deletions

View File

@ -140,7 +140,7 @@ const createAuctionTests = () => {
expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
const winningPriceAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = (bidderInitialBalance - winningPriceAmount).toString();
const expectedBalance = (bidderInitialBalance - winningPriceAmount);
const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]);
expect(winnerAccountObj).toBeDefined();
@ -149,7 +149,7 @@ const createAuctionTests = () => {
const [{ type, quantity }] = winnerAccountObj.balance;
expect(type).toBe(DENOM);
expect(quantity).toBe(expectedBalance);
expect(parseInt(quantity)).toBeLessThan(expectedBalance);
});
};
@ -255,43 +255,54 @@ const createProviderAuctionTests = () => {
setTimeout(done, waitTime);
});
test('Check auction winner, status, and bidder balance.', async () => {
test('Check auction winner, status, and all bidder balances.', async () => {
const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('completed');
const bidWinners = bidderAccounts.slice(0, 3);
const bidWinners = bidderAccounts.slice(0, 3); // Assuming top 3 are winners
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 [winnerAccountObj] = await registry.getAccounts([winner.address]);
expect(winnerAccountObj).toBeDefined();
expect(winnerAccountObj.address).toBe(winner.address);
const [{ type, quantity: currentBalance }] = winnerAccountObj.balance;
const [{ type, quantity }] = winnerAccountObj.balance;
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = bidderInitialBalance + winningBidAmount;
expect(type).toBe(DENOM);
expect(currentBalance).toEqual(expectedBalance);
expect(parseInt(quantity)).toBeLessThan(expectedBalance);
}
for (const bidder of bidderAccounts) {
const [bidderAccountObj] = await registry.getAccounts([bidder.address]);
expect(bidderAccountObj).toBeDefined();
expect(bidderAccountObj.address).toBe(bidder.address);
const [{ type, quantity }] = bidderAccountObj.balance;
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedWinningBalance = bidderInitialBalance - winningBidAmount;
expect(type).toBe(DENOM);
expect(parseInt(quantity)).toBeLessThan(expectedWinningBalance);
}
const [creatorAccountObj] = await registry.getAccounts([auctionCreatorAccount.address]);
expect(creatorAccountObj).toBeDefined();
expect(creatorAccountObj.address).toBe(auctionCreatorAccount.address);
const [{ type, quantity: currentBalance }] = creatorAccountObj.balance;
const [{ type, quantity }] = creatorAccountObj.balance;
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = creatorInitialBalance - (winningBidAmount * 3);
const totalWinningAmount = parseInt(auction.winnerPrice.quantity, 10) * bidWinners.length;
const expectedCreatorBalance = creatorInitialBalance - totalWinningAmount;
expect(type).toBe(DENOM);
expect(currentBalance).toEqual(expectedBalance);
expect(parseInt(quantity)).toBeLessThan(expectedCreatorBalance);
});
};

View File

@ -30,8 +30,8 @@ export const getConfig = () => {
rpcEndpoint: process.env.LACONICD_RPC_ENDPOINT || 'http://localhost:26657',
gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api',
fee: {
amount: [{ denom: 'alnt', amount: '400000' }],
gas: '400000'
amount: [{ denom: 'alnt', amount: '200000' }],
gas: '200000'
}
};
};