Add test for checking balances after provider funds are released
This commit is contained in:
parent
d95736b0cf
commit
60a2174a53
@ -163,6 +163,7 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
|
||||
let auctionCreatorAccount: { address: string, privateKey: string };
|
||||
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
|
||||
let sortedBidders: { address: string, privateKey: string, bid?: any }[] = [];
|
||||
let filteredBidders: { address: string, privateKey: string, bid?: any }[] = [];
|
||||
let invalidBidderAddresses: string[] = [];
|
||||
|
||||
const numBidders = bidAmounts.length;
|
||||
@ -294,24 +295,47 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
|
||||
setTimeout(done, waitTime);
|
||||
});
|
||||
|
||||
test('Check auction winner, status, and all bidder balances.', async () => {
|
||||
test('Check auction status, winners and creator balance.', async () => {
|
||||
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||
expect(auction.status).toEqual('completed');
|
||||
|
||||
// Filter bidders to exclude bids exceeding maxPrice
|
||||
const filteredBidders = sortedBidders.filter(bidder => {
|
||||
filteredBidders = sortedBidders.filter(bidder => {
|
||||
return parseInt(bidder.bid.reveal.bidAmount) <= parseInt(`${maxPrice}${DENOM}`);
|
||||
});
|
||||
|
||||
const numWinners = Math.min(filteredBidders.length, numProviders);
|
||||
const winningBidders = filteredBidders.slice(0, numWinners);
|
||||
const losingBidders = bidderAccounts.filter(bidder => !winningBidders.includes(bidder));
|
||||
|
||||
// Check winner price is equal to highest winning bid
|
||||
const winningBidAmount = parseInt(auction.winnerPrice.quantity);
|
||||
const expectedWinningPrice = winningBidders[numWinners - 1].bid.reveal.bidAmount;
|
||||
expect(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`).toEqual(expectedWinningPrice);
|
||||
|
||||
const [creatorAccountObj] = await registry.getAccounts([auctionCreatorAccount.address]);
|
||||
expect(creatorAccountObj).toBeDefined();
|
||||
|
||||
const [{ type, quantity }] = creatorAccountObj.balance;
|
||||
const actualBalance = parseInt(quantity);
|
||||
|
||||
// Check auction creator balance
|
||||
const totalWinningAmount = parseInt(auction.winnerPrice.quantity) * winningBidders.length;
|
||||
const expectedCreatorBalance = creatorInitialBalance - totalWinningAmount - txFees;
|
||||
expect(actualBalance).toBe(expectedCreatorBalance);
|
||||
expect(type).toBe(DENOM);
|
||||
});
|
||||
|
||||
test('Release funds and check provider balances.', async () => {
|
||||
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||
|
||||
const numWinners = Math.min(filteredBidders.length, numProviders);
|
||||
const winningBidders = filteredBidders.slice(0, numWinners);
|
||||
const losingBidders = bidderAccounts.filter(bidder => !winningBidders.includes(bidder));
|
||||
|
||||
const winningBidAmount = parseInt(auction.winnerPrice.quantity);
|
||||
|
||||
// Release funds
|
||||
await registry.releaseFunds({ auctionId }, auctionCreatorAccount.privateKey, fee);
|
||||
|
||||
// Check balances of auction winners
|
||||
for (let i = 0; i < winningBidders.length; i++) {
|
||||
const bidWinner = winningBidders[i];
|
||||
@ -351,18 +375,6 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
|
||||
expect(actualBalance).toBe(expectedBidderBalance);
|
||||
expect(type).toBe(DENOM);
|
||||
}
|
||||
|
||||
const [creatorAccountObj] = await registry.getAccounts([auctionCreatorAccount.address]);
|
||||
expect(creatorAccountObj).toBeDefined();
|
||||
|
||||
const [{ type, quantity }] = creatorAccountObj.balance;
|
||||
const actualBalance = parseInt(quantity);
|
||||
|
||||
// Check auction creator balance
|
||||
const totalWinningAmount = parseInt(auction.winnerPrice.quantity) * winningBidders.length;
|
||||
const expectedCreatorBalance = creatorInitialBalance - totalWinningAmount - txFees;
|
||||
expect(actualBalance).toBe(expectedCreatorBalance);
|
||||
expect(type).toBe(DENOM);
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user