Last active
February 13, 2024 05:11
-
-
Save PraneshASP/383758f5a31baea04e3c55d7b5f5c8da to your computer and use it in GitHub Desktop.
Using Mesc in foundry tests to avoid hardcoding urls.
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
// See Mesc Reference for setup: https://github.com/paradigmxyz/mesc/tree/main/cli#reference | |
contract TestSetup is Test { | |
function fetchRpcUrlFromMesc(string memory networkName) internal returns (string memory url) { | |
string[] memory inputs = new string[](3); | |
inputs[0] = "mesc"; | |
inputs[1] = "url"; | |
inputs[2] = networkName; | |
bytes memory res = vm.ffi(inputs); | |
url = string(res); | |
} | |
function setUp() public { | |
string memory network = "avax-c-chain"; | |
uint256 cchainForkId = vm.createSelectFork(fetchRpcUrlFromMesc(network), 41022344); | |
network = "eth-mainnet"; | |
uint256 mainnetForkId = vm.createSelectFork(fetchRpcUrlFromMesc(network), 19120056); | |
// Do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment