Check balances after locked amounts are deducted/returned

This commit is contained in:
IshaVenikar 2024-09-20 12:26:16 +05:30
parent 6562b9fc30
commit 5c3408279f

View File

@ -116,6 +116,19 @@ const auctionTests = () => {
const expectedBidAmounts = bidAmounts.map(bidAmount => { return { quantity: bidAmount.amount, type: bidAmount.denom }; }); const expectedBidAmounts = bidAmounts.map(bidAmount => { return { quantity: bidAmount.amount, type: bidAmount.denom }; });
const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount); const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount);
expect(actualBidAmounts).toEqual(expect.arrayContaining(expectedBidAmounts)); expect(actualBidAmounts).toEqual(expect.arrayContaining(expectedBidAmounts));
// Check that the bid amounts are locked after reveal phase
for (let i = 0; i < numBidders; i++) {
const [bidderrAccountObj] = await registry.getAccounts([bidderAccounts[i].address]);
expect(bidderrAccountObj).toBeDefined();
const [{ type, quantity }] = bidderrAccountObj.balance;
const actualBalance = parseInt(quantity);
const expectedBalance = bidderInitialBalance - parseInt(bidAmounts[i].amount);
expect(type).toBe(DENOM);
expect(actualBalance).toBeLessThan(expectedBalance);
}
}); });
test('Wait for auction completion.', (done) => { test('Wait for auction completion.', (done) => {
@ -202,6 +215,17 @@ const providerAuctionTests = () => {
expect(auction.auction?.id).toBeDefined(); expect(auction.auction?.id).toBeDefined();
auctionId = auction.auction?.id || ''; auctionId = auction.auction?.id || '';
expect(auction.auction?.status).toEqual('commit'); expect(auction.auction?.status).toEqual('commit');
// Check that the total locked amount is deducted from the creator's account
const [creatorAccountObj] = await registry.getAccounts([auctionCreatorAccount.address]);
expect(creatorAccountObj).toBeDefined();
const [{ type, quantity }] = creatorAccountObj.balance;
const actualBalance = parseInt(quantity);
const expectedBalance = creatorInitialBalance - (parseInt(maxPrice.amount) * numProviders);
expect(type).toBe(DENOM);
expect(actualBalance).toBeLessThan(expectedBalance);
}); });
test('Commit bids.', async () => { test('Commit bids.', async () => {
@ -308,6 +332,10 @@ const providerAuctionTests = () => {
// The balance would be less than expected balance // The balance would be less than expected balance
expect(type).toBe(DENOM); expect(type).toBe(DENOM);
expect(parseInt(quantity)).toBeLessThan(expectedCreatorBalance); expect(parseInt(quantity)).toBeLessThan(expectedCreatorBalance);
// Check whether the balance after deducting locked amount is less than the actual balance
const amountAfterDeduction = creatorInitialBalance - (parseInt(maxPrice.amount) * numProviders);
expect(parseInt(quantity)).toBeLessThan(amountAfterDeduction);
}); });
}; };