From 9f35b33ce035d82a75c0e08edd6249f6284dbc76 Mon Sep 17 00:00:00 2001 From: Ameesha Agrawal Date: Mon, 17 Jun 2024 20:45:44 +0530 Subject: [PATCH] fix: tests --- README.md | 1 - contracts/ExecutionManager.sol | 3 - test/Setup.t.sol | 10 +++- test/managers/ExecutionManager.t.sol | 76 +++++++++++++++--------- test/managers/OpenExecutionManager.t.sol | 1 - test/socket/SocketSrc.t.sol | 30 +--------- 6 files changed, 57 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 644dd0032..f6003d508 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,6 @@ It is recommended to setup the ide to work with solidity development. In case of | InvalidNonce() | 0x756688fe | | MsgValueTooLow() | 0x508aaf00 | | MsgValueTooHigh() | 0x5dffc92f | -| PayloadTooLarge() | 0x492f620d | | InsufficientMsgValue() | 0x78f38f76 | | InsufficientFees() | 0x8d53e553 | | InvalidMsgValue() | 0x1841b4e1 | diff --git a/contracts/ExecutionManager.sol b/contracts/ExecutionManager.sol index c5004a3c1..e0691e12f 100644 --- a/contracts/ExecutionManager.sol +++ b/contracts/ExecutionManager.sol @@ -141,9 +141,6 @@ contract ExecutionManager is IExecutionManager, AccessControlExtended { // triggered when msg value more than max threshold error MsgValueTooHigh(); - // triggered when payload is larger than expected limit - error PayloadTooLarge(); - // triggered when msg value is not enough error InsufficientMsgValue(); diff --git a/test/Setup.t.sol b/test/Setup.t.sol index 2c5fd94a2..d77746931 100644 --- a/test/Setup.t.sol +++ b/test/Setup.t.sol @@ -85,6 +85,10 @@ contract Setup is Test { uint256 internal _capacitorType = 1; uint256 internal constant DEFAULT_BATCH_LENGTH = 1; + uint80 internal gasPrice = 1 gwei; + uint80 internal perByteCost = 50 gwei; + uint80 internal overhead = 10 gwei; + bytes32 internal _transmissionParams = bytes32(0); bool isExecutionOpen = false; @@ -211,9 +215,9 @@ contract Setup is Test { IExecutionManager.ExecutionFeesParam memory executionFees = IExecutionManager.ExecutionFeesParam( - type(uint80).max, - type(uint80).max, - type(uint80).max + gasPrice, + perByteCost, + overhead ); _setExecutionFees(cc_, remoteChainSlug_, executionFees); _setMsgValueMaxThreshold(cc_, remoteChainSlug_, _msgValueMaxThreshold); diff --git a/test/managers/ExecutionManager.t.sol b/test/managers/ExecutionManager.t.sol index 7fde3cb2c..4d80e4c7f 100644 --- a/test/managers/ExecutionManager.t.sol +++ b/test/managers/ExecutionManager.t.sol @@ -5,7 +5,6 @@ import "../Setup.t.sol"; contract ExecutionManagerTest is Setup { ExecutionManager internal executionManager; - event FeesWithdrawn(address account_, uint256 value_); function setUp() public { @@ -53,8 +52,14 @@ contract ExecutionManagerTest is Setup { bChainSlug ); + uint256 executionFees = minMsgGasLimit * + gasPrice + + overhead + + payloadSize * + perByteCost; + //assert actual and expected data - assertEq(minFees, _executionFees); + assertEq(minFees, executionFees); } function testGetTransmissionExecutionFees() public { @@ -73,7 +78,14 @@ contract ExecutionManagerTest is Setup { ); //assert actual and expected data - assertEq(executionFees, _executionFees); + + uint256 executionFeesCalc = minMsgGasLimit * + gasPrice + + overhead + + payloadSize * + perByteCost; + + assertEq(executionFees, executionFeesCalc); assertEq(transmissionFees, _transmissionFees); } @@ -140,25 +152,15 @@ contract ExecutionManagerTest is Setup { bChainSlug ); + uint256 executionFeesCalc = minMsgGasLimit * + gasPrice + + overhead + + payloadSize * + perByteCost; + assertEq( minFees, - _executionFees + (msgValue * _relativeNativeTokenPrice) / 1e18 - ); - } - - function testGetMinFeesWithPayloadTooLong() public { - uint256 minMsgGasLimit = 100000; - uint256 payloadSize = 10000; - bytes32 executionParams = bytes32( - uint256((uint256(1) << 224) | uint224(100)) - ); - - vm.expectRevert(ExecutionManager.PayloadTooLarge.selector); - executionManager.getMinFees( - minMsgGasLimit, - payloadSize, - executionParams, - bChainSlug + executionFeesCalc + (msgValue * _relativeNativeTokenPrice) / 1e18 ); } @@ -208,10 +210,16 @@ contract ExecutionManagerTest is Setup { uint128 storedTransmissionFees ) = executionManager.totalExecutionAndTransmissionFees(bChainSlug); + uint256 executionFeesCalc = minMsgGasLimit * + gasPrice + + overhead + + payloadSize * + perByteCost; + assertEq(storedTransmissionFees, _transmissionFees); assertEq( storedExecutionFees, - _executionFees + _verificationOverheadFees + executionFeesCalc + _verificationOverheadFees ); assertEq( executionManager.totalSwitchboardFees( @@ -227,8 +235,14 @@ contract ExecutionManagerTest is Setup { uint256 payloadSize = 1000; bytes32 executionParams = bytes32(0); + uint256 executionFeesCalc = minMsgGasLimit * + gasPrice + + overhead + + payloadSize * + perByteCost; + uint256 totalFees = _transmissionFees + - _executionFees + + executionFeesCalc + type(uint128).max + //_switchboardFees _verificationOverheadFees; @@ -253,9 +267,9 @@ contract ExecutionManagerTest is Setup { IExecutionManager.ExecutionFeesParam memory executionFees = IExecutionManager.ExecutionFeesParam( - type(uint80).max, - type(uint80).max, - type(uint80).max + gasPrice, + perByteCost, + overhead ); _setExecutionFees(_a, _b.chainSlug, executionFees); @@ -278,9 +292,9 @@ contract ExecutionManagerTest is Setup { ); } - function testPayAndCheckFeesWithExecutionFeeSetTooHigh() public { + function testPayAndCheckFeesWithExecutionFeeTooHigh() public { uint256 minMsgGasLimit = 100000; - uint256 payloadSize = 1000; + uint256 payloadSize = type(uint128).max; uint256 msgValue = 1000; uint8 paramType = 1; bytes32 executionParams = bytes32( @@ -446,8 +460,14 @@ contract ExecutionManagerTest is Setup { uint256 payloadSize = 1000; bytes32 executionParams = bytes32(0); + uint256 executionFeesCalc = minMsgGasLimit * + gasPrice + + overhead + + payloadSize * + perByteCost; + uint256 totalFees = _transmissionFees + - _executionFees + + executionFeesCalc + _switchboardFees + _verificationOverheadFees; diff --git a/test/managers/OpenExecutionManager.t.sol b/test/managers/OpenExecutionManager.t.sol index 8fcb82995..127fdf36a 100644 --- a/test/managers/OpenExecutionManager.t.sol +++ b/test/managers/OpenExecutionManager.t.sol @@ -10,7 +10,6 @@ contract OpenExecutionManagerTest is Setup { event FeesWithdrawn(address account_, uint256 value_); error MsgValueTooLow(); error MsgValueTooHigh(); - error PayloadTooLarge(); error InsufficientMsgValue(); function setUp() public { diff --git a/test/socket/SocketSrc.t.sol b/test/socket/SocketSrc.t.sol index 156e69ff4..c0e6ce6be 100644 --- a/test/socket/SocketSrc.t.sol +++ b/test/socket/SocketSrc.t.sol @@ -146,7 +146,7 @@ contract SocketSrcTest is Setup { .executionManager__ .getExecutionTransmissionMinFees( _minMsgGasLimit, - 100, + 1000, bytes32(0), _transmissionParams, _b.chainSlug, @@ -171,18 +171,6 @@ contract SocketSrcTest is Setup { } // revert on wrong inputs - - // wrong payload size - vm.expectRevert(ExecutionManager.PayloadTooLarge.selector); - _a.socket__.getMinFees( - _minMsgGasLimit, - 4000, - bytes32(0), - _transmissionParams, - _b.chainSlug, - address(srcCounter__) - ); - // wrong sibling slug, revert because capacitor is address(0) vm.expectRevert(); _a.socket__.getMinFees( @@ -213,22 +201,8 @@ contract SocketSrcTest is Setup { executionParams = bytes32( uint256((uint256(1) << 248) | uint248(msgValue)) ); - vm.expectRevert(ExecutionManager.MsgValueTooLow.selector); - _a.socket__.getMinFees( - _minMsgGasLimit, - 1000, - executionParams, - _transmissionParams, - _b.chainSlug, - address(srcCounter__) - ); - // Revert if msg.value is greater than the maximum uint128 value. - msgValue = type(uint136).max; - executionParams = bytes32( - uint256((uint256(1) << 248) | uint248(msgValue)) - ); - vm.expectRevert(); + vm.expectRevert(ExecutionManager.MsgValueTooLow.selector); _a.socket__.getMinFees( _minMsgGasLimit, 1000,