Skip to content

Commit 5d15dd4

Browse files
chore(test-suite): fix expired delegation, acl not allow tests (#2060)
* chore(test-suite): update acl failure test for delegated user decr - Previously: negative delegated user decryption tests asserted on raw Solidity selector 0x0190c506 and was using relayer-sdk v0.4.1 that was not handling the label 'now_allowed_on_host_acl' from relayer. - Now: bump relayer-sdk to v0.4.2 that handles the label and asserts on relayer-sdk error label not_allowed_on_host_acl, matching the structured error returned by the relayer on HTTP 400 * chore(test-suite): fix expired delegation test - Issue: setting pastExpiration=1 reverted at the contract level (ExpirationDateBeforeOneHour) so the test never reached the decryption step - Fix: delegate with a valid expiration (now + 1h1m), then use evm_increaseTime to fast-forward past it before attempting decryption * chore(common): update package-lock.json --------- Co-authored-by: Simon Eudeline <simon.eudeline@zama.ai>
1 parent 1f395b5 commit 5d15dd4

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-suite/e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@fhevm/solidity": "*",
1818
"@openzeppelin/contracts": "^5.3.0",
19-
"@zama-fhe/relayer-sdk": "^0.4.1",
19+
"@zama-fhe/relayer-sdk": "^0.4.2",
2020
"bigint-buffer": "^1.1.5",
2121
"dotenv": "^16.0.3",
2222
"encrypted-types": "^0.0.4"

test-suite/e2e/test/delegatedUserDecryption/delegatedUserDecryption.ts

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createInstances } from '../instance';
55
import { getSigners, initSigners } from '../signers';
66
import { delegatedUserDecryptSingleHandle, waitForBlock } from '../utils';
77

8-
const USER_DECRYPTION_NOT_DELEGATED_SELECTOR = '0x0190c506';
8+
const NOT_ALLOWED_ON_HOST_ACL = 'not_allowed_on_host_acl';
99

1010
describe('Delegated user decryption', function () {
1111
before(async function () {
@@ -233,8 +233,8 @@ describe('Delegated user decryption', function () {
233233
const balanceHandle = await this.token.balanceOf(this.smartWalletAddress);
234234
const { publicKey, privateKey } = this.instances.bob.generateKeypair();
235235

236-
await expect(
237-
delegatedUserDecryptSingleHandle(
236+
try {
237+
await delegatedUserDecryptSingleHandle(
238238
this.instances.bob,
239239
balanceHandle,
240240
this.tokenAddress,
@@ -243,18 +243,19 @@ describe('Delegated user decryption', function () {
243243
this.signers.bob,
244244
privateKey,
245245
publicKey,
246-
)
247-
).to.be.rejectedWith(
248-
new RegExp(USER_DECRYPTION_NOT_DELEGATED_SELECTOR),
249-
);
246+
);
247+
expect.fail('Expected delegated user decrypt to be rejected after revocation');
248+
} catch (err: any) {
249+
expect(err.relayerApiError?.label).to.equal(NOT_ALLOWED_ON_HOST_ACL);
250+
}
250251
});
251252

252253
it('test delegated user decryption should fail when no delegation exists', async function () {
253254
const balanceHandle = await this.token.balanceOf(this.smartWalletAddress);
254255
const { publicKey, privateKey } = this.instances.dave.generateKeypair();
255256

256-
await expect(
257-
delegatedUserDecryptSingleHandle(
257+
try {
258+
await delegatedUserDecryptSingleHandle(
258259
this.instances.dave,
259260
balanceHandle,
260261
this.tokenAddress,
@@ -263,8 +264,11 @@ describe('Delegated user decryption', function () {
263264
this.signers.dave,
264265
privateKey,
265266
publicKey,
266-
)
267-
).to.be.rejectedWith(new RegExp(USER_DECRYPTION_NOT_DELEGATED_SELECTOR));
267+
);
268+
expect.fail('Expected delegated user decrypt to be rejected without delegation');
269+
} catch (err: any) {
270+
expect(err.relayerApiError?.label).to.equal(NOT_ALLOWED_ON_HOST_ACL);
271+
}
268272
});
269273

270274
it('test delegated user decryption should fail when delegation is for wrong contract', async function () {
@@ -284,8 +288,8 @@ describe('Delegated user decryption', function () {
284288
const balanceHandle = await this.token.balanceOf(this.smartWalletAddress);
285289
const { publicKey, privateKey } = this.instances.eve.generateKeypair();
286290

287-
await expect(
288-
delegatedUserDecryptSingleHandle(
291+
try {
292+
await delegatedUserDecryptSingleHandle(
289293
this.instances.eve,
290294
balanceHandle,
291295
this.tokenAddress,
@@ -294,24 +298,37 @@ describe('Delegated user decryption', function () {
294298
this.signers.eve,
295299
privateKey,
296300
publicKey,
297-
)
298-
).to.be.rejectedWith(new RegExp(USER_DECRYPTION_NOT_DELEGATED_SELECTOR));
301+
);
302+
expect.fail('Expected delegated user decrypt to be rejected for wrong contract');
303+
} catch (err: any) {
304+
expect(err.relayerApiError?.label).to.equal(NOT_ALLOWED_ON_HOST_ACL);
305+
}
299306
});
300307

301308
it('test delegated user decryption should fail when delegation has expired', async function () {
302-
const pastExpiration = 1;
309+
// Expiration must be >1h from chain time (FHE library constraint).
310+
// Use block timestamp, not Date.now(), since evm_increaseTime shifts chain clock.
311+
const oneHour = 3600;
312+
const buffer = 60;
313+
const latestBlock = await ethers.provider.getBlock('latest');
314+
const expirationTimestamp = latestBlock!.timestamp + oneHour + buffer;
303315
const tx = await this.smartWallet
304316
.connect(this.signers.bob)
305-
.delegateUserDecryption(this.signers.eve.address, this.tokenAddress, pastExpiration);
317+
.delegateUserDecryption(this.signers.eve.address, this.tokenAddress, expirationTimestamp);
306318
await tx.wait();
319+
320+
// Fast-forward time past the expiration.
321+
await ethers.provider.send('evm_increaseTime', [oneHour + buffer + 1]);
322+
await ethers.provider.send('evm_mine', []);
323+
307324
const currentBlock = await ethers.provider.getBlockNumber();
308325
await waitForBlock(currentBlock + 15);
309326

310327
const balanceHandle = await this.token.balanceOf(this.smartWalletAddress);
311328
const { publicKey, privateKey } = this.instances.eve.generateKeypair();
312329

313-
await expect(
314-
delegatedUserDecryptSingleHandle(
330+
try {
331+
await delegatedUserDecryptSingleHandle(
315332
this.instances.eve,
316333
balanceHandle,
317334
this.tokenAddress,
@@ -320,7 +337,10 @@ describe('Delegated user decryption', function () {
320337
this.signers.eve,
321338
privateKey,
322339
publicKey,
323-
)
324-
).to.be.rejectedWith(new RegExp(USER_DECRYPTION_NOT_DELEGATED_SELECTOR));
340+
);
341+
expect.fail('Expected delegated user decrypt to be rejected for expired delegation');
342+
} catch (err: any) {
343+
expect(err.relayerApiError?.label).to.equal(NOT_ALLOWED_ON_HOST_ACL);
344+
}
325345
});
326346
});

0 commit comments

Comments
 (0)