Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ameeshaagrawal committed Jun 17, 2024
1 parent 40baacb commit 9f35b33
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 64 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 0 additions & 3 deletions contracts/ExecutionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 7 additions & 3 deletions test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
76 changes: 48 additions & 28 deletions test/managers/ExecutionManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "../Setup.t.sol";

contract ExecutionManagerTest is Setup {
ExecutionManager internal executionManager;

event FeesWithdrawn(address account_, uint256 value_);

function setUp() public {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}

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

Expand Down Expand Up @@ -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(
Expand All @@ -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;

Expand All @@ -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);

Expand All @@ -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(
Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion test/managers/OpenExecutionManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 2 additions & 28 deletions test/socket/SocketSrc.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract SocketSrcTest is Setup {
.executionManager__
.getExecutionTransmissionMinFees(
_minMsgGasLimit,
100,
1000,
bytes32(0),
_transmissionParams,
_b.chainSlug,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9f35b33

Please sign in to comment.