@@ -5,7 +5,7 @@ import { createInstances } from '../instance';
55import { getSigners , initSigners } from '../signers' ;
66import { 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
1010describe ( '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