Skip to content

Instantly share code, notes, and snippets.

@PraneshASP
Last active February 13, 2024 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PraneshASP/383758f5a31baea04e3c55d7b5f5c8da to your computer and use it in GitHub Desktop.
Save PraneshASP/383758f5a31baea04e3c55d7b5f5c8da to your computer and use it in GitHub Desktop.
Using Mesc in foundry tests to avoid hardcoding urls.
// 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