Add methods for creating auctions and add auction tests #28

Merged
nabarun merged 32 commits from deep-stack/registry-sdk:iv-create-auction-test into main 2024-09-25 13:21:05 +00:00
Showing only changes of commit 71a23c34e9 - Show all commits

View File

@ -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);
});
};