Skip to content

Commit

Permalink
increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR committed Apr 3, 2024
1 parent f50dca5 commit c89ff60
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
11 changes: 10 additions & 1 deletion contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions contracts/src/v0.8/ccip/pools/TokenAdminRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
55 changes: 54 additions & 1 deletion contracts/src/v0.8/ccip/test/pools/TokenAdminRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit c89ff60

Please sign in to comment.