Commit 13b06bb3 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: refactor for more simple `Initializable` tests

Make the ERC721Bridge test setup be part of the same process as the
StandardBridge setup so that its possible to have the entire L1 system
set up in a single unit test block. This makes writing tests that
touch all of the system L1 contracts much more easy. These changes
were done with some find and replaces.
parent b6104508
...@@ -447,9 +447,9 @@ contract Bridge_Initializer is Messenger_Initializer { ...@@ -447,9 +447,9 @@ contract Bridge_Initializer is Messenger_Initializer {
} }
} }
contract ERC721Bridge_Initializer is Messenger_Initializer { contract ERC721Bridge_Initializer is Bridge_Initializer {
L1ERC721Bridge L1Bridge; L1ERC721Bridge L1NFTBridge;
L2ERC721Bridge L2Bridge; L2ERC721Bridge L2NFTBridge;
function setUp() public virtual override { function setUp() public virtual override {
super.setUp(); super.setUp();
...@@ -463,10 +463,10 @@ contract ERC721Bridge_Initializer is Messenger_Initializer { ...@@ -463,10 +463,10 @@ contract ERC721Bridge_Initializer is Messenger_Initializer {
address(l1BridgeImpl), abi.encodeCall(L1ERC721Bridge.initialize, (CrossDomainMessenger(L1Messenger))) address(l1BridgeImpl), abi.encodeCall(L1ERC721Bridge.initialize, (CrossDomainMessenger(L1Messenger)))
); );
L1Bridge = L1ERC721Bridge(address(l1BridgeProxy)); L1NFTBridge = L1ERC721Bridge(address(l1BridgeProxy));
// Deploy the implementation for the L2ERC721Bridge and etch it into the predeploy address. // Deploy the implementation for the L2ERC721Bridge and etch it into the predeploy address.
L2ERC721Bridge l2BridgeImpl = new L2ERC721Bridge(address(L1Bridge)); L2ERC721Bridge l2BridgeImpl = new L2ERC721Bridge(address(L1NFTBridge));
Proxy l2BridgeProxy = new Proxy(multisig); Proxy l2BridgeProxy = new Proxy(multisig);
vm.etch(Predeploys.L2_ERC721_BRIDGE, address(l2BridgeProxy).code); vm.etch(Predeploys.L2_ERC721_BRIDGE, address(l2BridgeProxy).code);
...@@ -480,11 +480,11 @@ contract ERC721Bridge_Initializer is Messenger_Initializer { ...@@ -480,11 +480,11 @@ contract ERC721Bridge_Initializer is Messenger_Initializer {
); );
// Set up a reference to the L2ERC721Bridge. // Set up a reference to the L2ERC721Bridge.
L2Bridge = L2ERC721Bridge(Predeploys.L2_ERC721_BRIDGE); L2NFTBridge = L2ERC721Bridge(Predeploys.L2_ERC721_BRIDGE);
// Label the L1 and L2 bridges. // Label the L1 and L2 bridges.
vm.label(address(L1Bridge), "L1ERC721Bridge"); vm.label(address(L1NFTBridge), "L1ERC721Bridge");
vm.label(address(L2Bridge), "L2ERC721Bridge"); vm.label(address(L2NFTBridge), "L2ERC721Bridge");
} }
} }
......
...@@ -9,8 +9,8 @@ import { ERC721Bridge_Initializer } from "./CommonTest.t.sol"; ...@@ -9,8 +9,8 @@ import { ERC721Bridge_Initializer } from "./CommonTest.t.sol";
import { OptimismMintableERC721, IOptimismMintableERC721 } from "../src/universal/OptimismMintableERC721.sol"; import { OptimismMintableERC721, IOptimismMintableERC721 } from "../src/universal/OptimismMintableERC721.sol";
contract OptimismMintableERC721_Test is ERC721Bridge_Initializer { contract OptimismMintableERC721_Test is ERC721Bridge_Initializer {
ERC721 internal L1Token; ERC721 internal L1NFT;
OptimismMintableERC721 internal L2Token; OptimismMintableERC721 internal L2NFT;
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
...@@ -22,41 +22,41 @@ contract OptimismMintableERC721_Test is ERC721Bridge_Initializer { ...@@ -22,41 +22,41 @@ contract OptimismMintableERC721_Test is ERC721Bridge_Initializer {
super.setUp(); super.setUp();
// Set up the token pair. // Set up the token pair.
L1Token = new ERC721("L1Token", "L1T"); L1NFT = new ERC721("L1NFT", "L1T");
L2Token = new OptimismMintableERC721( L2NFT = new OptimismMintableERC721(
address(L2Bridge), address(L2NFTBridge),
1, 1,
address(L1Token), address(L1NFT),
"L2Token", "L2NFT",
"L2T" "L2T"
); );
// Label the addresses for nice traces. // Label the addresses for nice traces.
vm.label(address(L1Token), "L1ERC721Token"); vm.label(address(L1NFT), "L1ERC721Token");
vm.label(address(L2Token), "L2ERC721Token"); vm.label(address(L2NFT), "L2ERC721Token");
} }
function test_constructor_succeeds() external { function test_constructor_succeeds() external {
assertEq(L2Token.name(), "L2Token"); assertEq(L2NFT.name(), "L2NFT");
assertEq(L2Token.symbol(), "L2T"); assertEq(L2NFT.symbol(), "L2T");
assertEq(L2Token.remoteToken(), address(L1Token)); assertEq(L2NFT.remoteToken(), address(L1NFT));
assertEq(L2Token.bridge(), address(L2Bridge)); assertEq(L2NFT.bridge(), address(L2NFTBridge));
assertEq(L2Token.remoteChainId(), 1); assertEq(L2NFT.remoteChainId(), 1);
assertEq(L2Token.REMOTE_TOKEN(), address(L1Token)); assertEq(L2NFT.REMOTE_TOKEN(), address(L1NFT));
assertEq(L2Token.BRIDGE(), address(L2Bridge)); assertEq(L2NFT.BRIDGE(), address(L2NFTBridge));
assertEq(L2Token.REMOTE_CHAIN_ID(), 1); assertEq(L2NFT.REMOTE_CHAIN_ID(), 1);
} }
/// @notice Ensure that the contract supports the expected interfaces. /// @notice Ensure that the contract supports the expected interfaces.
function test_supportsInterfaces_succeeds() external { function test_supportsInterfaces_succeeds() external {
// Checks if the contract supports the IOptimismMintableERC721 interface. // Checks if the contract supports the IOptimismMintableERC721 interface.
assertTrue(L2Token.supportsInterface(type(IOptimismMintableERC721).interfaceId)); assertTrue(L2NFT.supportsInterface(type(IOptimismMintableERC721).interfaceId));
// Checks if the contract supports the IERC721Enumerable interface. // Checks if the contract supports the IERC721Enumerable interface.
assertTrue(L2Token.supportsInterface(type(IERC721Enumerable).interfaceId)); assertTrue(L2NFT.supportsInterface(type(IERC721Enumerable).interfaceId));
// Checks if the contract supports the IERC721 interface. // Checks if the contract supports the IERC721 interface.
assertTrue(L2Token.supportsInterface(type(IERC721).interfaceId)); assertTrue(L2NFT.supportsInterface(type(IERC721).interfaceId));
// Checks if the contract supports the IERC165 interface. // Checks if the contract supports the IERC165 interface.
assertTrue(L2Token.supportsInterface(type(IERC165).interfaceId)); assertTrue(L2NFT.supportsInterface(type(IERC165).interfaceId));
} }
function test_safeMint_succeeds() external { function test_safeMint_succeeds() external {
...@@ -69,24 +69,24 @@ contract OptimismMintableERC721_Test is ERC721Bridge_Initializer { ...@@ -69,24 +69,24 @@ contract OptimismMintableERC721_Test is ERC721Bridge_Initializer {
emit Mint(alice, 1); emit Mint(alice, 1);
// Mint the token. // Mint the token.
vm.prank(address(L2Bridge)); vm.prank(address(L2NFTBridge));
L2Token.safeMint(alice, 1); L2NFT.safeMint(alice, 1);
// Token should be owned by alice. // Token should be owned by alice.
assertEq(L2Token.ownerOf(1), alice); assertEq(L2NFT.ownerOf(1), alice);
} }
function test_safeMint_notBridge_reverts() external { function test_safeMint_notBridge_reverts() external {
// Try to mint the token. // Try to mint the token.
vm.expectRevert("OptimismMintableERC721: only bridge can call this function"); vm.expectRevert("OptimismMintableERC721: only bridge can call this function");
vm.prank(address(alice)); vm.prank(address(alice));
L2Token.safeMint(alice, 1); L2NFT.safeMint(alice, 1);
} }
function test_burn_succeeds() external { function test_burn_succeeds() external {
// Mint the token first. // Mint the token first.
vm.prank(address(L2Bridge)); vm.prank(address(L2NFTBridge));
L2Token.safeMint(alice, 1); L2NFT.safeMint(alice, 1);
// Expect a transfer event. // Expect a transfer event.
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
...@@ -97,37 +97,37 @@ contract OptimismMintableERC721_Test is ERC721Bridge_Initializer { ...@@ -97,37 +97,37 @@ contract OptimismMintableERC721_Test is ERC721Bridge_Initializer {
emit Burn(alice, 1); emit Burn(alice, 1);
// Burn the token. // Burn the token.
vm.prank(address(L2Bridge)); vm.prank(address(L2NFTBridge));
L2Token.burn(alice, 1); L2NFT.burn(alice, 1);
// Token should be owned by address(0). // Token should be owned by address(0).
vm.expectRevert("ERC721: invalid token ID"); vm.expectRevert("ERC721: invalid token ID");
L2Token.ownerOf(1); L2NFT.ownerOf(1);
} }
function test_burn_notBridge_reverts() external { function test_burn_notBridge_reverts() external {
// Mint the token first. // Mint the token first.
vm.prank(address(L2Bridge)); vm.prank(address(L2NFTBridge));
L2Token.safeMint(alice, 1); L2NFT.safeMint(alice, 1);
// Try to burn the token. // Try to burn the token.
vm.expectRevert("OptimismMintableERC721: only bridge can call this function"); vm.expectRevert("OptimismMintableERC721: only bridge can call this function");
vm.prank(address(alice)); vm.prank(address(alice));
L2Token.burn(alice, 1); L2NFT.burn(alice, 1);
} }
function test_tokenURI_succeeds() external { function test_tokenURI_succeeds() external {
// Mint the token first. // Mint the token first.
vm.prank(address(L2Bridge)); vm.prank(address(L2NFTBridge));
L2Token.safeMint(alice, 1); L2NFT.safeMint(alice, 1);
// Token URI should be correct. // Token URI should be correct.
assertEq( assertEq(
L2Token.tokenURI(1), L2NFT.tokenURI(1),
string( string(
abi.encodePacked( abi.encodePacked(
"ethereum:", "ethereum:",
Strings.toHexString(uint160(address(L1Token)), 20), Strings.toHexString(uint160(address(L1NFT)), 20),
"@", "@",
Strings.toString(1), Strings.toString(1),
"/tokenURI?uint256=", "/tokenURI?uint256=",
......
...@@ -15,14 +15,14 @@ contract OptimismMintableERC721Factory_Test is ERC721Bridge_Initializer { ...@@ -15,14 +15,14 @@ contract OptimismMintableERC721Factory_Test is ERC721Bridge_Initializer {
super.setUp(); super.setUp();
// Set up the token pair. // Set up the token pair.
factory = new OptimismMintableERC721Factory(address(L2Bridge), 1); factory = new OptimismMintableERC721Factory(address(L2NFTBridge), 1);
// Label the addresses for nice traces. // Label the addresses for nice traces.
vm.label(address(factory), "OptimismMintableERC721Factory"); vm.label(address(factory), "OptimismMintableERC721Factory");
} }
function test_constructor_succeeds() external { function test_constructor_succeeds() external {
assertEq(factory.BRIDGE(), address(L2Bridge)); assertEq(factory.BRIDGE(), address(L2NFTBridge));
assertEq(factory.REMOTE_CHAIN_ID(), 1); assertEq(factory.REMOTE_CHAIN_ID(), 1);
} }
...@@ -49,7 +49,7 @@ contract OptimismMintableERC721Factory_Test is ERC721Bridge_Initializer { ...@@ -49,7 +49,7 @@ contract OptimismMintableERC721Factory_Test is ERC721Bridge_Initializer {
assertEq(created.name(), "L2Token"); assertEq(created.name(), "L2Token");
assertEq(created.symbol(), "L2T"); assertEq(created.symbol(), "L2T");
assertEq(created.REMOTE_TOKEN(), remote); assertEq(created.REMOTE_TOKEN(), remote);
assertEq(created.BRIDGE(), address(L2Bridge)); assertEq(created.BRIDGE(), address(L2NFTBridge));
assertEq(created.REMOTE_CHAIN_ID(), 1); assertEq(created.REMOTE_CHAIN_ID(), 1);
} }
...@@ -80,7 +80,7 @@ contract OptimismMintableERC721Factory_Test is ERC721Bridge_Initializer { ...@@ -80,7 +80,7 @@ contract OptimismMintableERC721Factory_Test is ERC721Bridge_Initializer {
view view
returns (address) returns (address)
{ {
bytes memory constructorArgs = abi.encode(address(L2Bridge), 1, _remote, _name, _symbol); bytes memory constructorArgs = abi.encode(address(L2NFTBridge), 1, _remote, _name, _symbol);
bytes memory bytecode = abi.encodePacked(type(OptimismMintableERC721).creationCode, constructorArgs); bytes memory bytecode = abi.encodePacked(type(OptimismMintableERC721).creationCode, constructorArgs);
bytes32 salt = keccak256(abi.encode(_remote, _name, _symbol)); bytes32 salt = keccak256(abi.encode(_remote, _name, _symbol));
bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(factory), salt, keccak256(bytecode))); bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(factory), salt, keccak256(bytecode)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment