Skip to content

Commit

Permalink
Add explicit test for _getMappedChainId()
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 committed Nov 12, 2024
1 parent c8de86d commit 291d0a7
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/solidity/Facets/RelayFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ contract TestRelayFacet is RelayFacet {
function setFunctionApprovalBySignature(bytes4 _signature) external {
LibAllowList.addAllowedSelector(_signature);
}

function getMappedChainId(
uint256 chainId
) external pure returns (uint256) {
return _getMappedChainId(chainId);
}
}

contract RelayFacetTest is TestBaseFacet {
Expand All @@ -41,7 +47,7 @@ contract RelayFacetTest is TestBaseFacet {
customBlockNumberForForking = 19767662;
initTestBase();
relayFacet = new TestRelayFacet(RELAY_RECEIVER, RELAY_SOLVER);
bytes4[] memory functionSelectors = new bytes4[](4);
bytes4[] memory functionSelectors = new bytes4[](5);
functionSelectors[0] = relayFacet.startBridgeTokensViaRelay.selector;
functionSelectors[1] = relayFacet
.swapAndStartBridgeTokensViaRelay
Expand All @@ -50,6 +56,7 @@ contract RelayFacetTest is TestBaseFacet {
functionSelectors[3] = relayFacet
.setFunctionApprovalBySignature
.selector;
functionSelectors[4] = relayFacet.getMappedChainId.selector;

addFacet(diamond, address(relayFacet), functionSelectors);
relayFacet = TestRelayFacet(address(diamond));
Expand Down Expand Up @@ -642,6 +649,23 @@ contract RelayFacetTest is TestBaseFacet {
vm.stopPrank();
}

function test_mapsCorrectChainId(uint256 chainId) public {
uint256 mapped = relayFacet.getMappedChainId(chainId);
// Bitcoin
if (chainId == 20000000000001) {
assertEq(mapped, 8253038);
return;
}

// Solana
if (chainId == 1151111081099710) {
assertEq(mapped, 792703809);
return;
}

assertEq(mapped, chainId);
}

function signData(
ILiFi.BridgeData memory _bridgeData,
RelayFacet.RelayData memory _relayData
Expand Down

0 comments on commit 291d0a7

Please sign in to comment.