Skip to content

Commit

Permalink
fix: rely less on foundry internals (#473)
Browse files Browse the repository at this point in the history
* fix: rely less on foundry internals

* chore: update comments
  • Loading branch information
DaniPopes authored Oct 31, 2023
1 parent 6d27cc0 commit 267acd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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");
}
}

0 comments on commit 267acd3

Please sign in to comment.