|
1 | 1 | import { expect } from 'chai'; |
| 2 | +import type { TransactionResponse } from 'ethers'; |
2 | 3 | import { ethers } from 'hardhat'; |
3 | 4 |
|
4 | 5 | import { createInstances } from '../instance'; |
@@ -106,11 +107,19 @@ describe('EncryptedERC20:HCU', function () { |
106 | 107 |
|
107 | 108 | describe('block cap scenarios', function () { |
108 | 109 | const BATCHED_TRANSFER_GAS_LIMIT = 1_000_000; |
| 110 | + const RECEIPT_TIMEOUT_MS = 300_000; |
109 | 111 | let savedHCUPerBlock: bigint; |
110 | 112 | let savedMaxHCUPerTx: bigint; |
111 | 113 | let savedMaxHCUDepthPerTx: bigint; |
112 | 114 | let wasWhitelisted: boolean; |
113 | 115 |
|
| 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 | + |
114 | 123 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
115 | 124 | async function sendEncryptedTransfer(ctx: any, sender: string, recipient: string, amount: number, overrides?: any) { |
116 | 125 | const erc20 = ctx.erc20.connect(ctx.signers[sender]); |
@@ -256,25 +265,25 @@ describe('EncryptedERC20:HCU', function () { |
256 | 265 | await ethers.provider.send('evm_setIntervalMining', [0]); |
257 | 266 |
|
258 | 267 | const mintTx = await this.erc20.mint(10000); |
259 | | - await waitForTransactionReceipt(mintTx.hash); |
| 268 | + await waitForConfirmedTx(mintTx, 'mint'); |
260 | 269 |
|
261 | 270 | const whitelistTx = await ownerHcuLimit.addToBlockHCUWhitelist(this.contractAddress); |
262 | | - await waitForTransactionReceipt(whitelistTx.hash); |
| 271 | + await waitForConfirmedTx(whitelistTx, 'whitelist'); |
263 | 272 | await mineNBlocks(1); |
264 | 273 |
|
265 | 274 | // Transfer while whitelisted — meter stays at 0 |
266 | 275 | const tx1 = await sendEncryptedTransfer(this, 'alice', this.signers.bob.address, 100); |
267 | | - await waitForTransactionReceipt(tx1.hash); |
| 276 | + await waitForConfirmedTx(tx1, 'whitelisted-transfer'); |
268 | 277 |
|
269 | 278 | const [, usedHCUWhitelisted] = await this.hcuLimit.getBlockMeter(); |
270 | 279 | expect(usedHCUWhitelisted).to.eq(0n, 'Whitelisted contract should not count HCU'); |
271 | 280 |
|
272 | 281 | const unwhitelistTx = await ownerHcuLimit.removeFromBlockHCUWhitelist(this.contractAddress); |
273 | | - await waitForTransactionReceipt(unwhitelistTx.hash); |
| 282 | + await waitForConfirmedTx(unwhitelistTx, 'unwhitelist'); |
274 | 283 |
|
275 | 284 | // Transfer after removal — meter should count HCU |
276 | 285 | const tx2 = await sendEncryptedTransfer(this, 'alice', this.signers.bob.address, 100); |
277 | | - await waitForTransactionReceipt(tx2.hash); |
| 286 | + await waitForConfirmedTx(tx2, 'post-whitelist-transfer'); |
278 | 287 |
|
279 | 288 | const [, usedHCUAfterRemoval] = await this.hcuLimit.getBlockMeter(); |
280 | 289 | expect(usedHCUAfterRemoval).to.be.greaterThan(0n, 'Should count HCU after whitelist removal'); |
|
0 commit comments