Skip to content

Commit 267acd3

Browse files
authored
fix: rely less on foundry internals (#473)
* fix: rely less on foundry internals * chore: update comments
1 parent 6d27cc0 commit 267acd3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/StdChains.sol

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,18 @@ abstract contract StdChains {
159159
} else {
160160
chain.rpcUrl = vm.envString(envName);
161161
}
162-
// distinguish 'not found' from 'cannot read'
163-
bytes memory notFoundError =
162+
// Distinguish 'not found' from 'cannot read'
163+
// The upstream error thrown by forge for failing cheats changed so we check both the old and new versions
164+
bytes memory oldNotFoundError =
164165
abi.encodeWithSignature("CheatCodeError", string(abi.encodePacked("invalid rpc url ", chainAlias)));
165-
if (keccak256(notFoundError) != keccak256(err) || bytes(chain.rpcUrl).length == 0) {
166+
bytes memory newNotFoundError = abi.encodeWithSignature(
167+
"CheatcodeError(string)", string(abi.encodePacked("invalid rpc url: ", chainAlias))
168+
);
169+
bytes32 errHash = keccak256(err);
170+
if (
171+
(errHash != keccak256(oldNotFoundError) && errHash != keccak256(newNotFoundError))
172+
|| bytes(chain.rpcUrl).length == 0
173+
) {
166174
/// @solidity memory-safe-assembly
167175
assembly {
168176
revert(add(32, err), mload(err))

test/StdChains.t.sol

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,9 @@ contract StdChainsTest is Test {
208208

209209
// Should error if default RPCs flag is set to false.
210210
stdChainsMock.exposed_setFallbackToDefaultRpcUrls(false);
211-
vm.expectRevert(
212-
"Failed to get environment variable `ANVIL_RPC_URL` as type `string`: environment variable not found"
213-
);
211+
vm.expectRevert();
214212
stdChainsMock.exposed_getChain(31337);
215-
vm.expectRevert(
216-
"Failed to get environment variable `SEPOLIA_RPC_URL` as type `string`: environment variable not found"
217-
);
213+
vm.expectRevert();
218214
stdChainsMock.exposed_getChain("sepolia");
219215
}
220216
}

0 commit comments

Comments
 (0)