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 38 additions and 8 deletions
Showing only changes of commit 216199fe47 - Show all commits

View File

@ -63,7 +63,6 @@
"scripts": {
"test": "jest --runInBand --verbose --testPathPattern=src",
"test:authority-auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/authority-auction.test.ts",
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
"test:onboarding": "ONBOARDING_ENABLED=1 jest --runInBand --verbose src/onboarding.test.ts",
"build": "tsc",

View File

@ -122,7 +122,7 @@ const createAuctionTests = () => {
setTimeout(done, waitTime);
});
test('Check auction winner, authority owner and status.', async () => {
test('Check auction winner, status, and balance.', async () => {
const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('completed');
@ -132,6 +132,20 @@ const createAuctionTests = () => {
expect(auction.winnerAddresses[0]).toEqual(highestBidder.address);
expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[0].quantity}${auction.winnerBids[0].type}`);
expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
const initialBalance = 20000000;
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = (initialBalance - winningBidAmount).toString();
const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]);
expect(winnerAccountObj).toBeDefined();
expect(winnerAccountObj.address).toBe(highestBidder.address);
const [{ type, quantity }] = winnerAccountObj.balance;
expect(type).toBe(DENOM);
expect(quantity).toBe(expectedBalance);
});
};
@ -231,17 +245,34 @@ const createSPAuctionTests = () => {
setTimeout(done, waitTime);
});
test('Check auction winner, authority owner and status.', async () => {
test('Check auction winner, status, and balance.', async () => {
const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('completed');
const bidWinners = bidderAccounts.slice(0, 3);
bidWinners.forEach((winner, index) => {
expect(auction.winnerAddresses[index]).toEqual(winner.address);
expect(bidWinners[index].bid.reveal.bidAmount).toEqual(`${auction.winnerBids[index].quantity}${auction.winnerBids[index].type}`);
});
expect(bidWinners[bidWinners.length - 1].bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
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 initialBalance = 20000000;
const [winnerAccountObj] = await registry.getAccounts([winner.address]);
expect(winnerAccountObj).toBeDefined();
expect(winnerAccountObj.address).toBe(winner.address);
const [{ type, quantity: currentBalance }] = winnerAccountObj.balance;
expect(type).toBe(DENOM);
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = (parseInt(currentBalance, 10) + winningBidAmount).toString();
expect(expectedBalance).toEqual(initialBalance.toString());
}
});
};