From 3126f005f8af2fceebbe93fda003d4d16961b1ce Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 15 Oct 2024 09:52:08 +0530 Subject: [PATCH 1/2] Make bid txs in parallel in auction tests --- src/auction.test.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/auction.test.ts b/src/auction.test.ts index 2f31b1b..d0ad600 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -67,10 +67,13 @@ const auctionTests = () => { test('Commit bids.', async () => { for (let i = 0; i < numBidders; i++) { bidAmounts.push((LOWEST_BID_AMOUNT + (i * 500)).toString()); - bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i]}${DENOM}`); - await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee); } + await Promise.all(bidderAccounts.map(async (bidderAccount, i) => { + bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccount.address, `${bidAmounts[i]}${DENOM}`); + return registry.commitBid({ auctionId, commitHash: bidderAccount.bid.commitHash }, bidderAccount.privateKey, fee); + })); + const [auction] = await registry.getAuctionsByIds([auctionId]); expect(auction.status).toEqual('commit'); expect(auction.bids.length).toEqual(3); @@ -90,9 +93,9 @@ const auctionTests = () => { const [auction] = await registry.getAuctionsByIds([auctionId]); expect(auction.status).toEqual('reveal'); - for (let i = 0; i < numBidders; i++) { - await registry.revealBid({ auctionId, reveal: bidderAccounts[i].bid.revealString }, bidderAccounts[i].privateKey, fee); - } + await Promise.all(bidderAccounts.map(async bidderAccount => { + return registry.revealBid({ auctionId, reveal: bidderAccount.bid.revealString }, bidderAccount.privateKey, fee); + })); }); test('Check bids are revealed', async () => { -- 2.45.2 From 26103a1cc8eb49e7afaa7e077a1eb7e8781c5b0b Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 15 Oct 2024 09:57:47 +0530 Subject: [PATCH 2/2] Make bid txs in parallel in provider auction tests --- src/auction.test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/auction.test.ts b/src/auction.test.ts index d0ad600..66efab4 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -178,7 +178,7 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number const otherAcc = await Account.generateFromMnemonic(mnenonic3); await otherAcc.init(); - await registry.sendCoins({ denom: DENOM, amount: CREATOR_INITIAL_BALANCE.toString(), destinationAddress: otherAcc.address }, privateKey, fee); + await registry.sendCoins({ denom: DENOM, amount: BIDDER_INITIAL_BALANCE.toString(), destinationAddress: otherAcc.address }, privateKey, fee); otherAccount = { address: otherAcc.address, privateKey: otherAcc.privateKey.toString('hex') }; }); @@ -208,10 +208,10 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number }); test('Commit bids.', async () => { - for (let i = 0; i < numBidders; i++) { - bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i]}${DENOM}`); - await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee); - } + await Promise.all(bidderAccounts.map(async (bidderAccount, i) => { + bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccount.address, `${bidAmounts[i]}${DENOM}`); + return registry.commitBid({ auctionId, commitHash: bidderAccount.bid.commitHash }, bidderAccount.privateKey, fee); + })); sortedBidders = bidderAccounts.slice().sort((a, b) => { return parseInt(a.bid.reveal.bidAmount) - parseInt(b.bid.reveal.bidAmount); @@ -242,21 +242,21 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number const [auction] = await registry.getAuctionsByIds([auctionId]); expect(auction.status).toEqual('reveal'); - for (let i = 0; i < numBidders; i++) { + await Promise.all(bidderAccounts.map(async bidderAccount => { try { await registry.revealBid( - { auctionId, reveal: bidderAccounts[i].bid.revealString }, - bidderAccounts[i].privateKey, + { auctionId, reveal: bidderAccount.bid.revealString }, + bidderAccount.privateKey, fee ); } catch (error: any) { - if (invalidBidderAddress === bidderAccounts[i].address) { + if (bidderAccount.address === invalidBidderAddress) { expect(error.toString()).toContain(INVALID_BID_ERROR); } else { throw error; } } - } + })); }); test('Check bids are revealed', async () => { -- 2.45.2