@@ -85,6 +85,8 @@ describe.only('L2Registry', () => {
85
85
hackerAddress = await hacker . getAddress ( )
86
86
dummyAccount = await signers [ 4 ]
87
87
dummyAccountAddress = await dummyAccount . getAddress ( )
88
+ renewalController = await signers [ 5 ]
89
+ renewalControllerAddress = await renewalController . getAddress ( )
88
90
89
91
resolver = await DelegatableResolver . new ( )
90
92
metaDataservice = await StaticMetadataService . new ( 'https://ens.domains' )
@@ -404,5 +406,144 @@ describe.only('L2Registry', () => {
404
406
EMPTY_ADDRESS ,
405
407
)
406
408
} )
409
+
410
+ // Make sure that a test subnode can be renewed by the renewal controller address.
411
+ it ( 'should renew a subnode using the renewal controller' , async ( ) => {
412
+ const blockTime = ( await ethers . provider . getBlock ( 'latest' ) ) . timestamp
413
+
414
+ await controller . setSubnode (
415
+ TEST_NODE ,
416
+ labelhash ( 'sub' ) ,
417
+ subnodeOwnerAddress ,
418
+ resolver . address ,
419
+ // blocktime + 60 DAYs
420
+ blockTime + 60 * DAY ,
421
+ 0 , // no fuse
422
+ renewalControllerAddress , // no controller
423
+ { from : ownerAddress } ,
424
+ )
425
+
426
+ // Make sure the subnode is owned by the subnodeOwnerAddress
427
+ assert . equal ( await controller . ownerOf ( TEST_SUBNODE ) , subnodeOwnerAddress )
428
+
429
+ // Make sure the renewal controller is set to the renewalControllerAddress
430
+ assert . equal (
431
+ await controller . renewalControllerOf ( TEST_SUBNODE ) ,
432
+ renewalControllerAddress ,
433
+ )
434
+
435
+ // Extend the expiry of the subnode by 30 days by calling the setExpiry function from the renewal controller address.
436
+ await controller . setExpiry (
437
+ TEST_NODE ,
438
+ labelhash ( 'sub' ) ,
439
+ blockTime + 90 * DAY ,
440
+ {
441
+ from : renewalControllerAddress ,
442
+ } ,
443
+ )
444
+
445
+ // Make sure the subnode is still owned by the subnodeOwnerAddress
446
+ assert . equal ( await controller . ownerOf ( TEST_SUBNODE ) , subnodeOwnerAddress )
447
+
448
+ // Make sure the expiry of the subnode has been extended by 30 days
449
+ assert . equal (
450
+ await controller . expiryOf ( TEST_SUBNODE ) ,
451
+ blockTime + 90 * DAY ,
452
+ )
453
+ } )
454
+
455
+ // Make sure that the test subnode can be renewed by the parent renewal controller address.
456
+ it ( 'should renew a subnode using the parent renewal controller' , async ( ) => {
457
+ const blockTime = ( await ethers . provider . getBlock ( 'latest' ) ) . timestamp
458
+
459
+ await controller . setSubnode (
460
+ TEST_NODE ,
461
+ labelhash ( 'sub' ) ,
462
+ subnodeOwnerAddress ,
463
+ resolver . address ,
464
+ // blocktime + 60 DAYs
465
+ blockTime + 60 * DAY ,
466
+ 0 , // no fuse
467
+ renewalControllerAddress , // no controller
468
+ { from : ownerAddress } ,
469
+ )
470
+
471
+ // Predict the node hash of the sub-subnode
472
+ const subSubNode = namehash ( 'sub-sub.sub.test' )
473
+
474
+ // Make a sub-subnode without a renewal controller
475
+ await controller . setSubnode (
476
+ TEST_SUBNODE ,
477
+ labelhash ( 'sub-sub' ) ,
478
+ dummyAccountAddress ,
479
+ resolver . address ,
480
+ // blocktime + 60 DAYs
481
+ blockTime + 60 * DAY ,
482
+ 0 , // no fuse
483
+ EMPTY_ADDRESS , // no controller
484
+ { from : subnodeOwnerAddress } ,
485
+ )
486
+
487
+ // Make sure the sub-subnode is owned by the dummyAccountAddress
488
+ assert . equal ( await controller . ownerOf ( subSubNode ) , dummyAccountAddress )
489
+
490
+ // Make sure we can renew the sub-subnode using the parent renewal controller
491
+ await controller . setExpiry (
492
+ TEST_SUBNODE ,
493
+ labelhash ( 'sub-sub' ) ,
494
+ blockTime + 90 * DAY ,
495
+ {
496
+ from : renewalControllerAddress ,
497
+ } ,
498
+ )
499
+
500
+ // Make sure the sub-subnode is still owned by the dummyAccountAddress
501
+ assert . equal ( await controller . ownerOf ( subSubNode ) , dummyAccountAddress )
502
+
503
+ // Make sure the expiry of the sub-subnode has been extended by 30 days
504
+ assert . equal ( await controller . expiryOf ( subSubNode ) , blockTime + 90 * DAY )
505
+ } )
506
+
507
+ // Make sure that a hacker can't renew a subnode using the renewal controller address.
508
+ it ( 'should revert when a hacker tries to renew a subnode using the renewal controller' , async ( ) => {
509
+ const blockTime = ( await ethers . provider . getBlock ( 'latest' ) ) . timestamp
510
+
511
+ await controller . setSubnode (
512
+ TEST_NODE ,
513
+ labelhash ( 'sub' ) ,
514
+ subnodeOwnerAddress ,
515
+ resolver . address ,
516
+ // blocktime + 60 DAYs
517
+ blockTime + 60 * DAY ,
518
+ 0 , // no fuse
519
+ renewalControllerAddress , // no controller
520
+ { from : ownerAddress } ,
521
+ )
522
+
523
+ // Make sure the subnode is owned by the subnodeOwnerAddress
524
+ assert . equal ( await controller . ownerOf ( TEST_SUBNODE ) , subnodeOwnerAddress )
525
+
526
+ // Make sure the renewal controller is set to the renewalControllerAddress
527
+ assert . equal (
528
+ await controller . renewalControllerOf ( TEST_SUBNODE ) ,
529
+ renewalControllerAddress ,
530
+ )
531
+
532
+ // Extend the expiry of the subnode by 30 days by calling the setExpiry
533
+ // function from the renewal controller address, expect it to revert
534
+ // with custom error, Unauthorised(bytes32 node, address addr);
535
+ await expect (
536
+ controller . setExpiry (
537
+ TEST_NODE ,
538
+ labelhash ( 'sub' ) ,
539
+ blockTime + 90 * DAY ,
540
+ {
541
+ from : hackerAddress ,
542
+ } ,
543
+ ) ,
544
+ ) . to . be . revertedWith (
545
+ `Unauthorised("${ TEST_SUBNODE } ", "${ hackerAddress } ")` ,
546
+ )
547
+ } )
407
548
} )
408
549
} )
0 commit comments