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 25 additions and 14 deletions
Showing only changes of commit e6d2a9dac0 - Show all commits

View File

@ -140,7 +140,7 @@ const createAuctionTests = () => {
expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`); expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
const winningPriceAmount = parseInt(auction.winnerPrice.quantity, 10); const winningPriceAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = (bidderInitialBalance - winningPriceAmount).toString(); const expectedBalance = (bidderInitialBalance - winningPriceAmount);
const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]); const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]);
expect(winnerAccountObj).toBeDefined(); expect(winnerAccountObj).toBeDefined();
@ -149,7 +149,7 @@ const createAuctionTests = () => {
const [{ type, quantity }] = winnerAccountObj.balance; const [{ type, quantity }] = winnerAccountObj.balance;
expect(type).toBe(DENOM); expect(type).toBe(DENOM);
expect(quantity).toBe(expectedBalance); expect(parseInt(quantity)).toBeLessThan(expectedBalance);
}); });
}; };
@ -255,43 +255,54 @@ const createProviderAuctionTests = () => {
setTimeout(done, waitTime); 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]); const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('completed'); 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++) { for (let i = 0; i < bidWinners.length; i++) {
const winner = bidWinners[i]; const winner = bidWinners[i];
expect(auction.winnerAddresses[i]).toEqual(winner.address); expect(auction.winnerAddresses[i]).toEqual(winner.address);
expect(winner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`); expect(winner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`);
const [winnerAccountObj] = await registry.getAccounts([winner.address]); const [winnerAccountObj] = await registry.getAccounts([winner.address]);
expect(winnerAccountObj).toBeDefined(); expect(winnerAccountObj).toBeDefined();
expect(winnerAccountObj.address).toBe(winner.address); 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 winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = bidderInitialBalance + winningBidAmount; const expectedBalance = bidderInitialBalance + winningBidAmount;
expect(type).toBe(DENOM); 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]); const [creatorAccountObj] = await registry.getAccounts([auctionCreatorAccount.address]);
expect(creatorAccountObj).toBeDefined(); expect(creatorAccountObj).toBeDefined();
expect(creatorAccountObj.address).toBe(auctionCreatorAccount.address); 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 totalWinningAmount = parseInt(auction.winnerPrice.quantity, 10) * bidWinners.length;
const expectedBalance = creatorInitialBalance - (winningBidAmount * 3); const expectedCreatorBalance = creatorInitialBalance - totalWinningAmount;
expect(type).toBe(DENOM); 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', rpcEndpoint: process.env.LACONICD_RPC_ENDPOINT || 'http://localhost:26657',
gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api', gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api',
fee: { fee: {
amount: [{ denom: 'alnt', amount: '400000' }], amount: [{ denom: 'alnt', amount: '200000' }],
gas: '400000' gas: '200000'
} }
}; };
}; };