Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rely less on foundry internals #473

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/StdChains.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,18 @@ abstract contract StdChains {
} else {
chain.rpcUrl = vm.envString(envName);
}
// distinguish 'not found' from 'cannot read'
bytes memory notFoundError =
// Distinguish 'not found' from 'cannot read'
// The upstream error thrown by forge for failing cheats changed so we check both the old and new versions
bytes memory oldNotFoundError =
abi.encodeWithSignature("CheatCodeError", string(abi.encodePacked("invalid rpc url ", chainAlias)));
if (keccak256(notFoundError) != keccak256(err) || bytes(chain.rpcUrl).length == 0) {
bytes memory newNotFoundError = abi.encodeWithSignature(
"CheatcodeError(string)", string(abi.encodePacked("invalid rpc url: ", chainAlias))
);
bytes32 errHash = keccak256(err);
if (
(errHash != keccak256(oldNotFoundError) && errHash != keccak256(newNotFoundError))
|| bytes(chain.rpcUrl).length == 0
) {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, err), mload(err))
Expand Down
8 changes: 2 additions & 6 deletions test/StdChains.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,9 @@ contract StdChainsTest is Test {

// Should error if default RPCs flag is set to false.
stdChainsMock.exposed_setFallbackToDefaultRpcUrls(false);
vm.expectRevert(
"Failed to get environment variable `ANVIL_RPC_URL` as type `string`: environment variable not found"
);
vm.expectRevert();
stdChainsMock.exposed_getChain(31337);
vm.expectRevert(
"Failed to get environment variable `SEPOLIA_RPC_URL` as type `string`: environment variable not found"
);
vm.expectRevert();
stdChainsMock.exposed_getChain("sepolia");
}
}