From 71a23c34e9c56c96d57a593afd7c64f543390152 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 20 Sep 2024 15:12:30 +0530 Subject: [PATCH] Update check to exclude bids greater than max price --- src/auction.test.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/auction.test.ts b/src/auction.test.ts index a0853d1..a52d2fe 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -3,7 +3,7 @@ import Long from 'long'; import { coin } from '@cosmjs/amino'; import { Coin } from '@cosmjs/proto-signing'; -import { Registry, Account, createBid } from './index'; +import { Registry, Account, createBid, INVALID_BID_ERROR } from './index'; import { getConfig } from './testing/helper'; import { DENOM } from './constants'; import { Duration } from './proto/google/protobuf/duration'; @@ -282,12 +282,18 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number return parseInt(a.bid.reveal.bidAmount) - parseInt(b.bid.reveal.bidAmount); }); - const winningBidders = sortedBidders.slice(0, numProviders); - const losingBidders = sortedBidders.slice(numProviders); + const filteredBidders = sortedBidders.filter(bidder => { + return parseInt(bidder.bid.reveal.bidAmount) <= parseInt(maxPrice.amount); + }); + + const numWinners = Math.min(filteredBidders.length, numProviders); + const winningBidders = filteredBidders.slice(0, numWinners); + const losingBidders = bidderAccounts.filter(bidder => !winningBidders.includes(bidder)); // Check winner price is equal to highest winning bid const winningBidAmount = parseInt(auction.winnerPrice.quantity); - expect(auction.winnerPrice.quantity).toEqual(bidAmounts[numProviders - 1].amount); + const expectedWinningPrice = winningBidders[numWinners - 1].bid.reveal.bidAmount; + expect(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`).toEqual(expectedWinningPrice); // Check balances of auction winners for (let i = 0; i < winningBidders.length; i++) { @@ -332,7 +338,7 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number // Check whether the balance after deducting locked amount is less than the actual balance expect(type).toBe(DENOM); - expect(parseInt(quantity)).toBe(expectedCreatorBalance); + expect(parseInt(quantity)).toBeLessThan(expectedCreatorBalance); }); };