Skip to content

Commit c4e5e78

Browse files
committed
test(test-suite): instrument HCU whitelist tx waits
1 parent 21a6f6e commit c4e5e78

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

test-suite/e2e/test/encryptedERC20/EncryptedERC20.HCU.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
import type { TransactionResponse } from 'ethers';
23
import { ethers } from 'hardhat';
34

45
import { createInstances } from '../instance';
@@ -106,11 +107,19 @@ describe('EncryptedERC20:HCU', function () {
106107

107108
describe('block cap scenarios', function () {
108109
const BATCHED_TRANSFER_GAS_LIMIT = 1_000_000;
110+
const RECEIPT_TIMEOUT_MS = 300_000;
109111
let savedHCUPerBlock: bigint;
110112
let savedMaxHCUPerTx: bigint;
111113
let savedMaxHCUDepthPerTx: bigint;
112114
let wasWhitelisted: boolean;
113115

116+
async function waitForConfirmedTx(tx: TransactionResponse, label: string) {
117+
console.log(`[HCU] waiting ${label} ${tx.hash}`);
118+
const receipt = await tx.wait(1, RECEIPT_TIMEOUT_MS);
119+
console.log(`[HCU] mined ${label} ${tx.hash} block=${receipt?.blockNumber} status=${receipt?.status}`);
120+
return receipt;
121+
}
122+
114123
// eslint-disable-next-line @typescript-eslint/no-explicit-any
115124
async function sendEncryptedTransfer(ctx: any, sender: string, recipient: string, amount: number, overrides?: any) {
116125
const erc20 = ctx.erc20.connect(ctx.signers[sender]);
@@ -256,25 +265,25 @@ describe('EncryptedERC20:HCU', function () {
256265
await ethers.provider.send('evm_setIntervalMining', [0]);
257266

258267
const mintTx = await this.erc20.mint(10000);
259-
await waitForTransactionReceipt(mintTx.hash);
268+
await waitForConfirmedTx(mintTx, 'mint');
260269

261270
const whitelistTx = await ownerHcuLimit.addToBlockHCUWhitelist(this.contractAddress);
262-
await waitForTransactionReceipt(whitelistTx.hash);
271+
await waitForConfirmedTx(whitelistTx, 'whitelist');
263272
await mineNBlocks(1);
264273

265274
// Transfer while whitelisted — meter stays at 0
266275
const tx1 = await sendEncryptedTransfer(this, 'alice', this.signers.bob.address, 100);
267-
await waitForTransactionReceipt(tx1.hash);
276+
await waitForConfirmedTx(tx1, 'whitelisted-transfer');
268277

269278
const [, usedHCUWhitelisted] = await this.hcuLimit.getBlockMeter();
270279
expect(usedHCUWhitelisted).to.eq(0n, 'Whitelisted contract should not count HCU');
271280

272281
const unwhitelistTx = await ownerHcuLimit.removeFromBlockHCUWhitelist(this.contractAddress);
273-
await waitForTransactionReceipt(unwhitelistTx.hash);
282+
await waitForConfirmedTx(unwhitelistTx, 'unwhitelist');
274283

275284
// Transfer after removal — meter should count HCU
276285
const tx2 = await sendEncryptedTransfer(this, 'alice', this.signers.bob.address, 100);
277-
await waitForTransactionReceipt(tx2.hash);
286+
await waitForConfirmedTx(tx2, 'post-whitelist-transfer');
278287

279288
const [, usedHCUAfterRemoval] = await this.hcuLimit.getBlockMeter();
280289
expect(usedHCUAfterRemoval).to.be.greaterThan(0n, 'Should count HCU after whitelist removal');

0 commit comments

Comments
 (0)