Skip to content

Commit

Permalink
fix: replace strings with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Feb 21, 2025
1 parent c8bb9fc commit 3975cc4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
32 changes: 24 additions & 8 deletions src/core/ImuachainGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,21 @@ contract ImuachainGateway is
string calldata oracleInfo,
uint128 tvlLimit
) external payable onlyOwner whenNotPaused nonReentrant {
require(clientChainId != 0, "ImuachainGateway: client chain id cannot be zero");
require(token != bytes32(0), "ImuachainGateway: token cannot be zero address");
require(bytes(name).length != 0, "ImuachainGateway: name cannot be empty");
require(bytes(metaData).length != 0, "ImuachainGateway: meta data cannot be empty");
require(bytes(oracleInfo).length != 0, "ImuachainGateway: oracleInfo cannot be empty");
if (clientChainId == 0) {
revert Errors.ZeroValue();
}
if (token == bytes32(0)) {
revert Errors.ZeroAddress();
}
if (bytes(name).length == 0) {
revert Errors.ZeroValue();
}
if (bytes(metaData).length == 0) {
revert Errors.ZeroValue();
}
if (bytes(oracleInfo).length == 0) {
revert Errors.ZeroValue();
}
// setting a TVL limit of 0 is permitted to simply add an inactive token, which may
// be activated later by updating the TVL limit on the client chain

Expand Down Expand Up @@ -212,9 +222,15 @@ contract ImuachainGateway is
whenNotPaused
nonReentrant
{
require(clientChainId != 0, "ImuachainGateway: client chain id cannot be zero");
require(token != bytes32(0), "ImuachainGateway: token cannot be zero address");
require(bytes(metaData).length != 0, "ImuachainGateway: meta data cannot be empty");
if (clientChainId == 0) {
revert Errors.ZeroValue();
}
if (token == bytes32(0)) {
revert Errors.ZeroAddress();
}
if (bytes(metaData).length == 0) {
revert Errors.ZeroValue();
}
bool success = ASSETS_CONTRACT.updateToken(clientChainId, abi.encodePacked(token), metaData);
if (success) {
emit WhitelistTokenUpdated(clientChainId, token);
Expand Down
6 changes: 3 additions & 3 deletions test/foundry/unit/ImuachainGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ contract AddWhitelistTokens is SetUp {

function test_RevertWhen_HasZeroAddressToken() public {
vm.startPrank(owner.addr);
vm.expectRevert("ImuachainGateway: token cannot be zero address");
vm.expectRevert(abi.encodeWithSelector(Errors.ZeroAddress.selector));
imuachainGateway.addWhitelistToken{value: nativeFee}(
clientChainId, bytes32(0), 18, "name", "metadata", "oracleInfo", 0
);
Expand Down Expand Up @@ -699,13 +699,13 @@ contract UpdateWhitelistTokens is SetUp {

function test_RevertUpdateWhen_HasZeroAddress() public {
vm.startPrank(owner.addr);
vm.expectRevert("ImuachainGateway: token cannot be zero address");
vm.expectRevert(abi.encodeWithSelector(Errors.ZeroAddress.selector));
imuachainGateway.updateWhitelistToken(clientChainId, bytes32(0), tokenDetails.metaData);
}

function test_RevertUpdateWhen_HasZeroChainId() public {
vm.startPrank(owner.addr);
vm.expectRevert("ImuachainGateway: client chain id cannot be zero");
vm.expectRevert(abi.encodeWithSelector(Errors.ZeroValue.selector));
imuachainGateway.updateWhitelistToken(0, tokenDetails.tokenAddress, tokenDetails.metaData);
}

Expand Down
32 changes: 24 additions & 8 deletions test/mocks/ImuachainGatewayMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,21 @@ contract ImuachainGatewayMock is
string calldata oracleInfo,
uint128 tvlLimit
) external payable onlyOwner whenNotPaused nonReentrant {
require(clientChainId != 0, "ImuachainGateway: client chain id cannot be zero");
require(token != bytes32(0), "ImuachainGateway: token cannot be zero address");
require(bytes(name).length != 0, "ImuachainGateway: name cannot be empty");
require(bytes(metaData).length != 0, "ImuachainGateway: meta data cannot be empty");
require(bytes(oracleInfo).length != 0, "ImuachainGateway: oracleInfo cannot be empty");
if (clientChainId == 0) {
revert Errors.ZeroValue();
}
if (token == bytes32(0)) {
revert Errors.ZeroAddress();
}
if (bytes(name).length == 0) {
revert Errors.ZeroValue();
}
if (bytes(metaData).length == 0) {
revert Errors.ZeroValue();
}
if (bytes(oracleInfo).length == 0) {
revert Errors.ZeroValue();
}
// setting a TVL limit of 0 is permitted to simply add an inactive token, which may
// be activated later by updating the TVL limit on the client chain

Expand Down Expand Up @@ -230,9 +240,15 @@ contract ImuachainGatewayMock is
whenNotPaused
nonReentrant
{
require(clientChainId != 0, "ImuachainGateway: client chain id cannot be zero");
require(token != bytes32(0), "ImuachainGateway: token cannot be zero address");
require(bytes(metaData).length != 0, "ImuachainGateway: meta data cannot be empty");
if (clientChainId == 0) {
revert Errors.ZeroValue();
}
if (token == bytes32(0)) {
revert Errors.ZeroAddress();
}
if (bytes(metaData).length == 0) {
revert Errors.ZeroValue();
}
bool success = ASSETS_CONTRACT.updateToken(clientChainId, abi.encodePacked(token), metaData);
if (success) {
emit WhitelistTokenUpdated(clientChainId, token);
Expand Down

0 comments on commit 3975cc4

Please sign in to comment.