-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bring code coverage to 100% (#106)
* chore: add unit test multimessage receiver * chore: bring libraries to 100% coverage * feat: bring all libraries to 100% coverage * feat: bring branch coverage for string lib to 100% * chore: added more unit tests * chore: change to assertEq * tests: add reverting refund address tests * revert: remove lcov.info * fix: pr comments * fix: run forge fmt
- Loading branch information
1 parent
16698c6
commit dcaa8b8
Showing
6 changed files
with
535 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
test/unit-tests/adapters/axelar/libraries/StringAddressConversion.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity >=0.8.9; | ||
|
||
/// library imports | ||
import {Test, Vm} from "forge-std/Test.sol"; | ||
|
||
/// local imports | ||
import "src/adapters/axelar/libraries/StringAddressConversion.sol"; | ||
|
||
/// @dev helper for testing StringAddressConversion library | ||
/// @dev library testing using foundry can only be done through helper contracts | ||
/// @dev see https://github.com/foundry-rs/foundry/issues/2567 | ||
contract StringAddressConversionTestClient { | ||
function toString(address _addr) external pure returns (string memory) { | ||
return StringAddressConversion.toString(_addr); | ||
} | ||
|
||
function toAddress(string calldata _addressString) external pure returns (address) { | ||
return StringAddressConversion.toAddress(_addressString); | ||
} | ||
} | ||
|
||
contract StringAddressConversionTest is Test { | ||
StringAddressConversionTestClient public conversionHelper; | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
SETUP | ||
//////////////////////////////////////////////////////////////*/ | ||
function setUp() public { | ||
conversionHelper = new StringAddressConversionTestClient(); | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
TEST CASES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev tests conversion of address to string | ||
function test_to_string() public { | ||
address testAddr = address(0x1234567890123456789012345678901234567890); | ||
string memory result = conversionHelper.toString(testAddr); | ||
string memory expected = "0x1234567890123456789012345678901234567890"; | ||
|
||
assertEq(keccak256(bytes(result)), keccak256(bytes(expected))); | ||
} | ||
|
||
/// @dev tests conversion of string to address | ||
function test_to_address() public { | ||
string memory testString = "0x1234567890123456789012345678901234567890"; | ||
address result = conversionHelper.toAddress(testString); | ||
address expected = address(0x1234567890123456789012345678901234567890); | ||
|
||
assertEq(result, expected); | ||
} | ||
|
||
/// @dev tests invalid address conversion | ||
function test_invalid_address_string_conversion() public { | ||
string memory invalidAddressString = "1234567890123456789012345678901234567892"; | ||
|
||
bytes4 selector = StringAddressConversion.InvalidAddressString.selector; | ||
vm.expectRevert(selector); | ||
conversionHelper.toAddress(invalidAddressString); | ||
} | ||
|
||
/// @dev tests short address string | ||
function test_short_address_string_conversion() public { | ||
string memory shortAddressString = "0x12345678901234567890123456789012345678"; | ||
|
||
bytes4 selector = StringAddressConversion.InvalidAddressString.selector; | ||
vm.expectRevert(selector); | ||
conversionHelper.toAddress(shortAddressString); | ||
} | ||
|
||
/// @dev tests long address string | ||
function test_long_address_string_conversion() public { | ||
string memory longAddressString = "0x123456789012345678901234567890123456789012"; | ||
|
||
bytes4 selector = StringAddressConversion.InvalidAddressString.selector; | ||
vm.expectRevert(selector); | ||
conversionHelper.toAddress(longAddressString); | ||
} | ||
|
||
/// @dev tests invalid prefix in address string | ||
function test_invalid_prefix_address_string_conversion() public { | ||
string memory invalidPrefixAddressString = "1x1234567890123456789012345678901234567890"; | ||
|
||
bytes4 selector = StringAddressConversion.InvalidAddressString.selector; | ||
vm.expectRevert(selector); | ||
conversionHelper.toAddress(invalidPrefixAddressString); | ||
} | ||
|
||
/// @dev tests address string with invalid characters | ||
function test_invalid_character_address_string_conversion() public { | ||
string memory invalidCharacterAddressString = "0x12345678901234567890123456789012345678g0"; // 'g' is an invalid character | ||
|
||
bytes4 selector = StringAddressConversion.InvalidAddressString.selector; | ||
vm.expectRevert(selector); | ||
conversionHelper.toAddress(invalidCharacterAddressString); | ||
} | ||
|
||
/// @dev tests conversion of string with lowercase hex characters to address | ||
function test_lowercase_hex_character_to_address() public { | ||
string memory testString = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"; | ||
address result = conversionHelper.toAddress(testString); | ||
address expected = address(0xABcdEFABcdEFabcdEfAbCdefabcdeFABcDEFabCD); | ||
|
||
assertEq(result, expected); | ||
} | ||
|
||
/// @dev tests conversion of string with uppercase hex characters to address | ||
function test_ppercase_hex_character_to_address() public { | ||
string memory testString = "0xABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCD"; | ||
address result = conversionHelper.toAddress(testString); | ||
address expected = address(0xABcdEFABcdEFabcdEfAbCdefabcdeFABcDEFabCD); | ||
|
||
assertEq(result, expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity >=0.8.9; | ||
|
||
/// library imports | ||
import {Test, Vm} from "forge-std/Test.sol"; | ||
|
||
/// local imports | ||
import "src/libraries/EIP5164/ExecutorAware.sol"; | ||
|
||
/// @dev helper to test abstract contract | ||
contract ExecutorAwareTestClient is ExecutorAware { | ||
function addTrustedExecutor(address _executor) external returns (bool) { | ||
return _addTrustedExecutor(_executor); | ||
} | ||
|
||
function removeTrustedExecutor(address _executor) external returns (bool) { | ||
return _removeTrustedExecutor(_executor); | ||
} | ||
} | ||
|
||
contract ExecutorAwareTest is Test { | ||
ExecutorAwareTestClient public executorAware; | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
SETUP | ||
//////////////////////////////////////////////////////////////*/ | ||
function setUp() public { | ||
executorAware = new ExecutorAwareTestClient(); | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
TEST CASES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev tests adding a trusted executor | ||
function test_add_trusted_executor() public { | ||
address executor = address(0x1234567890123456789012345678901234567890); | ||
bool added = executorAware.addTrustedExecutor(executor); | ||
|
||
assertEq(added, true); | ||
assertEq(executorAware.isTrustedExecutor(executor), true); | ||
} | ||
|
||
/// @dev tests removing a trusted executor | ||
function test_remove_trusted_executor() public { | ||
address executor = address(0x1234567890123456789012345678901234567890); | ||
executorAware.addTrustedExecutor(executor); | ||
|
||
bool removed = executorAware.removeTrustedExecutor(executor); | ||
|
||
assertEq(removed, true); | ||
assertEq(executorAware.isTrustedExecutor(executor), false); | ||
} | ||
|
||
/// @dev tests retrieval of trusted executors | ||
function test_get_trusted_executors() public { | ||
address executor1 = address(420); | ||
address executor2 = address(421); | ||
executorAware.addTrustedExecutor(executor1); | ||
executorAware.addTrustedExecutor(executor2); | ||
|
||
address[] memory executors = executorAware.getTrustedExecutors(); | ||
|
||
assertEq(executors.length == 2, true); | ||
assertEq(executors[0], executor1); | ||
assertEq(executors[1], executor2); | ||
} | ||
|
||
/// @dev tests counting the number of trusted executors | ||
function test_trusted_executors_count() public { | ||
address executor1 = address(420); | ||
address executor2 = address(421); | ||
executorAware.addTrustedExecutor(executor1); | ||
executorAware.addTrustedExecutor(executor2); | ||
|
||
uint256 count = executorAware.trustedExecutorsCount(); | ||
|
||
assertEq(count, 2); | ||
} | ||
} |
Oops, something went wrong.