Skip to content

Commit

Permalink
fix: SuperchainWETH fuzz testing chain ID error (ethereum-optimism#11352
Browse files Browse the repository at this point in the history
)

Minor fix to fuzz testing for SuperchainWETH and related contracts.
Recipient chain ID cannot be the same as the sending chain ID.
Contracts throw an error when this is the case, causing fuzz tests
to fail.
  • Loading branch information
smartcontracts authored Aug 5, 2024
1 parent e4c17d3 commit c14a8b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# `SuperchainWETH` Invariants

## Calls to sendERC20 should always succeed as long as the actor has less than uint248 wei which is much greater than the total ETH supply. Actor's balance should also not increase out of nowhere.
**Test:** [`SuperchainWETH.t.sol#L171`](../test/invariants/SuperchainWETH.t.sol#L171)
**Test:** [`SuperchainWETH.t.sol#L174`](../test/invariants/SuperchainWETH.t.sol#L174)

3 changes: 3 additions & 0 deletions packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ contract SuperchainWETH_Test is CommonTest {
public
{
// Assume
vm.assume(_chainId != block.chainid);
_amount = bound(_amount, 0, type(uint248).max - 1);

// Arrange
Expand Down Expand Up @@ -169,6 +170,7 @@ contract SuperchainWETH_Test is CommonTest {
/// @param _chainId The chain ID to send the WETH to.
function testFuzz_sendERC20_sufficientFromCustomGasTokenChain_succeeds(uint256 _amount, uint256 _chainId) public {
// Assume
vm.assume(_chainId != block.chainid);
_amount = bound(_amount, 0, type(uint248).max - 1);

// Arrange
Expand Down Expand Up @@ -204,6 +206,7 @@ contract SuperchainWETH_Test is CommonTest {
/// @param _chainId The chain ID to send the WETH to.
function testFuzz_sendERC20_insufficientBalance_fails(uint256 _amount, uint256 _chainId) public {
// Assume
vm.assume(_chainId != block.chainid);
_amount = bound(_amount, 0, type(uint248).max - 1);

// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ contract SuperchainWETH_User is StdUtils {
// Bound send amount to our WETH balance.
_amount = bound(_amount, 0, weth.balanceOf(address(this)));

// Prevent receiving chain ID from being the same as the current chain ID.
_chainId = _chainId == block.chainid ? _chainId + 1 : _chainId;

// Send the amount.
try weth.sendERC20(address(this), _amount, _chainId) {
// Success.
Expand Down

0 comments on commit c14a8b2

Please sign in to comment.