@@ -186,6 +186,48 @@ describe('L1GraphTokenGateway', () => {
186
186
expect ( await l1GraphTokenGateway . escrow ( ) ) . eq ( bridgeEscrow . address )
187
187
} )
188
188
} )
189
+ describe ( 'addToCallhookWhitelist' , function ( ) {
190
+ it ( 'is not callable by addreses that are not the governor' , async function ( ) {
191
+ const tx = l1GraphTokenGateway
192
+ . connect ( tokenSender . signer )
193
+ . addToCallhookWhitelist ( tokenSender . address )
194
+ await expect ( tx ) . revertedWith ( 'Caller must be Controller governor' )
195
+ expect ( await l1GraphTokenGateway . callhookWhitelist ( tokenSender . address ) ) . eq ( false )
196
+ } )
197
+ it ( 'adds an address to the callhook whitelist' , async function ( ) {
198
+ const tx = l1GraphTokenGateway
199
+ . connect ( governor . signer )
200
+ . addToCallhookWhitelist ( tokenSender . address )
201
+ await expect ( tx )
202
+ . emit ( l1GraphTokenGateway , 'AddedToCallhookWhitelist' )
203
+ . withArgs ( tokenSender . address )
204
+ expect ( await l1GraphTokenGateway . callhookWhitelist ( tokenSender . address ) ) . eq ( true )
205
+ } )
206
+ } )
207
+ describe ( 'removeFromCallhookWhitelist' , function ( ) {
208
+ it ( 'is not callable by addreses that are not the governor' , async function ( ) {
209
+ await l1GraphTokenGateway
210
+ . connect ( governor . signer )
211
+ . addToCallhookWhitelist ( tokenSender . address )
212
+ const tx = l1GraphTokenGateway
213
+ . connect ( tokenSender . signer )
214
+ . removeFromCallhookWhitelist ( tokenSender . address )
215
+ await expect ( tx ) . revertedWith ( 'Caller must be Controller governor' )
216
+ expect ( await l1GraphTokenGateway . callhookWhitelist ( tokenSender . address ) ) . eq ( true )
217
+ } )
218
+ it ( 'removes an address from the callhook whitelist' , async function ( ) {
219
+ await l1GraphTokenGateway
220
+ . connect ( governor . signer )
221
+ . addToCallhookWhitelist ( tokenSender . address )
222
+ const tx = l1GraphTokenGateway
223
+ . connect ( governor . signer )
224
+ . removeFromCallhookWhitelist ( tokenSender . address )
225
+ await expect ( tx )
226
+ . emit ( l1GraphTokenGateway , 'RemovedFromCallhookWhitelist' )
227
+ . withArgs ( tokenSender . address )
228
+ expect ( await l1GraphTokenGateway . callhookWhitelist ( tokenSender . address ) ) . eq ( false )
229
+ } )
230
+ } )
189
231
describe ( 'Pausable behavior' , ( ) => {
190
232
it ( 'cannot be paused or unpaused by someone other than governor or pauseGuardian' , async ( ) => {
191
233
let tx = l1GraphTokenGateway . connect ( tokenSender . signer ) . setPaused ( false )
@@ -230,7 +272,7 @@ describe('L1GraphTokenGateway', () => {
230
272
} )
231
273
232
274
context ( '> after configuring and unpausing' , function ( ) {
233
- const createMsgData = function ( ) {
275
+ const createMsgData = function ( callHookData : string ) {
234
276
const selector = l1GraphTokenGateway . interface . getSighash ( 'finalizeInboundTransfer' )
235
277
const params = utils . defaultAbiCoder . encode (
236
278
[ 'address' , 'address' , 'address' , 'uint256' , 'bytes' ] ,
@@ -239,7 +281,7 @@ describe('L1GraphTokenGateway', () => {
239
281
tokenSender . address ,
240
282
l2Receiver . address ,
241
283
toGRT ( '10' ) ,
242
- utils . defaultAbiCoder . encode ( [ 'bytes' , 'bytes' ] , [ emptyCallHookData , emptyCallHookData ] ) ,
284
+ utils . defaultAbiCoder . encode ( [ 'bytes' , 'bytes' ] , [ emptyCallHookData , callHookData ] ) ,
243
285
] ,
244
286
)
245
287
const outboundData = utils . hexlify ( utils . concat ( [ selector , params ] ) )
@@ -283,7 +325,11 @@ describe('L1GraphTokenGateway', () => {
283
325
)
284
326
return expectedInboxAccsEntry
285
327
}
286
- const testValidOutboundTransfer = async function ( signer : Signer , data : string ) {
328
+ const testValidOutboundTransfer = async function (
329
+ signer : Signer ,
330
+ data : string ,
331
+ callHookData : string ,
332
+ ) {
287
333
const tx = l1GraphTokenGateway
288
334
. connect ( signer )
289
335
. outboundTransfer ( grt . address , l2Receiver . address , toGRT ( '10' ) , maxGas , gasPriceBid , data , {
@@ -295,7 +341,7 @@ describe('L1GraphTokenGateway', () => {
295
341
. emit ( l1GraphTokenGateway , 'DepositInitiated' )
296
342
. withArgs ( grt . address , tokenSender . address , l2Receiver . address , expectedSeqNum , toGRT ( '10' ) )
297
343
298
- const msgData = createMsgData ( )
344
+ const msgData = createMsgData ( callHookData )
299
345
const msgDataHash = utils . keccak256 ( msgData )
300
346
const expectedInboxAccsEntry = createInboxAccsEntry ( msgDataHash )
301
347
@@ -365,15 +411,15 @@ describe('L1GraphTokenGateway', () => {
365
411
} )
366
412
it ( 'puts tokens in escrow and creates a retryable ticket' , async function ( ) {
367
413
await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '10' ) )
368
- await testValidOutboundTransfer ( tokenSender . signer , defaultData )
414
+ await testValidOutboundTransfer ( tokenSender . signer , defaultData , emptyCallHookData )
369
415
} )
370
416
it ( 'decodes the sender address from messages sent by the router' , async function ( ) {
371
417
await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '10' ) )
372
418
const routerEncodedData = utils . defaultAbiCoder . encode (
373
419
[ 'address' , 'bytes' ] ,
374
420
[ tokenSender . address , defaultData ] ,
375
421
)
376
- await testValidOutboundTransfer ( mockRouter . signer , routerEncodedData )
422
+ await testValidOutboundTransfer ( mockRouter . signer , routerEncodedData , emptyCallHookData )
377
423
} )
378
424
it ( 'reverts when called with the wrong value' , async function ( ) {
379
425
await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '10' ) )
@@ -392,7 +438,7 @@ describe('L1GraphTokenGateway', () => {
392
438
)
393
439
await expect ( tx ) . revertedWith ( 'WRONG_ETH_VALUE' )
394
440
} )
395
- it ( 'reverts when called with nonempty calldata' , async function ( ) {
441
+ it ( 'reverts when called with nonempty calldata, if the sender is not whitelisted ' , async function ( ) {
396
442
await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '10' ) )
397
443
const tx = l1GraphTokenGateway
398
444
. connect ( tokenSender . signer )
@@ -409,6 +455,17 @@ describe('L1GraphTokenGateway', () => {
409
455
)
410
456
await expect ( tx ) . revertedWith ( 'CALL_HOOK_DATA_NOT_ALLOWED' )
411
457
} )
458
+ it ( 'allows sending nonempty calldata, if the sender is whitelisted' , async function ( ) {
459
+ await l1GraphTokenGateway
460
+ . connect ( governor . signer )
461
+ . addToCallhookWhitelist ( tokenSender . address )
462
+ await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '10' ) )
463
+ await testValidOutboundTransfer (
464
+ tokenSender . signer ,
465
+ defaultDataWithNotEmptyCallHookData ,
466
+ notEmptyCallHookData ,
467
+ )
468
+ } )
412
469
it ( 'reverts when the sender does not have enough GRT' , async function ( ) {
413
470
await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '1001' ) )
414
471
const tx = l1GraphTokenGateway
@@ -503,7 +560,7 @@ describe('L1GraphTokenGateway', () => {
503
560
} )
504
561
it ( 'reverts if the gateway is revoked from escrow' , async function ( ) {
505
562
await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '10' ) )
506
- await testValidOutboundTransfer ( tokenSender . signer , defaultData )
563
+ await testValidOutboundTransfer ( tokenSender . signer , defaultData , emptyCallHookData )
507
564
// At this point, the gateway holds 10 GRT in escrow
508
565
// But we revoke the gateway's permission to move the funds:
509
566
await bridgeEscrow . connect ( governor . signer ) . revokeAll ( l1GraphTokenGateway . address )
@@ -538,7 +595,7 @@ describe('L1GraphTokenGateway', () => {
538
595
} )
539
596
it ( 'sends tokens out of escrow' , async function ( ) {
540
597
await grt . connect ( tokenSender . signer ) . approve ( l1GraphTokenGateway . address , toGRT ( '10' ) )
541
- await testValidOutboundTransfer ( tokenSender . signer , defaultData )
598
+ await testValidOutboundTransfer ( tokenSender . signer , defaultData , emptyCallHookData )
542
599
// At this point, the gateway holds 10 GRT in escrow
543
600
const encodedCalldata = l1GraphTokenGateway . interface . encodeFunctionData (
544
601
'finalizeInboundTransfer' ,
0 commit comments