Skip to content

feat: superchainerc20 tests#5

Merged
0xDiscotech merged 11 commits intosuperc20from
feat/superchainerc20-tests
Jul 16, 2024
Merged

feat: superchainerc20 tests#5
0xDiscotech merged 11 commits intosuperc20from
feat/superchainerc20-tests

Conversation

@0xDiscotech
Copy link
Copy Markdown

CLOSES OPT-143

@0xDiscotech 0xDiscotech requested review from 0xng and hexshire July 15, 2024 16:44
@0xDiscotech 0xDiscotech self-assigned this Jul 15, 2024
@linear
Copy link
Copy Markdown

linear bot commented Jul 15, 2024

@0xDiscotech
Copy link
Copy Markdown
Author

Tried to stick to their testing standard. But I'm unsure if the testFuzz_mint_zeroAddressTo_reverts, testFuzz_burn_zeroAddressFrom_reverts and testFuzz_relayERC20_zeroAddressTo_reverts are needed since they're not Unit tests. But I've seen a similar behavior on other tests so I think it doesn't harm to keep them if we are in doubt.


// Mint some tokens to `_from` so then they can be burned
vm.prank(BRIDGE);
superchainERC20.mint(_from, _amount);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deal() didn't work here so I used the mint()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's okay. I'm not sure if deal increases the totalSupply, and the SuperchainERC20 tokens start with a totalSupply of 0. If you don't mint, the totalSupply would underflow. Either way, how did you attempt to use deal here, and with what error did it fail?

deal(address(SuperchainERC20), _from, _amount) didn't work?


// Mint some tokens to the sender so then they can be sent
vm.prank(BRIDGE);
superchainERC20.mint(_sender, _amount);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, deal() didn't work here so I used mint()

@0xng
Copy link
Copy Markdown
Member

0xng commented Jul 15, 2024

Tried to stick to their testing standard. But I'm unsure if the testFuzz_mint_zeroAddressTo_reverts, testFuzz_burn_zeroAddressFrom_reverts and testFuzz_relayERC20_zeroAddressTo_reverts are needed since they're not Unit tests. But I've seen a similar behavior on other tests so I think it doesn't harm to keep them if we are in doubt.

Let's leave them for now. They shouldn't be tested, as this is functionality incorporated by OZ, but as long as we use OZ it's ok to have them. If we switch to solady or solmate, we will need to remove it (plus they should fail if we do so)

vm.assume(_caller != BRIDGE);

// Expect the revert with `CallerNotBridge` selector
vm.expectRevert(abi.encodeWithSelector(CallerNotBridge.selector));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to encode it, should allow you to do vm.expectRevert(CallerNotBridge.selector);


// Call the `mint` function with the zero address
vm.prank(BRIDGE);
address _to = address(0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if there's a ZERO_ADDRESS constant, or create it otherwise and replace, you can probably do some:
``superchainERC20.mint({_to: ZERO_ADDRESS, _amount})` kind of thing to have it as a one liner


// Mint some tokens to `_from` so then they can be burned
vm.prank(BRIDGE);
superchainERC20.mint(_from, _amount);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's okay. I'm not sure if deal increases the totalSupply, and the SuperchainERC20 tokens start with a totalSupply of 0. If you don't mint, the totalSupply would underflow. Either way, how did you attempt to use deal here, and with what error did it fail?

deal(address(SuperchainERC20), _from, _amount) didn't work?

bytes memory _message = abi.encodeCall(superchainERC20.relayERC20, (_to, _amount));
_mockAndExpect(
MESSENGER,
abi.encodeWithSelector(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abi.encodeCall here would be tidier

// Expect the revert with `CallerNotBridge` selector
vm.expectRevert(abi.encodeWithSelector(RelayMessageCallerNotL2ToL2CrossDomainMessenger.selector));

// Call the `sendERC20` function with the non-messenger caller
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Call the `sendERC20` function with the non-messenger caller
// Call the `relayERC20` function with the non-messenger caller

// Ensure the caller is not the messenger
vm.assume(_caller != MESSENGER);

// Expect the revert with `CallerNotBridge` selector
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Expect the revert with `CallerNotBridge` selector
// Expect the revert with `RelayMesasgeCallerNotL2ToL2CrossDomainMessenger` selector

assertEq(superchainERC20.balanceOf(_sender), _senderBalanceBefore - _amount);
}

/// @dev Tests the `sendERC20` function reverts when the caller is not the bridge.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @dev Tests the `sendERC20` function reverts when the caller is not the bridge.
/// @dev Tests the `relayERC20` function reverts when the caller is not the L2ToL2CrossDomainMessenger.

@0xDiscotech
Copy link
Copy Markdown
Author

Tried to stick to their testing standard. But I'm unsure if the testFuzz_mint_zeroAddressTo_reverts, testFuzz_burn_zeroAddressFrom_reverts and testFuzz_relayERC20_zeroAddressTo_reverts are needed since they're not Unit tests. But I've seen a similar behavior on other tests so I think it doesn't harm to keep them if we are in doubt.

Let's leave them for now. They shouldn't be tested, as this is functionality incorporated by OZ, but as long as we use OZ it's ok to have them. If we switch to solady or solmate, we will need to remove it (plus they should fail if we do so)

Since this pov, I'm more inclined to removing those tests. But lmk which is your decision 👍

@0xDiscotech
Copy link
Copy Markdown
Author

deal(address(SuperchainERC20), _from, _amount) didn't work?

Yes, I tested using deal() in that way and the revert is bc of the underflow:
image

@0xDiscotech 0xDiscotech requested a review from 0xng July 15, 2024 18:13
}

/// @dev Tests the `burn` succeeds and emits the `Burn` event.
/// @dev Tests the `burn` bruns the amount and emits the `Burn` event.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

burns is mispelled here

// Mock the call over the `sendMessage` function and expect it to be called properly
_mockAndExpect(
MESSENGER,
abi.encodeWithSelector(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe i meant using abi.encodeCall instead of abi.encodeWithSelector not moving the message declaration within the body, but it's ok

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah jaja, will undo that and use abi.encodeCall then

@0xDiscotech 0xDiscotech requested a review from 0xng July 15, 2024 21:46
@0xDiscotech 0xDiscotech merged commit 6ff5ecb into superc20 Jul 16, 2024
@0xDiscotech 0xDiscotech deleted the feat/superchainerc20-tests branch July 16, 2024 16:19
0xOneTony pushed a commit that referenced this pull request Mar 6, 2026
…thereum-optimism#19272)

* contracts: implement audit code fixes and add tests

Add onlyDelegateCall enforcement to upgradeSuperchain, upgrade, and
migrate functions (#17). Include msg.sender in deploy salt to prevent
cross-caller CREATE2 collisions (#17). Add duplicate instruction key
detection in upgrade validation (#9). Validate startingRespectedGameType
against enabled game configs (#10). Add code-existence check in
loadBytes (#18). Add setUp guard to VerifyOPCM.runSingle (#4). Remove
unused _findChar function (#5). Pass real AddressManager in migrator
proxy deploy args (#11). Add tests covering all audit fix behaviors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* contracts: regenerate semver-lock.json for OPContractsManagerV2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* contracts: bump OPContractsManagerV2 version to 7.0.10

Semver-diff requires a patch version bump when bytecode changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants