Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elatoskinas committed Sep 13, 2024
1 parent 4a0b46d commit 291f0fa
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 100 deletions.
109 changes: 55 additions & 54 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -35,61 +35,62 @@ BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas
BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 243707)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 23951)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2091438)
CCIPConfigSetup:test_getCapabilityConfiguration_Success() (gas: 9539)
CCIPConfig_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 66000)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 358959)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 476474)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 442826)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_TooManyOCR3Configs_Reverts() (gas: 33848)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeCommitConfigs_Reverts() (gas: 56914)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeExecutionConfigs_Reverts() (gas: 56852)
CCIPConfig_ConfigStateMachine:test__stateFromConfigLength_Success() (gas: 11719)
CCIPConfig_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8849)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 309789)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 45865)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_NonExistentConfigTransition_Reverts() (gas: 29690)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 370076)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 111376)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 145446)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 369852)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 145513)
CCIPConfig_ConfigStateMachine:test_getCapabilityConfiguration_Success() (gas: 9627)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1792577)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 1039157)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 1039188)
CCIPConfigSetup:test_getCapabilityConfiguration_Success() (gas: 9496)
CCIPConfig_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 81288)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 351506)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 459892)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 427187)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_TooManyOCR3Configs_Reverts() (gas: 27049)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeCommitConfigs_Reverts() (gas: 59262)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeExecutionConfigs_Reverts() (gas: 59200)
CCIPConfig_ConfigStateMachine:test__stateFromConfigLength_Success() (gas: 11650)
CCIPConfig_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8783)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 304312)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 45002)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_NonExistentConfigTransition_Reverts() (gas: 24194)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 358817)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 106815)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 137508)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 358593)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 137575)
CCIPConfig_ConfigStateMachine:test_getCapabilityConfiguration_Success() (gas: 9584)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1696208)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 989652)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 989683)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_OnlyCapabilitiesRegistryCanCall_Reverts() (gas: 9611)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ZeroLengthConfig_Success() (gas: 15996)
CCIPConfig_beforeCapabilityConfigSet:test_getCapabilityConfiguration_Success() (gas: 9627)
CCIPConfig_chainConfig:test__applyChainConfigUpdates_FChainNotPositive_Reverts() (gas: 184771)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 346687)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_nodeNotInRegistry_Reverts() (gas: 20340)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 270334)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_selectorNotFound_Reverts() (gas: 14819)
CCIPConfig_chainConfig:test_getCapabilityConfiguration_Success() (gas: 9648)
CCIPConfig_chainConfig:test_getPaginatedCCIPConfigs_Success() (gas: 370293)
CCIPConfig_constructor:test_constructor_Success() (gas: 3364563)
CCIPConfig_constructor:test_constructor_ZeroAddressNotAllowed_Revert() (gas: 61471)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InvalidConfigLength_Reverts() (gas: 25819)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InvalidConfigStateTransition_Reverts() (gas: 21913)
CCIPConfig_updatePluginConfig:test_getCapabilityConfiguration_Success() (gas: 9649)
CCIPConfig_updatePluginConfig:test_updatePluginConfig_InitToRunning_Success() (gas: 1088595)
CCIPConfig_updatePluginConfig:test_updatePluginConfig_RunningToStaging_Success() (gas: 2034382)
CCIPConfig_updatePluginConfig:test_updatePluginConfig_StagingToRunning_Success() (gas: 2034416)
CCIPConfig_validateConfig:test__validateConfigLessTransmittersThanSigners_Success() (gas: 334727)
CCIPConfig_validateConfig:test__validateConfigSmallerFChain_Success() (gas: 470319)
CCIPConfig_validateConfig:test__validateConfig_ABIEncodedAddress_OfframpAddressCannotBeZero_Reverts() (gas: 291171)
CCIPConfig_validateConfig:test__validateConfig_ChainSelectorNotFound_Reverts() (gas: 293905)
CCIPConfig_validateConfig:test__validateConfig_ChainSelectorNotSet_Reverts() (gas: 290826)
CCIPConfig_validateConfig:test__validateConfig_FChainTooHigh_Reverts() (gas: 339498)
CCIPConfig_validateConfig:test__validateConfig_FMustBePositive_Reverts() (gas: 291640)
CCIPConfig_validateConfig:test__validateConfig_FTooHigh_Reverts() (gas: 292976)
CCIPConfig_validateConfig:test__validateConfig_NodeNotInRegistry_Reverts() (gas: 346203)
CCIPConfig_validateConfig:test__validateConfig_NotEnoughTransmittersEmptyAddresses_Reverts() (gas: 308248)
CCIPConfig_validateConfig:test__validateConfig_NotEnoughTransmitters_Reverts() (gas: 1209756)
CCIPConfig_validateConfig:test__validateConfig_OfframpAddressCannotBeZero_Reverts() (gas: 290865)
CCIPConfig_validateConfig:test__validateConfig_P2PIdsLengthNotMatching_Reverts() (gas: 293693)
CCIPConfig_validateConfig:test__validateConfig_Success() (gas: 300892)
CCIPConfig_validateConfig:test__validateConfig_TooManySigners_Reverts() (gas: 494367)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ZeroLengthConfig_Success() (gas: 15850)
CCIPConfig_beforeCapabilityConfigSet:test_getCapabilityConfiguration_Success() (gas: 9584)
CCIPConfig_chainConfig:test__applyChainConfigUpdates_FChainNotPositive_Reverts() (gas: 184686)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 346519)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_nodeNotInRegistry_Reverts() (gas: 20326)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 270291)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_selectorNotFound_Reverts() (gas: 14841)
CCIPConfig_chainConfig:test_getCapabilityConfiguration_Success() (gas: 9605)
CCIPConfig_chainConfig:test_getPaginatedCCIPConfigs_Success() (gas: 369963)
CCIPConfig_constructor:test_constructor_Success() (gas: 3331483)
CCIPConfig_constructor:test_constructor_ZeroAddressNotAllowed_Revert() (gas: 61430)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InvalidConfigLength_Reverts() (gas: 21608)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InvalidConfigStateTransition_Reverts() (gas: 19107)
CCIPConfig_updatePluginConfig:test_getCapabilityConfiguration_Success() (gas: 9606)
CCIPConfig_updatePluginConfig:test_updatePluginConfig_InitToRunning_Success() (gas: 1036184)
CCIPConfig_updatePluginConfig:test_updatePluginConfig_RunningToStaging_Success() (gas: 1918020)
CCIPConfig_updatePluginConfig:test_updatePluginConfig_StagingToRunning_Success() (gas: 1918055)
CCIPConfig_validateConfig:test__validateConfigLessTransmittersThanSigners_Success() (gas: 331749)
CCIPConfig_validateConfig:test__validateConfigSmallerFChain_Success() (gas: 461988)
CCIPConfig_validateConfig:test__validateConfig_ABIEncodedAddress_OfframpAddressCannotBeZero_Reverts() (gas: 287563)
CCIPConfig_validateConfig:test__validateConfig_ChainSelectorNotFound_Reverts() (gas: 290340)
CCIPConfig_validateConfig:test__validateConfig_ChainSelectorNotSet_Reverts() (gas: 287196)
CCIPConfig_validateConfig:test__validateConfig_FChainTooHigh_Reverts() (gas: 334132)
CCIPConfig_validateConfig:test__validateConfig_FMustBePositive_Reverts() (gas: 288724)
CCIPConfig_validateConfig:test__validateConfig_FTooHigh_Reverts() (gas: 288163)
CCIPConfig_validateConfig:test__validateConfig_NodeNotInRegistry_Reverts() (gas: 340860)
CCIPConfig_validateConfig:test__validateConfig_NotEnoughTransmittersEmptyAddresses_Reverts() (gas: 305440)
CCIPConfig_validateConfig:test__validateConfig_NotEnoughTransmitters_Reverts() (gas: 1204532)
CCIPConfig_validateConfig:test__validateConfig_OfframpAddressCannotBeZero_Reverts() (gas: 287302)
CCIPConfig_validateConfig:test__validateConfig_Success() (gas: 297907)
CCIPConfig_validateConfig:test__validateConfig_TooManySigners_Reverts() (gas: 769732)
CCIPConfig_validateConfig:test__validateConfig_ZeroP2PId_Reverts() (gas: 291482)
CCIPConfig_validateConfig:test__validateConfig_ZeroSignerKey_Reverts() (gas: 291537)
CCIPConfig_validateConfig:test_getCapabilityConfiguration_Success() (gas: 9584)
CommitStore_constructor:test_Constructor_Success() (gas: 3013980)
CommitStore_isUnpausedAndRMNHealthy:test_RMN_Success() (gas: 73477)
Expand Down
45 changes: 13 additions & 32 deletions contracts/src/v0.8/ccip/test/capability/CCIPConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ contract CCIPConfigSetup is Test {
return subset;
}

//TODO: Use OZ's Arrays.sort when we upgrade to OZ v5
function _sort(bytes32[] memory arr, int256 left, int256 right) private pure {
int256 i = left;
int256 j = right;
if (i == j) return;
bytes32 pivot = arr[uint256(left + (right - left) / 2)];
while (i <= j) {
while (arr[uint256(i)] < pivot) i++;
while (pivot < arr[uint256(j)]) j--;
if (i <= j) {
(arr[uint256(i)], arr[uint256(j)]) = (arr[uint256(j)], arr[uint256(i)]);
i++;
j--;
}
}
if (left < j) _sort(arr, left, j);
if (i < right) _sort(arr, i, right);
}

function _addChainConfig(uint256 numNodes) internal returns (CCIPConfigTypes.OCR3Node[] memory nodes) {
return _addChainConfig(numNodes, 1);
}
Expand Down Expand Up @@ -533,21 +514,21 @@ contract CCIPConfig_validateConfig is CCIPConfigSetup {
s_ccipCC.validateConfig(config);
}

// TODO: rewrite test
// function test__validateConfig_P2PIdsLengthNotMatching_Reverts() public {
// CCIPConfigTypes.OCR3Config memory config = _getCorrectOCR3Config();
function test__validateConfig_ZeroP2PId_Reverts() public {
CCIPConfigTypes.OCR3Config memory config = _getCorrectOCR3Config();
config.nodes[1].p2pId = bytes32(0);

vm.expectRevert(abi.encodeWithSelector(CCIPConfig.InvalidNode.selector, config.nodes[1]));
s_ccipCC.validateConfig(config);
}

// uint256 expectedNumberOfP2pIds = config.signers.length;
// uint256 wrongNumberOfP2pIds = expectedNumberOfP2pIds - 1;
// config.p2pIds = new bytes32[](wrongNumberOfP2pIds); // Not enough
function test__validateConfig_ZeroSignerKey_Reverts() public {
CCIPConfigTypes.OCR3Config memory config = _getCorrectOCR3Config();
config.nodes[2].signerKey = bytes("");

// vm.expectRevert(
// abi.encodeWithSelector(
// CCIPConfig.P2PIdsLengthNotMatching.selector, wrongNumberOfP2pIds, expectedNumberOfP2pIds, expectedNumberOfP2pIds
// )
// );
// s_ccipCC.validateConfig(config);
// }
vm.expectRevert(abi.encodeWithSelector(CCIPConfig.InvalidNode.selector, config.nodes[2]));
s_ccipCC.validateConfig(config);
}

function test__validateConfig_NodeNotInRegistry_Reverts() public {
CCIPConfigTypes.OCR3Node[] memory nodes = _addChainConfig(4);
Expand Down
Loading

0 comments on commit 291f0fa

Please sign in to comment.