diff --git a/lcov.info b/lcov.info index e6acc88..8a67463 100644 --- a/lcov.info +++ b/lcov.info @@ -464,45 +464,45 @@ end_of_record TN: SF:src/adapters/axelar/libraries/StringAddressConversion.sol FN:7,StringAddressConversion.toString -FNDA:14,StringAddressConversion.toString -DA:8,14 -DA:9,14 -DA:10,14 -DA:11,14 -DA:13,14 -DA:14,14 -DA:16,14 -DA:17,280 -DA:18,280 -DA:20,14 +FNDA:15,StringAddressConversion.toString +DA:8,15 +DA:9,15 +DA:10,15 +DA:11,15 +DA:13,15 +DA:14,15 +DA:16,15 +DA:17,300 +DA:18,300 +DA:20,15 FN:23,StringAddressConversion.toAddress -FNDA:0,StringAddressConversion.toAddress -DA:24,0 -DA:25,0 -DA:26,0 -DA:28,0 -BRDA:28,0,0,- -BRDA:28,0,1,- -DA:30,0 -DA:31,0 -DA:33,0 +FNDA:6,StringAddressConversion.toAddress +DA:24,6 +DA:25,6 +DA:26,6 +DA:28,6 +BRDA:28,0,0,4 +BRDA:28,0,1,2 +DA:30,2 +DA:31,79 +DA:33,79 BRDA:33,1,0,- -BRDA:33,1,1,- -DA:34,0 +BRDA:33,1,1,79 +DA:34,79 BRDA:34,2,0,- -BRDA:34,2,1,- -DA:35,0 -BRDA:35,3,0,- -BRDA:35,3,1,- -DA:36,0 -DA:38,0 -DA:40,0 +BRDA:34,2,1,79 +DA:35,79 +BRDA:35,3,0,78 +BRDA:35,3,1,1 +DA:36,1 +DA:38,78 +DA:40,1 FNF:2 -FNH:1 +FNH:2 LF:22 -LH:10 +LH:22 BRF:8 -BRH:0 +BRH:6 end_of_record TN: SF:src/adapters/wormhole/WormholeReceiverAdapter.sol @@ -744,22 +744,22 @@ end_of_record TN: SF:src/libraries/EIP5164/ExecutorAware.sol FN:34,ExecutorAware.isTrustedExecutor -FNDA:27,ExecutorAware.isTrustedExecutor -DA:35,70 +FNDA:29,ExecutorAware.isTrustedExecutor +DA:35,72 FN:42,ExecutorAware.getTrustedExecutors -FNDA:0,ExecutorAware.getTrustedExecutors -DA:43,1 +FNDA:1,ExecutorAware.getTrustedExecutors +DA:43,2 FN:50,ExecutorAware.trustedExecutorsCount -FNDA:0,ExecutorAware.trustedExecutorsCount -DA:51,28 +FNDA:1,ExecutorAware.trustedExecutorsCount +DA:51,29 FN:61,ExecutorAware._addTrustedExecutor -FNDA:22,ExecutorAware._addTrustedExecutor -DA:62,22 +FNDA:28,ExecutorAware._addTrustedExecutor +DA:62,28 FN:70,ExecutorAware._removeTrustedExecutor -FNDA:9,ExecutorAware._removeTrustedExecutor -DA:71,9 +FNDA:10,ExecutorAware._removeTrustedExecutor +DA:71,10 FNF:5 -FNH:3 +FNH:5 LF:5 LH:5 BRF:0 @@ -768,36 +768,36 @@ end_of_record TN: SF:src/libraries/Message.sol FN:41,MessageLibrary.computeMsgId -FNDA:14,MessageLibrary.computeMsgId -DA:42,14 +FNDA:15,MessageLibrary.computeMsgId +DA:42,15 FN:55,MessageLibrary.extractExecutionParams -FNDA:0,MessageLibrary.extractExecutionParams -DA:56,0 +FNDA:2,MessageLibrary.extractExecutionParams +DA:56,2 FN:65,MessageLibrary.computeExecutionParamsHash -FNDA:0,MessageLibrary.computeExecutionParamsHash -DA:66,0 +FNDA:2,MessageLibrary.computeExecutionParamsHash +DA:66,2 FN:71,MessageLibrary.computeExecutionParamsHash -FNDA:0,MessageLibrary.computeExecutionParamsHash -DA:72,0 +FNDA:1,MessageLibrary.computeExecutionParamsHash +DA:72,1 FNF:4 -FNH:1 +FNH:4 LF:4 -LH:1 +LH:4 BRF:0 BRH:0 end_of_record TN: SF:src/libraries/TypeCasts.sol FN:7,TypeCasts.addressToBytes32 -FNDA:0,TypeCasts.addressToBytes32 -DA:8,0 +FNDA:1,TypeCasts.addressToBytes32 +DA:8,1 FN:12,TypeCasts.bytes32ToAddress -FNDA:16,TypeCasts.bytes32ToAddress -DA:13,16 +FNDA:17,TypeCasts.bytes32ToAddress +DA:13,17 FNF:2 -FNH:1 +FNH:2 LF:2 -LH:1 +LH:2 BRF:0 BRH:0 end_of_record @@ -1138,3 +1138,69 @@ LH:1 BRF:0 BRH:0 end_of_record +TN: +SF:test/unit-tests/adapters/axelar/libraries/StringAddressConversion.t.sol +FN:12,StringAddressConversionHelper.toString +FNDA:1,StringAddressConversionHelper.toString +DA:13,1 +FN:16,StringAddressConversionHelper.toAddress +FNDA:6,StringAddressConversionHelper.toAddress +DA:17,6 +FNF:2 +FNH:2 +LF:2 +LH:2 +BRF:0 +BRH:0 +end_of_record +TN: +SF:test/unit-tests/libraries/EIP5164/ExecutorAware.t.sol +FN:12,ExecutorAwareHelper.addTrustedExecutor +FNDA:6,ExecutorAwareHelper.addTrustedExecutor +DA:13,6 +FN:16,ExecutorAwareHelper.removeTrustedExecutor +FNDA:1,ExecutorAwareHelper.removeTrustedExecutor +DA:17,1 +FNF:2 +FNH:2 +LF:2 +LH:2 +BRF:0 +BRH:0 +end_of_record +TN: +SF:test/unit-tests/libraries/Message.t.sol +FN:14,MessageHelper.computeMsgId +FNDA:1,MessageHelper.computeMsgId +DA:15,1 +FN:18,MessageHelper.extractExecutionParams +FNDA:1,MessageHelper.extractExecutionParams +DA:23,1 +FN:26,MessageHelper.computeExecutionParamsHash +FNDA:1,MessageHelper.computeExecutionParamsHash +DA:31,1 +FN:34,MessageHelper.computeExecutionParamsHashFromMessage +FNDA:1,MessageHelper.computeExecutionParamsHashFromMessage +DA:39,1 +FNF:4 +FNH:4 +LF:4 +LH:4 +BRF:0 +BRH:0 +end_of_record +TN: +SF:test/unit-tests/libraries/TypeCasts.t.sol +FN:12,TypeCastsHelper.addressToBytes32 +FNDA:1,TypeCastsHelper.addressToBytes32 +DA:13,1 +FN:16,TypeCastsHelper.bytes32ToAddress +FNDA:1,TypeCastsHelper.bytes32ToAddress +DA:17,1 +FNF:2 +FNH:2 +LF:2 +LH:2 +BRF:0 +BRH:0 +end_of_record diff --git a/test/unit-tests/adapters/axelar/libraries/StringAddressConversion.t.sol b/test/unit-tests/adapters/axelar/libraries/StringAddressConversion.t.sol new file mode 100644 index 0000000..19ca2b1 --- /dev/null +++ b/test/unit-tests/adapters/axelar/libraries/StringAddressConversion.t.sol @@ -0,0 +1,99 @@ +// 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 +contract StringAddressConversionHelper { + 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 { + StringAddressConversionHelper public conversionHelper; + + /*/////////////////////////////////////////////////////////////// + SETUP + //////////////////////////////////////////////////////////////*/ + function setUp() public { + conversionHelper = new StringAddressConversionHelper(); + } + + /*/////////////////////////////////////////////////////////////// + TEST CASES + //////////////////////////////////////////////////////////////*/ + + /// @dev tests conversion of address to string + function testToString() public { + address testAddr = address(0x1234567890123456789012345678901234567890); + string memory result = conversionHelper.toString(testAddr); + string memory expected = "0x1234567890123456789012345678901234567890"; + + assertTrue( + keccak256(bytes(result)) == keccak256(bytes(expected)), "Converted string does not match expected value" + ); + } + + /// @dev tests conversion of string to address + function testToAddress() public { + string memory testString = "0x1234567890123456789012345678901234567890"; + address result = conversionHelper.toAddress(testString); + address expected = address(0x1234567890123456789012345678901234567890); + + assertTrue(result == expected, "Converted address does not match expected value"); + } + + /// @dev tests invalid address conversion + function testInvalidAddressStringConversion() public { + string memory invalidAddressString = "1234567890123456789012345678901234567892"; + + bytes4 selector = bytes4(keccak256(bytes("InvalidAddressString()"))); + vm.expectRevert(selector); + conversionHelper.toAddress(invalidAddressString); + } + + /// @dev tests short address string + function testShortAddressStringConversion() public { + string memory shortAddressString = "0x12345678901234567890123456789012345678"; + + bytes4 selector = bytes4(keccak256(bytes("InvalidAddressString()"))); + vm.expectRevert(selector); + conversionHelper.toAddress(shortAddressString); + } + + /// @dev tests long address string + function testLongAddressStringConversion() public { + string memory longAddressString = "0x123456789012345678901234567890123456789012"; + + bytes4 selector = bytes4(keccak256(bytes("InvalidAddressString()"))); + vm.expectRevert(selector); + conversionHelper.toAddress(longAddressString); + } + + /// @dev tests invalid prefix in address string + function testInvalidPrefixAddressStringConversion() public { + string memory invalidPrefixAddressString = "1x1234567890123456789012345678901234567890"; + + bytes4 selector = bytes4(keccak256(bytes("InvalidAddressString()"))); + vm.expectRevert(selector); + conversionHelper.toAddress(invalidPrefixAddressString); + } + + /// @dev tests address string with invalid characters + function testInvalidCharacterAddressStringConversion() public { + string memory invalidCharacterAddressString = "0x12345678901234567890123456789012345678g0"; // 'g' is an invalid character + + bytes4 selector = bytes4(keccak256(bytes("InvalidAddressString()"))); + vm.expectRevert(selector); + conversionHelper.toAddress(invalidCharacterAddressString); + } +} diff --git a/test/unit-tests/libraries/EIP5164/ExecutorAware.t.sol b/test/unit-tests/libraries/EIP5164/ExecutorAware.t.sol new file mode 100644 index 0000000..d98e9cc --- /dev/null +++ b/test/unit-tests/libraries/EIP5164/ExecutorAware.t.sol @@ -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 ExecutorAwareHelper 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 { + ExecutorAwareHelper public executorAware; + + /*/////////////////////////////////////////////////////////////// + SETUP + //////////////////////////////////////////////////////////////*/ + function setUp() public { + executorAware = new ExecutorAwareHelper(); + } + + /*/////////////////////////////////////////////////////////////// + TEST CASES + //////////////////////////////////////////////////////////////*/ + + /// @dev tests adding a trusted executor + function testAddTrustedExecutor() public { + address executor = address(0x1234567890123456789012345678901234567890); + bool added = executorAware.addTrustedExecutor(executor); + + assertTrue(added, "Executor should be added successfully"); + assertTrue(executorAware.isTrustedExecutor(executor), "Executor should be trusted after addition"); + } + + /// @dev tests removing a trusted executor + function testRemoveTrustedExecutor() public { + address executor = address(0x1234567890123456789012345678901234567890); + executorAware.addTrustedExecutor(executor); + + bool removed = executorAware.removeTrustedExecutor(executor); + + assertTrue(removed, "Executor should be removed successfully"); + assertFalse(executorAware.isTrustedExecutor(executor), "Executor should no longer be trusted after removal"); + } + + /// @dev tests retrieval of trusted executors + function testGetTrustedExecutors() public { + address executor1 = address(420); + address executor2 = address(421); + executorAware.addTrustedExecutor(executor1); + executorAware.addTrustedExecutor(executor2); + + address[] memory executors = executorAware.getTrustedExecutors(); + + assertTrue(executors.length == 2, "There should be two trusted executors"); + assertTrue(executors[0] == executor1 || executors[1] == executor1, "Executor1 should be in the returned list"); + assertTrue(executors[0] == executor2 || executors[1] == executor2, "Executor2 should be in the returned list"); + } + + /// @dev tests counting the number of trusted executors + function testTrustedExecutorsCount() public { + address executor1 = address(420); + address executor2 = address(421); + executorAware.addTrustedExecutor(executor1); + executorAware.addTrustedExecutor(executor2); + + uint256 count = executorAware.trustedExecutorsCount(); + + assertTrue(count == 2, "There should be two trusted executors"); + } +}