fix(cheatcode): expect revert only for calls with greater depth than test#9537
fix(cheatcode): expect revert only for calls with greater depth than test#9537grandizzy merged 7 commits intofoundry-rs:masterfrom
Conversation
dccc236 to
8a0ea49
Compare
8a0ea49 to
284b0fc
Compare
284b0fc to
93aec03
Compare
377735c to
df77c40
Compare
| assertEq(token.balanceOf(bob), 200); | ||
| } | ||
|
|
||
| /// forge-config: default.allow_internal_expect_revert = true |
There was a problem hiding this comment.
unrelated, pretty cool that this works
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
### 🕓 Changelog The Foundry PR [#9537](foundry-rs/foundry#9537) has disabled `expectRevert` for `internal` functions by default. However, we need this functionality in the `ECDSATest` contract since we use the `internal` function [`to2098Format`](https://github.com/pcaversaccio/snekmate/blob/9f75d9276251ccd03254e62c7b5581d776099d52/test/utils/ECDSA.t.sol#L37-L52) in various `expectRevert` test calls: ```solidity /** * @dev Transforms a standard signature into an EIP-2098 * compliant signature. * @param signature The secp256k1 64/65-bytes signature. * @return short The 64-bytes EIP-2098 compliant signature. */ function to2098Format( bytes memory signature ) internal view returns (bytes memory) { if (signature.length != 65) revert InvalidSignatureLength(self); // <-- We need to enable this `revert`. if (uint8(signature[32]) >> 7 == 1) revert InvalidSignatureSValue(self); // <-- We need to enable this `revert`. bytes memory short = signature.slice(0, 64); uint8 parityBit = uint8(short[32]) | ((uint8(signature[64]) % 27) << 7); short[32] = bytes1(parityBit); return short; } ``` This commit enables `expectRevert` for `internal` functions by setting `allow_internal_expect_revert = true` in the `foundry.toml` file. --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
|
Just spotted some test failures in MUD due to this change. (We intentionally use nightly in CI to make sure we're always ready for latest/upcoming foundry, to flag situations like this.) MUD makes extensive use of internal libraries and free functions, but it's sort of unclear if the test failures we're seeing are intended. Wanted to check in before we enable the For example, this failing test: Comes from a revert in this free function bound to a user type: Seems like any test that uses |
### 🕓 Changelog The Foundry PR [#9537](foundry-rs/foundry#9537) has disabled `expectRevert` for `internal` functions by default. However, we need this functionality in the `ECDSATest` contract since we use the `internal` function [`to2098Format`](https://github.com/pcaversaccio/snekmate/blob/9f75d9276251ccd03254e62c7b5581d776099d52/test/utils/ECDSA.t.sol#L37-L52) in various `expectRevert` test calls: ```solidity /** * @dev Transforms a standard signature into an EIP-2098 * compliant signature. * @param signature The secp256k1 64/65-bytes signature. * @return short The 64-bytes EIP-2098 compliant signature. */ function to2098Format( bytes memory signature ) internal view returns (bytes memory) { if (signature.length != 65) revert InvalidSignatureLength(self); // <-- We need to enable this `revert`. if (uint8(signature[32]) >> 7 == 1) revert InvalidSignatureSValue(self); // <-- We need to enable this `revert`. bytes memory short = signature.slice(0, 64); uint8 parityBit = uint8(short[32]) | ((uint8(signature[64]) % 27) << 7); short[32] = bytes1(parityBit); return short; } ``` This commit enables `expectRevert` for `internal` functions by setting `allow_internal_expect_revert = true` in the `foundry.toml` file. --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
### 🕓 Changelog The Foundry PR [#9537](foundry-rs/foundry#9537) has disabled `expectRevert` for `internal` functions by default. However, we need this functionality in the `ECDSATest` contract since we use the `internal` function [`to2098Format`](https://github.com/pcaversaccio/snekmate/blob/9f75d9276251ccd03254e62c7b5581d776099d52/test/utils/ECDSA.t.sol#L37-L52) in various `expectRevert` test calls: ```solidity /** * @dev Transforms a standard signature into an EIP-2098 * compliant signature. * @param signature The secp256k1 64/65-bytes signature. * @return short The 64-bytes EIP-2098 compliant signature. */ function to2098Format( bytes memory signature ) internal view returns (bytes memory) { if (signature.length != 65) revert InvalidSignatureLength(self); // <-- We need to enable this `revert`. if (uint8(signature[32]) >> 7 == 1) revert InvalidSignatureSValue(self); // <-- We need to enable this `revert`. bytes memory short = signature.slice(0, 64); uint8 parityBit = uint8(short[32]) | ((uint8(signature[64]) % 27) << 7); short[32] = bytes1(parityBit); return short; } ``` This commit enables `expectRevert` for `internal` functions by setting `allow_internal_expect_revert = true` in the `foundry.toml` file. --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Motivation
Closes #3723
Closes #7238
Closes #3437
Breaking change, should be merged after pinned version.
expectRevert, compares with test depth (at which cheatcode was added). Does not apply for_expectCheatcodeRevertcalls.allow_internal_expect_revertconfig to enable expect reverts for internal calls. defaults to falseSolution