Skip to content

Commit

Permalink
fix: adding sanity check tests to OptimismSuperchainERC20 and fixing …
Browse files Browse the repository at this point in the history
…error in allowance override
  • Loading branch information
0xng committed Sep 18, 2024
1 parent 5c6a124 commit beabbc5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"sourceCodeHash": "0x4b806cc85cead74c8df34ab08f4b6c6a95a1a387a335ec8a7cb2de4ea4e1cf41"
},
"src/L2/OptimismSuperchainERC20.sol": {
"initCodeHash": "0x362f5ee610df9ba99bf2ae5e6a96abace8ac8eb62d7a3433037525818cf13de0",
"initCodeHash": "0xa812d6c13a02e560864a023f0bc9696065f426aa95b8558e01925b164400d11c",
"sourceCodeHash": "0xad3934ea533544b3c130c80be26201354af85f9166cb2ce54d96e5e383ebb5c1"
},
"src/L2/OptimismSuperchainERC20Beacon.sol": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/src/L2/SuperchainERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract contract SuperchainERC20 is ISuperchainERC20Extensions, ISuperchainERC2
/// @return result Allowance for the spender.
function allowance(address owner, address spender) public view virtual override returns (uint256 result) {
if (spender == PERMIT2()) {
result = type(uint256).max;
return type(uint256).max;
}
result = super.allowance(owner, spender);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts-bedrock/test/L2/OptimismSuperchainERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ contract OptimismSuperchainERC20Test is Test {
assertEq(superchainERC20.balanceOf(_to), _toBalanceBefore + _amount);
}

function testFuzz_allowance_permit2_max(address _owner) external view {
assertEq(superchainERC20.allowance(_owner, superchainERC20.PERMIT2()), type(uint256).max);
}

function testFuzz_permit2_transferFrom(address _owner, address _receiver, uint256 _amount) external {
vm.assume(_owner != _receiver);
vm.assume(_owner != ZERO_ADDRESS);
vm.prank(BRIDGE);
superchainERC20.mint(_owner, _amount);

assertEq(superchainERC20.balanceOf(_receiver), 0);
vm.prank(superchainERC20.PERMIT2());
superchainERC20.transferFrom(_owner, _receiver, _amount);
assertEq(superchainERC20.balanceOf(_receiver), _amount);
}

/// @notice Tests the `decimals` function always returns the correct value.
function testFuzz_decimals_succeeds(uint8 _decimals) public {
OptimismSuperchainERC20 _newSuperchainERC20 = _deploySuperchainERC20Proxy(REMOTE_TOKEN, NAME, SYMBOL, _decimals);
Expand Down

0 comments on commit beabbc5

Please sign in to comment.