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
2 changed files with 16 additions and 9 deletions
Showing only changes of commit 6562b9fc30 - Show all commits

View File

@ -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

View File

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