Add check for balance of auction winner
This commit is contained in:
parent
93c78b4464
commit
216199fe47
@ -63,7 +63,6 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --runInBand --verbose --testPathPattern=src",
|
"test": "jest --runInBand --verbose --testPathPattern=src",
|
||||||
"test:authority-auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/authority-auction.test.ts",
|
"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: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",
|
"test:onboarding": "ONBOARDING_ENABLED=1 jest --runInBand --verbose src/onboarding.test.ts",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
|
@ -122,7 +122,7 @@ const createAuctionTests = () => {
|
|||||||
setTimeout(done, waitTime);
|
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]);
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
expect(auction.status).toEqual('completed');
|
expect(auction.status).toEqual('completed');
|
||||||
|
|
||||||
@ -132,6 +132,20 @@ const createAuctionTests = () => {
|
|||||||
expect(auction.winnerAddresses[0]).toEqual(highestBidder.address);
|
expect(auction.winnerAddresses[0]).toEqual(highestBidder.address);
|
||||||
expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[0].quantity}${auction.winnerBids[0].type}`);
|
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}`);
|
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);
|
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]);
|
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);
|
||||||
|
|
||||||
bidWinners.forEach((winner, index) => {
|
for (let i = 0; i < bidWinners.length; i++) {
|
||||||
expect(auction.winnerAddresses[index]).toEqual(winner.address);
|
const winner = bidWinners[i];
|
||||||
expect(bidWinners[index].bid.reveal.bidAmount).toEqual(`${auction.winnerBids[index].quantity}${auction.winnerBids[index].type}`);
|
|
||||||
});
|
expect(auction.winnerAddresses[i]).toEqual(winner.address);
|
||||||
expect(bidWinners[bidWinners.length - 1].bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user