From c89ff604e8d6115ced4061dbc78611c6f07a9a19 Mon Sep 17 00:00:00 2001 From: Rens Rooimans Date: Wed, 3 Apr 2024 16:38:35 +0200 Subject: [PATCH] increase coverage --- contracts/gas-snapshots/ccip.gas-snapshot | 11 +++- .../v0.8/ccip/pools/TokenAdminRegistry.sol | 10 ++++ .../ccip/test/pools/TokenAdminRegistry.t.sol | 55 ++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/contracts/gas-snapshots/ccip.gas-snapshot b/contracts/gas-snapshots/ccip.gas-snapshot index bb30dffa4c..f500aa7a3e 100644 --- a/contracts/gas-snapshots/ccip.gas-snapshot +++ b/contracts/gas-snapshots/ccip.gas-snapshot @@ -179,7 +179,7 @@ EVM2EVMOnRamp_forwardFromRouter:testPriceNotFoundForTokenReverts() (gas: 35137) EVM2EVMOnRamp_forwardFromRouter:testShouldIncrementSeqNumAndNonceSuccess() (gas: 169353) EVM2EVMOnRamp_forwardFromRouter:testShouldStoreLinkFees() (gas: 104547) EVM2EVMOnRamp_forwardFromRouter:testShouldStoreNonLinkFees() (gas: 123825) -EVM2EVMOnRamp_forwardFromRouter:testSourceTokenDataTooLargeReverts() (gas: 3446952) +EVM2EVMOnRamp_forwardFromRouter:testSourceTokenDataTooLargeReverts() (gas: 3446997) EVM2EVMOnRamp_forwardFromRouter:testTooManyTokensReverts() (gas: 28283) EVM2EVMOnRamp_forwardFromRouter:testUnhealthyReverts() (gas: 43114) EVM2EVMOnRamp_forwardFromRouter:testUnsupportedTokenReverts() (gas: 108972) @@ -372,6 +372,15 @@ Router_setWrappedNative:testOnlyOwnerReverts() (gas: 10978) SelfFundedPingPong_ccipReceive:test_FundingIfNotANopReverts() (gas: 53492) SelfFundedPingPong_ccipReceive:test_FundingSuccess() (gas: 403758) SelfFundedPingPong_setCountIncrBeforeFunding:test_setCountIncrBeforeFunding() (gas: 19775) +TokenAdminRegistry_getPool:test_getPool_Success() (gas: 14806) +TokenAdminRegistry_getPool:test_getPool_UnsupportedToken_Revert() (gas: 12732) +TokenAdminRegistry_getPools:test_getPools_Success() (gas: 37790) +TokenAdminRegistry_isAdministrator:test_isAdministrator_Success() (gas: 33214) +TokenAdminRegistry_registerAdministrator:test_registerAdministrator_AlreadyRegistered_Revert() (gas: 40979) +TokenAdminRegistry_registerAdministrator:test_registerAdministrator_OnlyRegistryModule_Revert() (gas: 13179) +TokenAdminRegistry_registerAdministrator:test_registerAdministrator_Success() (gas: 42914) +TokenAdminRegistry_setPool:test_setPool_OnlyAdministrator_Revert() (gas: 17882) +TokenAdminRegistry_setPool:test_setPool_Success() (gas: 26550) TokenPoolWithAllowList_applyAllowListUpdates:testOnlyOwnerReverts() (gas: 12082) TokenPoolWithAllowList_applyAllowListUpdates:testSetAllowListSkipsZeroSuccess() (gas: 20445) TokenPoolWithAllowList_applyAllowListUpdates:testSetAllowListSuccess() (gas: 175816) diff --git a/contracts/src/v0.8/ccip/pools/TokenAdminRegistry.sol b/contracts/src/v0.8/ccip/pools/TokenAdminRegistry.sol index 820acbdd5f..96e813630c 100644 --- a/contracts/src/v0.8/ccip/pools/TokenAdminRegistry.sol +++ b/contracts/src/v0.8/ccip/pools/TokenAdminRegistry.sol @@ -7,6 +7,8 @@ import {OwnerIsCreator} from "../../shared/access/OwnerIsCreator.sol"; import {EnumerableSet} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableSet.sol"; +// This contract has minimal functionality and minimal test coverage. It will be +// improved upon in future tickets. contract TokenAdminRegistry is ITokenAdminRegistry, OwnerIsCreator { using EnumerableSet for EnumerableSet.AddressSet; @@ -101,4 +103,12 @@ contract TokenAdminRegistry is ITokenAdminRegistry, OwnerIsCreator { emit AdministratorRegistered(localToken, administrator); } + + // ================================================================ + // │ Registry Modules │ + // ================================================================ + + function addRegistryModule(address module) external onlyOwner { + s_RegistryModules.add(module); + } } diff --git a/contracts/src/v0.8/ccip/test/pools/TokenAdminRegistry.t.sol b/contracts/src/v0.8/ccip/test/pools/TokenAdminRegistry.t.sol index 095c79eb74..d3d4df6f77 100644 --- a/contracts/src/v0.8/ccip/test/pools/TokenAdminRegistry.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/TokenAdminRegistry.t.sol @@ -8,8 +8,12 @@ contract TokenAdminRegistrySetup is TokenSetup { event AdministratorRegistered(address indexed token, address indexed administrator); event PoolSet(address indexed token, address indexed pool); + address internal s_registryModule = makeAddr("registryModule"); + function setUp() public virtual override { TokenSetup.setUp(); + + s_tokenAdminRegistry.addRegistryModule(s_registryModule); } } @@ -42,7 +46,7 @@ contract TokenAdminRegistry_getPool is TokenAdminRegistrySetup { assertEq(got, s_sourcePoolByToken[s_sourceTokens[0]]); } - function test_getPool_UnsupportedToken_Reverts() public { + function test_getPool_UnsupportedToken_Revert() public { address doesNotExist = makeAddr("doesNotExist"); vm.expectRevert(abi.encodeWithSelector(TokenAdminRegistry.UnsupportedToken.selector, doesNotExist)); s_tokenAdminRegistry.getPool(doesNotExist); @@ -70,3 +74,52 @@ contract TokenAdminRegistry_setPool is TokenAdminRegistrySetup { s_tokenAdminRegistry.setPool(s_sourceTokens[0], makeAddr("pool")); } } + +contract TokenAdminRegistry_isAdministrator is TokenAdminRegistrySetup { + function test_isAdministrator_Success() public { + assert(s_tokenAdminRegistry.isAdministrator(s_sourceTokens[0], OWNER)); + + address newOwner = makeAddr("newOwner"); + address newToken = makeAddr("newToken"); + assert(!s_tokenAdminRegistry.isAdministrator(newToken, newOwner)); + assert(!s_tokenAdminRegistry.isAdministrator(newToken, OWNER)); + + s_tokenAdminRegistry.registerAdministratorPermissioned(s_sourceTokens[0], newOwner); + + assert(s_tokenAdminRegistry.isAdministrator(s_sourceTokens[0], newOwner)); + assert(!s_tokenAdminRegistry.isAdministrator(s_sourceTokens[0], OWNER)); + } +} + +contract TokenAdminRegistry_registerAdministrator is TokenAdminRegistrySetup { + function test_registerAdministrator_Success() public { + vm.startPrank(s_registryModule); + address newOwner = makeAddr("newOwner"); + address newToken = makeAddr("newToken"); + + vm.expectEmit(); + emit AdministratorRegistered(newToken, newOwner); + + s_tokenAdminRegistry.registerAdministrator(newToken, newOwner); + + assert(s_tokenAdminRegistry.isAdministrator(newToken, newOwner)); + } + + function test_registerAdministrator_OnlyRegistryModule_Revert() public { + address newToken = makeAddr("newToken"); + vm.stopPrank(); + + vm.expectRevert(abi.encodeWithSelector(TokenAdminRegistry.OnlyRegistryModule.selector, address(this))); + s_tokenAdminRegistry.registerAdministrator(newToken, OWNER); + } + + function test_registerAdministrator_AlreadyRegistered_Revert() public { + address newToken = makeAddr("newToken"); + vm.startPrank(s_registryModule); + + s_tokenAdminRegistry.registerAdministrator(newToken, OWNER); + + vm.expectRevert(abi.encodeWithSelector(TokenAdminRegistry.AlreadyRegistered.selector, newToken, OWNER)); + s_tokenAdminRegistry.registerAdministrator(newToken, OWNER); + } +}