Skip to content

Commit c9dcc45

Browse files
committed
refactor(test-suite): simplify accumulation test to use block meter only
Replace receipt-based HCU comparison with three block meter readings: 1. Single-tx block → baseline meter 2. Two-tx block → meter exceeds baseline (proves accumulation) 3. Single-tx block → meter resets and matches baseline No cross-comparison of price tables, no getTxHCUFromTxReceipt needed.
1 parent 925f42f commit c9dcc45

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,33 @@ describe('EncryptedERC20:HCU', function () {
143143
it('should accumulate HCU from multiple users in the same block', async function () {
144144
await mintAndDistribute(this);
145145

146+
// Block 1: single tx — baseline meter
146147
await mineNBlocks(1);
147-
await ethers.provider.send('evm_setAutomine', [false]);
148-
149-
const txAlice = await sendEncryptedTransfer(this, 'alice', this.signers.carol.address, 1000);
150-
const txBob = await sendEncryptedTransfer(this, 'bob', this.signers.carol.address, 1000);
148+
const tx1 = await sendEncryptedTransfer(this, 'alice', this.signers.bob.address, 100);
149+
await tx1.wait();
150+
const [, meter1] = await this.hcuLimit.getBlockMeter();
151+
expect(meter1).to.be.greaterThan(0n);
151152

153+
// Block 2: two txs in same block — meter should exceed block 1
154+
await mineNBlocks(1);
155+
await ethers.provider.send('evm_setAutomine', [false]);
156+
const txA = await sendEncryptedTransfer(this, 'alice', this.signers.bob.address, 100);
157+
const txB = await sendEncryptedTransfer(this, 'bob', this.signers.alice.address, 100);
152158
await ethers.provider.send('evm_mine');
153159
await ethers.provider.send('evm_setAutomine', [true]);
154-
155-
const receiptAlice = await txAlice.wait();
156-
const receiptBob = await txBob.wait();
157-
158-
expect(receiptAlice?.status).to.eq(1);
159-
expect(receiptBob?.status).to.eq(1);
160-
expect(receiptAlice?.blockNumber).to.eq(receiptBob?.blockNumber);
161-
162-
const { globalTxHCU: hcuAlice } = getTxHCUFromTxReceipt(receiptAlice);
163-
const { globalTxHCU: hcuBob } = getTxHCUFromTxReceipt(receiptBob);
164-
expect(hcuAlice).to.be.greaterThan(0);
165-
expect(hcuBob).to.be.greaterThan(0);
166-
167-
// Verify block meter accumulated HCU from both txs.
168-
// We compare the on-chain meter against individual receipt-reported HCU
169-
// rather than their sum, because the receipt parser reconstructs HCU from
170-
// the @fhevm/solidity npm price table while the block meter uses the
171-
// deployed contract's hardcoded prices — a version skew can cause a small
172-
// discrepancy. Asserting meter > each individual tx proves accumulation
173-
// without cross-comparing price tables.
174-
const [, usedHCU] = await this.hcuLimit.getBlockMeter();
175-
expect(usedHCU).to.be.greaterThan(BigInt(hcuAlice), 'Block meter should exceed alice HCU alone');
176-
expect(usedHCU).to.be.greaterThan(BigInt(hcuBob), 'Block meter should exceed bob HCU alone');
160+
const [receiptA, receiptB] = await Promise.all([txA.wait(), txB.wait()]);
161+
expect(receiptA?.status).to.eq(1);
162+
expect(receiptB?.status).to.eq(1);
163+
expect(receiptA?.blockNumber).to.eq(receiptB?.blockNumber);
164+
const [, meter2] = await this.hcuLimit.getBlockMeter();
165+
expect(meter2).to.be.greaterThan(meter1);
166+
167+
// Block 3: single tx again — meter resets and matches block 1
168+
await mineNBlocks(1);
169+
const tx3 = await sendEncryptedTransfer(this, 'alice', this.signers.bob.address, 100);
170+
await tx3.wait();
171+
const [, meter3] = await this.hcuLimit.getBlockMeter();
172+
expect(meter3).to.eq(meter1);
177173
});
178174

179175
describe('with lowered limits', function () {

0 commit comments

Comments
 (0)