Skip to content

Commit

Permalink
Add onReceive ERC721 and ERC1155 check
Browse files Browse the repository at this point in the history
  • Loading branch information
Phanco committed Jun 12, 2024
1 parent afefffd commit 2076e38
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/L2/paused/L2GovernorPaused.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ contract L2GovernorPaused is L2Governor {
uint256[] memory,
bytes memory
)
public
virtual
override
returns (bytes4)
public
virtual
override
returns (bytes4)
{
revert GovernorIsPaused();
}
Expand All @@ -121,10 +121,10 @@ contract L2GovernorPaused is L2Governor {
uint256,
bytes memory
)
public
virtual
override
returns (bytes4)
public
virtual
override
returns (bytes4)
{
revert GovernorIsPaused();
}
Expand Down
39 changes: 38 additions & 1 deletion test/L2/paused/L2GovernorPaused.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import { TimelockController } from "@openzeppelin/contracts/governance/TimelockC
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { TimelockControllerUpgradeable } from
"@openzeppelin-upgradeable/contracts/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import { ERC1155Holder } from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import { ERC721Holder } from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import { Test, console } from "forge-std/Test.sol";
import { L2Governor } from "src/L2/L2Governor.sol";
import { L2GovernorPaused } from "src/L2/paused/L2GovernorPaused.sol";
import { Utils } from "script/contracts/Utils.sol";
import { MockERC721 } from "test/mock/MockERC721.sol";
import { MockERC1155 } from "test/mock/MockERC1155.sol";

contract MockL2GovernorV2 is L2Governor {
function version() public pure virtual override returns (string memory) {
return "2.0.0";
}
}

contract L2GovernorPausedTest is Test {
contract L2GovernorPausedTest is Test, ERC1155Holder, ERC721Holder {
Utils public utils;
L2Governor public l2GovernorImplementation;
L2Governor public l2Governor;
Expand Down Expand Up @@ -118,6 +122,39 @@ contract L2GovernorPausedTest is Test {
l2Governor.execute(new address[](1), new uint256[](1), new bytes[](1), 0);
}

function test_OnERC1155BatchReceived_Paused() public {
MockERC1155 mockERC1155 = new MockERC1155();
mockERC1155.mint(address(this), 0, 10, "");
mockERC1155.mint(address(this), 1, 20, "");

uint256[] memory ids = new uint256[](2);
ids[0] = 0;
ids[1] = 1;

uint256[] memory values = new uint256[](2);
values[0] = 10;
values[1] = 20;

vm.expectRevert(L2GovernorPaused.GovernorIsPaused.selector);
mockERC1155.safeBatchTransferFrom(address(this), address(l2Governor), ids, values, "");
}

function test_OnERC1155Received_Paused() public {
MockERC1155 mockERC1155 = new MockERC1155();
mockERC1155.mint(address(this), 0, 10, "");

vm.expectRevert(L2GovernorPaused.GovernorIsPaused.selector);
mockERC1155.safeTransferFrom(address(this), address(l2Governor), 0, 10, "");
}

function test_OnERC721Received_Paused() public {
MockERC721 mockERC721 = new MockERC721();
mockERC721.mint(address(this), 0);

vm.expectRevert(L2GovernorPaused.GovernorIsPaused.selector);
mockERC721.safeTransferFrom(address(this), address(l2Governor), 0);
}

function test_Propose_Paused() public {
vm.expectRevert(L2GovernorPaused.GovernorIsPaused.selector);
l2Governor.propose(new address[](1), new uint256[](1), new bytes[](1), "");
Expand Down
15 changes: 15 additions & 0 deletions test/mock/MockERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.23;

import { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

/// @title MockERC1155
/// @notice MockERC1155 is a mock implementation of ERC1155 token.
/// IT SHOULD NEVER BE USED IN PRODUCTION.
contract MockERC1155 is ERC1155 {
constructor() ERC1155("") { }

function mint(address _to, uint256 _id, uint256 _value, bytes memory _data) public {
_mint(_to, _id, _value, _data);
}
}
15 changes: 15 additions & 0 deletions test/mock/MockERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.23;

import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

/// @title MockERC721
/// @notice MockERC721 is a mock implementation of ERC721 token.
/// IT SHOULD NEVER BE USED IN PRODUCTION.
contract MockERC721 is ERC721 {
constructor() ERC721("MockERC721", "ERC721") { }

function mint(address _to, uint256 _id) public {
_mint(_to, _id);
}
}

0 comments on commit 2076e38

Please sign in to comment.