forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptimismMintableERC20Factory.t.sol
88 lines (68 loc) · 3.17 KB
/
OptimismMintableERC20Factory.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { OptimismMintableERC20 } from "../src/universal/OptimismMintableERC20.sol";
import { Bridge_Initializer } from "./CommonTest.t.sol";
contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
event StandardL2TokenCreated(address indexed remoteToken, address indexed localToken);
event OptimismMintableERC20Created(address indexed localToken, address indexed remoteToken, address deployer);
function setUp() public override {
super.setUp();
}
function test_bridge_succeeds() external {
assertEq(address(L2TokenFactory.BRIDGE()), address(L2Bridge));
}
function test_createStandardL2Token_succeeds() external {
address remote = address(4);
// Defaults to 18 decimals
address local = calculateTokenAddress(remote, "Beep", "BOOP", 18);
vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated(remote, local);
vm.expectEmit(true, true, true, true);
emit OptimismMintableERC20Created(local, remote, alice);
vm.prank(alice);
address addr = L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
assertTrue(addr == local);
assertTrue(OptimismMintableERC20(local).decimals() == 18);
}
function test_createStandardL2TokenWithDecimals_succeeds() external {
address remote = address(4);
address local = calculateTokenAddress(remote, "Beep", "BOOP", 6);
vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated(remote, local);
vm.expectEmit(true, true, true, true);
emit OptimismMintableERC20Created(local, remote, alice);
vm.prank(alice);
address addr = L2TokenFactory.createOptimismMintableERC20WithDecimals(remote, "Beep", "BOOP", 6);
assertTrue(addr == local);
assertTrue(OptimismMintableERC20(local).decimals() == 6);
}
function test_createStandardL2Token_sameTwice_reverts() external {
address remote = address(4);
vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
vm.expectRevert();
vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
}
function test_createStandardL2Token_remoteIsZero_reverts() external {
address remote = address(0);
vm.expectRevert("OptimismMintableERC20Factory: must provide remote token address");
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
}
function calculateTokenAddress(
address _remote,
string memory _name,
string memory _symbol,
uint8 _decimals
)
internal
view
returns (address)
{
bytes memory constructorArgs = abi.encode(address(L2Bridge), _remote, _name, _symbol, _decimals);
bytes memory bytecode = abi.encodePacked(type(OptimismMintableERC20).creationCode, constructorArgs);
bytes32 salt = keccak256(abi.encode(_remote, _name, _symbol, _decimals));
bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(L2TokenFactory), salt, keccak256(bytecode)));
return address(uint160(uint256(hash)));
}
}