Commit 01ed5651 authored by Maurelian's avatar Maurelian

ctb: Format forge tests with prettier

parent 1518a4f5
# Deps and test files
node_modules
lib
contracts/test/*.t.sol
contracts/vendor/*.sol
# build output
......
......@@ -142,10 +142,7 @@ contract L2OutputOracle_Initializer is CommonTest {
vm.label(address(oracle), "L2OutputOracle");
// Set the L2ToL1MessagePasser at the correct address
vm.etch(
Predeploys.L2_TO_L1_MESSAGE_PASSER,
address(new L2ToL1MessagePasser()).code
);
vm.etch(Predeploys.L2_TO_L1_MESSAGE_PASSER, address(new L2ToL1MessagePasser()).code);
vm.label(Predeploys.L2_TO_L1_MESSAGE_PASSER, "L2ToL1MessagePasser");
}
......@@ -185,10 +182,7 @@ contract Messenger_Initializer is L2OutputOracle_Initializer {
uint256 gasLimit
);
event SentMessageExtension1(
address indexed sender,
uint256 value
);
event SentMessageExtension1(address indexed sender, uint256 value);
event MessagePassed(
uint256 indexed nonce,
......@@ -273,12 +267,7 @@ contract Bridge_Initializer is Messenger_Initializer {
ERC20 BadL2Token;
OptimismMintableERC20 RemoteL1Token;
event ETHDepositInitiated(
address indexed from,
address indexed to,
uint256 amount,
bytes data
);
event ETHDepositInitiated(address indexed from, address indexed to, uint256 amount, bytes data);
event ETHWithdrawalFinalized(
address indexed from,
......@@ -332,19 +321,9 @@ contract Bridge_Initializer is Messenger_Initializer {
bytes data
);
event ETHBridgeInitiated(
address indexed from,
address indexed to,
uint256 amount,
bytes data
);
event ETHBridgeInitiated(address indexed from, address indexed to, uint256 amount, bytes data);
event ETHBridgeFinalized(
address indexed from,
address indexed to,
uint256 amount,
bytes data
);
event ETHBridgeFinalized(address indexed from, address indexed to, uint256 amount, bytes data);
event ERC20BridgeInitiated(
address indexed localToken,
......@@ -400,9 +379,7 @@ contract Bridge_Initializer is Messenger_Initializer {
Predeploys.L2_STANDARD_BRIDGE
);
vm.etch(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY, address(factory).code);
L2TokenFactory = OptimismMintableERC20Factory(
Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY
);
L2TokenFactory = OptimismMintableERC20Factory(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY);
vm.etch(Predeploys.LEGACY_ERC20_ETH, address(new LegacyERC20ETH()).code);
......@@ -571,9 +548,10 @@ contract FFIInterface is Test {
return abi.decode(result, (bytes32));
}
function encodeDepositTransaction(
Types.UserDepositTransaction calldata txn
) external returns (bytes memory) {
function encodeDepositTransaction(Types.UserDepositTransaction calldata txn)
external
returns (bytes memory)
{
string[] memory cmds = new string[](12);
cmds[0] = "node";
cmds[1] = "dist/scripts/differential-testing.js";
......@@ -651,18 +629,19 @@ contract Reverter {
// Useful for testing reentrancy guards
contract CallerCaller {
event WhatHappened(
bool success,
bytes returndata
);
event WhatHappened(bool success, bytes returndata);
fallback() external {
(bool success, bytes memory returndata) = msg.sender.call(msg.data);
emit WhatHappened(success, returndata);
assembly {
switch success
case 0 { revert(add(returndata, 0x20), mload(returndata)) }
default { return(add(returndata, 0x20), mload(returndata)) }
case 0 {
revert(add(returndata, 0x20), mload(returndata))
}
default {
return(add(returndata, 0x20), mload(returndata))
}
}
}
}
......@@ -30,17 +30,11 @@ contract CrossDomainOwnable_Test is CommonTest {
// Check that making a call can set the value properly
function test_onlyOwner() external {
assertEq(
setter.value(),
0
);
assertEq(setter.value(), 0);
vm.prank(AddressAliasHelper.applyL1ToL2Alias(setter.owner()));
setter.set(1);
assertEq(
setter.value(),
1
);
assertEq(setter.value(), 1);
}
}
......@@ -63,10 +57,7 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer {
0,
10000,
false,
abi.encodeWithSelector(
XDomainSetter.set.selector,
1
)
abi.encodeWithSelector(XDomainSetter.set.selector, 1)
);
// Simulate the operation of the `op-node` by parsing data
......@@ -79,19 +70,13 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer {
// It is the expected topic
bytes32 topic = log.topics[0];
assertEq(
topic,
keccak256("TransactionDeposited(address,address,uint256,bytes)")
);
assertEq(topic, keccak256("TransactionDeposited(address,address,uint256,bytes)"));
// from is indexed and the first argument to the event.
bytes32 _from = log.topics[1];
address from = Bytes32AddressLib.fromLast20Bytes(_from);
assertEq(
AddressAliasHelper.undoL1ToL2Alias(from),
alice
);
assertEq(AddressAliasHelper.undoL1ToL2Alias(from), alice);
// Make a call from the "from" value received from the log.
// In theory the opaque data could be parsed from the log
......@@ -99,9 +84,6 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer {
// directly on the setter is good enough.
vm.prank(from);
setter.set(1);
assertEq(
setter.value(),
1
);
assertEq(setter.value(), 1);
}
}
......@@ -19,7 +19,7 @@ contract XDomainSetter2 is CrossDomainOwnable2 {
contract CrossDomainOwnable2_Test is Messenger_Initializer {
XDomainSetter2 setter;
function setUp() override public {
function setUp() public override {
super.setUp();
vm.prank(alice);
setter = new XDomainSetter2();
......@@ -47,10 +47,7 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer {
address target = address(setter);
uint256 value = 0;
uint256 minGasLimit = 0;
bytes memory message = abi.encodeWithSelector(
XDomainSetter2.set.selector,
1
);
bytes memory message = abi.encodeWithSelector(XDomainSetter2.set.selector, 1);
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(nonce, 1),
......@@ -76,10 +73,7 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer {
message
);
assertEq(
setter.value(),
0
);
assertEq(setter.value(), 0);
}
function test_onlyOwner() external {
......@@ -94,15 +88,9 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer {
address(setter),
0,
0,
abi.encodeWithSelector(
XDomainSetter2.set.selector,
2
)
abi.encodeWithSelector(XDomainSetter2.set.selector, 2)
);
assertEq(
setter.value(),
2
);
assertEq(setter.value(), 2);
}
}
......@@ -21,9 +21,6 @@ contract DeployerWhitelist_Test is CommonTest {
vm.prank(list.owner());
list.setOwner(address(1));
assertEq(
bytes32(uint256(1)),
vm.load(address(list), bytes32(uint256(0)))
);
assertEq(bytes32(uint256(1)), vm.load(address(list), bytes32(uint256(0))));
}
}
......@@ -22,15 +22,9 @@ contract Encoding_Test is CommonTest {
uint256 nonce = uint256(Encoding.encodeVersionedNonce(_nonce, _version));
(uint256 decodedNonce, uint256 decodedVersion) = ffi.decodeVersionedNonce(nonce);
assertEq(
_version,
uint16(decodedVersion)
);
assertEq(_version, uint16(decodedVersion));
assertEq(
_nonce,
uint240(decodedNonce)
);
assertEq(_nonce, uint240(decodedNonce));
}
function test_encodeCrossDomainMessage_differential(
......@@ -91,9 +85,6 @@ contract Encoding_Test is CommonTest {
bytes memory txn = Encoding.encodeDepositTransaction(t);
bytes memory _txn = ffi.encodeDepositTransaction(t);
assertEq(
txn,
_txn
);
assertEq(txn, _txn);
}
}
......@@ -7,7 +7,6 @@ import { L1Block } from "../L2/L1Block.sol";
import { Predeploys } from "../libraries/Predeploys.sol";
contract GasPriceOracle_Test is CommonTest {
event OverheadUpdated(uint256);
event ScalarUpdated(uint256);
event DecimalsUpdated(uint256);
......@@ -18,10 +17,7 @@ contract GasPriceOracle_Test is CommonTest {
function setUp() external {
// place the L1Block contract at the predeploy address
vm.etch(
Predeploys.L1_BLOCK_ATTRIBUTES,
address(new L1Block()).code
);
vm.etch(Predeploys.L1_BLOCK_ATTRIBUTES, address(new L1Block()).code);
l1Block = L1Block(Predeploys.L1_BLOCK_ATTRIBUTES);
depositor = l1Block.DEPOSITOR_ACCOUNT();
......@@ -39,13 +35,7 @@ contract GasPriceOracle_Test is CommonTest {
uint64 sequenceNumber = 0;
vm.prank(depositor);
l1Block.setL1BlockValues(
number,
timestamp,
basefee,
hash,
sequenceNumber
);
l1Block.setL1BlockValues(number, timestamp, basefee, hash, sequenceNumber);
}
function test_owner() external {
......@@ -57,26 +47,17 @@ contract GasPriceOracle_Test is CommonTest {
// the overhead is at slot 3
vm.prank(gasOracle.owner());
gasOracle.setOverhead(456);
assertEq(
456,
uint256(vm.load(address(gasOracle), bytes32(uint256(3))))
);
assertEq(456, uint256(vm.load(address(gasOracle), bytes32(uint256(3)))));
// scalar is at slot 4
vm.prank(gasOracle.owner());
gasOracle.setScalar(333);
assertEq(
333,
uint256(vm.load(address(gasOracle), bytes32(uint256(4))))
);
assertEq(333, uint256(vm.load(address(gasOracle), bytes32(uint256(4)))));
// decimals is at slot 5
vm.prank(gasOracle.owner());
gasOracle.setDecimals(222);
assertEq(
222,
uint256(vm.load(address(gasOracle), bytes32(uint256(5))))
);
assertEq(222, uint256(vm.load(address(gasOracle), bytes32(uint256(5)))));
}
function test_l1BaseFee() external {
......@@ -99,10 +80,7 @@ contract GasPriceOracle_Test is CommonTest {
function test_setGasPriceReverts() external {
vm.prank(gasOracle.owner());
(bool success, bytes memory returndata) = address(gasOracle).call(
abi.encodeWithSignature(
"setGasPrice(uint256)",
1
)
abi.encodeWithSignature("setGasPrice(uint256)", 1)
);
assertEq(success, false);
......@@ -112,10 +90,7 @@ contract GasPriceOracle_Test is CommonTest {
function test_setL1BaseFeeReverts() external {
vm.prank(gasOracle.owner());
(bool success, bytes memory returndata) = address(gasOracle).call(
abi.encodeWithSignature(
"setL1BaseFee(uint256)",
1
)
abi.encodeWithSignature("setL1BaseFee(uint256)", 1)
);
assertEq(success, false);
......
......@@ -17,10 +17,7 @@ contract Hashing_Test is CommonTest {
0x1
);
assertEq(
sourceHash,
0xf923fb07134d7d287cb52c770cc619e17e82606c21a875c92f4c63b65280a5cc
);
assertEq(sourceHash, 0xf923fb07134d7d287cb52c770cc619e17e82606c21a875c92f4c63b65280a5cc);
}
function test_hashCrossDomainMessage_differential(
......@@ -65,24 +62,10 @@ contract Hashing_Test is CommonTest {
bytes memory _data
) external {
bytes32 hash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction(
_nonce,
_sender,
_target,
_value,
_gasLimit,
_data
)
Types.WithdrawalTransaction(_nonce, _sender, _target, _value, _gasLimit, _data)
);
bytes32 _hash = ffi.hashWithdrawal(
_nonce,
_sender,
_target,
_value,
_gasLimit,
_data
);
bytes32 _hash = ffi.hashWithdrawal(_nonce, _sender, _target, _value, _gasLimit, _data);
assertEq(hash, _hash);
}
......
......@@ -16,7 +16,13 @@ contract L1BlockTest is CommonTest {
lb.setL1BlockValues(uint64(1), uint64(2), 3, NON_ZERO_HASH, uint64(4));
}
function test_updatesValues(uint64 n, uint64 t, uint256 b, bytes32 h, uint64 s) external {
function test_updatesValues(
uint64 n,
uint64 t,
uint256 b,
bytes32 h,
uint64 s
) external {
vm.prank(depositor);
lb.setL1BlockValues(n, t, b, h, s);
assertEq(lb.number(), n);
......@@ -48,6 +54,12 @@ contract L1BlockTest is CommonTest {
function test_updateValues() external {
vm.prank(depositor);
lb.setL1BlockValues(type(uint64).max, type(uint64).max, type(uint256).max, keccak256(abi.encode(1)), type(uint64).max);
lb.setL1BlockValues(
type(uint64).max,
type(uint64).max,
type(uint256).max,
keccak256(abi.encode(1)),
type(uint64).max
);
}
}
......@@ -144,7 +144,9 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.prank(address(op));
vm.expectRevert("CrossDomainMessenger: only version 1 messages are supported after the Bedrock upgrade");
vm.expectRevert(
"CrossDomainMessenger: only version 1 messages are supported after the Bedrock upgrade"
);
L1Messenger.relayMessage(
0, // nonce
sender,
......@@ -168,7 +170,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.expectEmit(true, true, true, true);
bytes32 hash = Hashing.hashCrossDomainMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, 0, 0, hex"1111");
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
0,
0,
hex"1111"
);
emit RelayedMessage(hash);
......@@ -196,11 +205,25 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.prank(address(op));
vm.expectRevert("CrossDomainMessenger: message cannot be replayed");
L1Messenger.relayMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, 0, 0, message);
L1Messenger.relayMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
0,
0,
message
);
vm.store(address(op), 0, bytes32(abi.encode(sender)));
vm.expectRevert("CrossDomainMessenger: message cannot be replayed");
L1Messenger.relayMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, 0, 0, message);
L1Messenger.relayMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
0,
0,
message
);
}
// relayMessage: should revert if eth is sent from a contract other than the standard bridge
......@@ -212,7 +235,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.expectRevert(
"CrossDomainMessenger: value must be zero unless message is from a system address"
);
L1Messenger.relayMessage{ value: 100 }(Encoding.encodeVersionedNonce(0, 1), sender, target, 0, 0, message);
L1Messenger.relayMessage{ value: 100 }(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
0,
0,
message
);
}
// relayMessage: the xDomainMessageSender is reset to the original value
......@@ -224,7 +254,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.prank(address(op));
L1Messenger.relayMessage(Encoding.encodeVersionedNonce(0, 1), address(0), address(0), 0, 0, hex"");
L1Messenger.relayMessage(
Encoding.encodeVersionedNonce(0, 1),
address(0),
address(0),
0,
0,
hex""
);
vm.expectRevert("CrossDomainMessenger: xDomainMessageSender is not set");
L1Messenger.xDomainMessageSender();
......@@ -248,13 +285,20 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.expectCall(target, hex"1111");
bytes32 hash = Hashing.hashCrossDomainMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, value, 0, hex"1111");
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
value,
0,
hex"1111"
);
vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.etch(target, address(new Reverter()).code);
vm.deal(address(op), value);
vm.prank(address(op));
L1Messenger.relayMessage{value: value}(
L1Messenger.relayMessage{ value: value }(
Encoding.encodeVersionedNonce(0, 1), // nonce
sender,
target,
......@@ -303,14 +347,24 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
hex"1111"
);
bytes32 hash = Hashing.hashCrossDomainMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, 0, 0, message);
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
0,
0,
message
);
vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.etch(target, address(new CallerCaller()).code);
vm.expectEmit(true, true, true, true, target);
emit WhatHappened(false, abi.encodeWithSignature("Error(string)", "ReentrancyGuard: reentrant call"));
emit WhatHappened(
false,
abi.encodeWithSignature("Error(string)", "ReentrancyGuard: reentrant call")
);
vm.prank(address(op));
vm.expectCall(target, message);
......
......@@ -21,20 +21,11 @@ contract L1StandardBridge_Getter_Test is Bridge_Initializer {
contract L1StandardBridge_Initialize_Test is Bridge_Initializer {
function test_initialize_success() external {
assertEq(
address(L1Bridge.messenger()),
address(L1Messenger)
);
assertEq(address(L1Bridge.messenger()), address(L1Messenger));
assertEq(
address(L1Bridge.otherBridge()),
Predeploys.L2_STANDARD_BRIDGE
);
assertEq(address(L1Bridge.otherBridge()), Predeploys.L2_STANDARD_BRIDGE);
assertEq(
address(L2Bridge),
Predeploys.L2_STANDARD_BRIDGE
);
assertEq(address(L2Bridge), Predeploys.L2_STANDARD_BRIDGE);
}
}
......@@ -66,7 +57,7 @@ contract L1StandardBridge_Receive_Test is Bridge_Initializer {
);
vm.prank(alice, alice);
(bool success,) = address(L1Bridge).call{ value: 100 }(hex"");
(bool success, ) = address(L1Bridge).call{ value: 100 }(hex"");
assertEq(success, true);
assertEq(address(op).balance, 100);
}
......@@ -137,12 +128,7 @@ contract L1StandardBridge_DepositETHTo_Test is Bridge_Initializer {
// depositETHTo on the L1 bridge should be called
vm.expectCall(
address(L1Bridge),
abi.encodeWithSelector(
L1Bridge.depositETHTo.selector,
bob,
1000,
hex"dead"
)
abi.encodeWithSelector(L1Bridge.depositETHTo.selector, bob, 1000, hex"dead")
);
// the L1 bridge should call
......@@ -176,6 +162,7 @@ contract L1StandardBridge_DepositETHTo_TestFail is Bridge_Initializer {}
contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
using stdStorage for StdStorage;
// depositERC20
// - updates bridge.deposits
// - emits ERC20DepositInitiated
......@@ -183,14 +170,7 @@ contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
// - only callable by EOA
function test_depositERC20_succeeds() external {
vm.expectEmit(true, true, true, true);
emit ERC20DepositInitiated(
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
emit ERC20DepositInitiated(address(L1Token), address(L2Token), alice, alice, 100, hex"");
deal(address(L1Token), alice, 100000, true);
......@@ -201,24 +181,13 @@ contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
// to itself
vm.expectCall(
address(L1Token),
abi.encodeWithSelector(
ERC20.transferFrom.selector,
alice,
address(L1Bridge),
100
)
abi.encodeWithSelector(ERC20.transferFrom.selector, alice, address(L1Bridge), 100)
);
// TODO: optimismPortal.depositTransaction call + event
vm.prank(alice);
L1Bridge.depositERC20(
address(L1Token),
address(L2Token),
100,
10000,
hex""
);
L1Bridge.depositERC20(address(L1Token), address(L2Token), 100, 10000, hex"");
assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 100);
}
......@@ -231,13 +200,7 @@ contract L1StandardBridge_DepositERC20_TestFail is Bridge_Initializer {
vm.expectRevert("StandardBridge: function can only be called from an EOA");
vm.prank(alice, alice);
L1Bridge.depositERC20(
address(0),
address(0),
100,
100,
hex""
);
L1Bridge.depositERC20(address(0), address(0), 100, 100, hex"");
}
}
......@@ -249,14 +212,7 @@ contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer {
// - callable by a contract
function test_depositERC20To_success() external {
vm.expectEmit(true, true, true, true);
emit ERC20DepositInitiated(
address(L1Token),
address(L2Token),
alice,
bob,
1000,
hex""
);
emit ERC20DepositInitiated(address(L1Token), address(L2Token), alice, bob, 1000, hex"");
deal(address(L1Token), alice, 100000, true);
......@@ -265,23 +221,11 @@ contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer {
vm.expectCall(
address(L1Token),
abi.encodeWithSelector(
ERC20.transferFrom.selector,
alice,
address(L1Bridge),
1000
)
abi.encodeWithSelector(ERC20.transferFrom.selector, alice, address(L1Bridge), 1000)
);
vm.prank(alice);
L1Bridge.depositERC20To(
address(L1Token),
address(L2Token),
bob,
1000,
10000,
hex""
);
L1Bridge.depositERC20To(address(L1Token), address(L2Token), bob, 1000, 10000, hex"");
assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 1000);
}
......@@ -297,17 +241,9 @@ contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer {
uint256 aliceBalance = alice.balance;
vm.expectEmit(true, true, true, true);
emit ETHWithdrawalFinalized(
alice,
alice,
100,
hex""
);
emit ETHWithdrawalFinalized(alice, alice, 100, hex"");
vm.expectCall(
alice,
hex""
);
vm.expectCall(alice, hex"");
vm.mockCall(
address(L1Bridge.messenger()),
......@@ -317,12 +253,7 @@ contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer {
// ensure that the messenger has ETH to call with
vm.deal(address(L1Bridge.messenger()), 100);
vm.prank(address(L1Bridge.messenger()));
L1Bridge.finalizeETHWithdrawal{ value: 100 }(
alice,
alice,
100,
hex""
);
L1Bridge.finalizeETHWithdrawal{ value: 100 }(alice, alice, 100, hex"");
assertEq(address(L1Bridge.messenger()).balance, 0);
assertEq(aliceBalance + 100, alice.balance);
......@@ -353,22 +284,11 @@ contract L1StandardBridge_FinalizeERC20Withdrawal_Test is Bridge_Initializer {
assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 100);
vm.expectEmit(true, true, true, true);
emit ERC20WithdrawalFinalized(
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
emit ERC20WithdrawalFinalized(address(L1Token), address(L2Token), alice, alice, 100, hex"");
vm.expectCall(
address(L1Token),
abi.encodeWithSelector(
ERC20.transfer.selector,
alice,
100
)
abi.encodeWithSelector(ERC20.transfer.selector, alice, 100)
);
vm.mockCall(
......@@ -431,7 +351,9 @@ contract L1StandardBridge_FinalizeERC20Withdrawal_TestFail is Bridge_Initializer
// Todo: move these next two contracts into a test file specific to the direction agnostic
// StandardBridge interface
contract L1StandardBridge_FinalizeBridgeETH_Test is Bridge_Initializer {}
contract L1StandardBridge_FinalizeBridgeETH_Test is Bridge_Initializer {
}
contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
function test_finalizeBridgeETH_revert_incorrectValue() external {
......@@ -444,12 +366,7 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
vm.deal(messenger, 100);
vm.prank(messenger);
vm.expectRevert("StandardBridge: amount sent does not match amount required");
L1Bridge.finalizeBridgeETH{value: 50}(
alice,
alice,
100,
hex""
);
L1Bridge.finalizeBridgeETH{ value: 50 }(alice, alice, 100, hex"");
}
function test_finalizeBridgeETH_revert_sendToSelf() external {
......@@ -462,12 +379,7 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
vm.deal(messenger, 100);
vm.prank(messenger);
vm.expectRevert("StandardBridge: cannot send to self");
L1Bridge.finalizeBridgeETH{value: 100}(
alice,
address(L1Bridge),
100,
hex""
);
L1Bridge.finalizeBridgeETH{ value: 100 }(alice, address(L1Bridge), 100, hex"");
}
function test_finalizeBridgeETH_revert_sendToMessenger() external {
......@@ -480,11 +392,6 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
vm.deal(messenger, 100);
vm.prank(messenger);
vm.expectRevert("StandardBridge: cannot send to messenger");
L1Bridge.finalizeBridgeETH{value: 100}(
alice,
messenger,
100,
hex""
);
L1Bridge.finalizeBridgeETH{ value: 100 }(alice, messenger, 100, hex"");
}
}
......@@ -32,10 +32,7 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
function test_L2MessengerMessageVersion() external {
(, uint16 version) = Encoding.decodeVersionedNonce(L2Messenger.messageNonce());
assertEq(
version,
L2Messenger.MESSAGE_VERSION()
);
assertEq(version, L2Messenger.MESSAGE_VERSION());
}
function test_L2MessengerSendMessage() external {
......@@ -83,10 +80,7 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
L2Messenger.sendMessage(recipient, hex"aa", uint32(500_000));
L2Messenger.sendMessage(recipient, hex"aa", uint32(500_000));
// the nonce increments for each message sent
assertEq(
nonce + 2,
L2Messenger.messageNonce()
);
assertEq(nonce + 2, L2Messenger.messageNonce());
}
function test_L2MessengerXDomainSenderReverts() external {
......@@ -101,7 +95,9 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
vm.prank(caller);
vm.expectRevert("CrossDomainMessenger: only version 1 messages are supported after the Bedrock upgrade");
vm.expectRevert(
"CrossDomainMessenger: only version 1 messages are supported after the Bedrock upgrade"
);
L2Messenger.relayMessage(
0, // nonce
sender,
......@@ -158,7 +154,14 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
vm.prank(caller);
vm.expectRevert("CrossDomainMessenger: message cannot be replayed");
L1Messenger.relayMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, 0, 0, message);
L1Messenger.relayMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
0,
0,
message
);
}
// relayMessage: the xDomainMessageSender is reset to the original value
......@@ -168,7 +171,14 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
address caller = AddressAliasHelper.applyL1ToL2Alias(address(L1Messenger));
vm.prank(caller);
L2Messenger.relayMessage(Encoding.encodeVersionedNonce(0, 1), address(0), address(0), 0, 0, hex"");
L2Messenger.relayMessage(
Encoding.encodeVersionedNonce(0, 1),
address(0),
address(0),
0,
0,
hex""
);
vm.expectRevert("CrossDomainMessenger: xDomainMessageSender is not set");
L2Messenger.xDomainMessageSender();
......@@ -191,12 +201,19 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
address caller = AddressAliasHelper.applyL1ToL2Alias(address(L1Messenger));
uint256 value = 100;
bytes32 hash = Hashing.hashCrossDomainMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, value, 0, hex"1111");
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
value,
0,
hex"1111"
);
vm.etch(target, address(new Reverter()).code);
vm.deal(address(caller), value);
vm.prank(caller);
L2Messenger.relayMessage{value: value}(
L2Messenger.relayMessage{ value: value }(
Encoding.encodeVersionedNonce(0, 1), // nonce
sender,
target,
......@@ -246,13 +263,23 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
hex"1111"
);
bytes32 hash = Hashing.hashCrossDomainMessage(Encoding.encodeVersionedNonce(0, 1), sender, target, 0, 0, message);
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(0, 1),
sender,
target,
0,
0,
message
);
vm.etch(target, address(new CallerCaller()).code);
vm.expectEmit(true, true, true, true, target);
emit WhatHappened(false, abi.encodeWithSignature("Error(string)", "ReentrancyGuard: reentrant call"));
emit WhatHappened(
false,
abi.encodeWithSignature("Error(string)", "ReentrancyGuard: reentrant call")
);
vm.prank(caller);
vm.expectCall(target, message);
......
......@@ -29,9 +29,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
}
function testCannot_constructWithBadTimestamp() external {
vm.expectRevert(
"L2OutputOracle: starting L2 timestamp must be less than current time"
);
vm.expectRevert("L2OutputOracle: starting L2 timestamp must be less than current time");
new L2OutputOracle(
submissionInterval,
......@@ -78,7 +76,9 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
assertEq(proposal.timestamp, block.timestamp);
// The block number is too low:
vm.expectRevert("L2OutputOracle: block number cannot be less than the starting block number.");
vm.expectRevert(
"L2OutputOracle: block number cannot be less than the starting block number."
);
oracle.getL2Output(0);
// The block number is larger than the latest proposed output:
......@@ -292,9 +292,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
test_proposingAnotherOutput();
uint256 latestBlockNumber = oracle.latestBlockNumber();
Types.OutputProposal memory proposalToDelete = oracle.getL2Output(
latestBlockNumber
);
Types.OutputProposal memory proposalToDelete = oracle.getL2Output(latestBlockNumber);
Types.OutputProposal memory newLatestOutput = oracle.getL2Output(
latestBlockNumber - submissionInterval
);
......@@ -334,9 +332,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
test_proposingAnotherOutput();
uint256 previousBlockNumber = oracle.latestBlockNumber() - submissionInterval;
Types.OutputProposal memory proposalToDelete = oracle.getL2Output(
previousBlockNumber
);
Types.OutputProposal memory proposalToDelete = oracle.getL2Output(previousBlockNumber);
vm.prank(owner);
vm.expectRevert(
......@@ -349,9 +345,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
test_proposingAnotherOutput();
uint256 latestBlockNumber = oracle.latestBlockNumber();
Types.OutputProposal memory proposalToDelete = oracle.getL2Output(
latestBlockNumber
);
Types.OutputProposal memory proposalToDelete = oracle.getL2Output(latestBlockNumber);
// Modify the timestamp so that it does not match.
proposalToDelete.timestamp -= 1;
......@@ -378,9 +372,7 @@ contract L2OutputOracleUpgradeable_Test is L2OutputOracle_Initializer {
assertEq(startingTimestamp, oracleImpl.STARTING_TIMESTAMP());
assertEq(l2BlockTime, oracleImpl.L2_BLOCK_TIME());
Types.OutputProposal memory initOutput = oracleImpl.getL2Output(
startingBlockNumber
);
Types.OutputProposal memory initOutput = oracleImpl.getL2Output(startingBlockNumber);
assertEq(genesisL2Output, initOutput.outputRoot);
assertEq(initL1Time, initOutput.timestamp);
......
......@@ -15,15 +15,9 @@ contract L2StandardBridge_Test is Bridge_Initializer {
}
function test_initialize() external {
assertEq(
address(L2Bridge.messenger()),
address(L2Messenger)
);
assertEq(address(L2Bridge.messenger()), address(L2Messenger));
assertEq(
address(L2Bridge.otherBridge()),
address(L1Bridge)
);
assertEq(address(L2Bridge.otherBridge()), address(L1Bridge));
}
// receive
......@@ -40,7 +34,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
// TODO: events from each contract
vm.prank(alice, alice);
(bool success,) = address(L2Bridge).call{ value: 100 }(hex"");
(bool success, ) = address(L2Bridge).call{ value: 100 }(hex"");
assertEq(success, true);
assertEq(address(messagePasser).balance, 100);
}
......@@ -52,12 +46,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.expectRevert("StandardBridge: bridging ETH must include sufficient ETH value");
vm.prank(alice, alice);
L2Bridge.withdraw(
address(Predeploys.LEGACY_ERC20_ETH),
100,
1000,
hex""
);
L2Bridge.withdraw(address(Predeploys.LEGACY_ERC20_ETH), 100, 1000, hex"");
}
// withdraw
......@@ -70,12 +59,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
assertEq(L2Token.balanceOf(alice), 100);
vm.prank(alice, alice);
L2Bridge.withdraw(
address(L2Token),
100,
1000,
hex""
);
L2Bridge.withdraw(address(L2Token), 100, 1000, hex"");
// TODO: events and calls
......@@ -87,12 +71,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
deal(address(L2Token), address(this), 100, true);
vm.expectRevert("StandardBridge: function can only be called from an EOA");
L2Bridge.withdraw(
address(L2Token),
100,
1000,
hex""
);
L2Bridge.withdraw(address(L2Token), 100, 1000, hex"");
}
// withdrawTo
......@@ -103,13 +82,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
deal(address(L2Token), alice, 100, true);
vm.prank(alice, alice);
L2Bridge.withdrawTo(
address(L2Token),
bob,
100,
1000,
hex""
);
L2Bridge.withdrawTo(address(L2Token), bob, 100, 1000, hex"");
// TODO: events and calls
......@@ -138,23 +111,9 @@ contract L2StandardBridge_Test is Bridge_Initializer {
hex""
);
vm.expectEmit(true, true, true, true, address(L2Bridge));
emit DepositFinalized(
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
emit DepositFinalized(address(L1Token), address(L2Token), alice, alice, 100, hex"");
vm.prank(address(L2Messenger));
L2Bridge.finalizeDeposit(
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
L2Bridge.finalizeDeposit(address(L1Token), address(L2Token), alice, alice, 100, hex"");
}
function test_finalizeBridgeETH_incorrectValueReverts() external {
......@@ -166,12 +125,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.deal(address(L2Messenger), 100);
vm.prank(address(L2Messenger));
vm.expectRevert("StandardBridge: amount sent does not match amount required");
L2Bridge.finalizeBridgeETH{value: 50}(
alice,
alice,
100,
hex""
);
L2Bridge.finalizeBridgeETH{ value: 50 }(alice, alice, 100, hex"");
}
function test_finalizeBridgeETH_sendToSelfReverts() external {
......@@ -183,12 +137,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.deal(address(L2Messenger), 100);
vm.prank(address(L2Messenger));
vm.expectRevert("StandardBridge: cannot send to self");
L2Bridge.finalizeBridgeETH{value: 100}(
alice,
address(L2Bridge),
100,
hex""
);
L2Bridge.finalizeBridgeETH{ value: 100 }(alice, address(L2Bridge), 100, hex"");
}
function test_finalizeBridgeETH_sendToMessengerReverts() external {
......@@ -200,11 +149,6 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.deal(address(L2Messenger), 100);
vm.prank(address(L2Messenger));
vm.expectRevert("StandardBridge: cannot send to messenger");
L2Bridge.finalizeBridgeETH{value: 100}(
alice,
address(L2Messenger),
100,
hex""
);
L2Bridge.finalizeBridgeETH{ value: 100 }(alice, address(L2Messenger), 100, hex"");
}
}
......@@ -22,7 +22,7 @@ contract L2ToL1MessagePasserTest is CommonTest {
event WithdrawerBalanceBurnt(uint256 indexed amount);
function setUp() virtual public {
function setUp() public virtual {
messagePasser = new L2ToL1MessagePasser();
}
......@@ -36,14 +36,7 @@ contract L2ToL1MessagePasserTest is CommonTest {
uint256 nonce = messagePasser.nonce();
vm.expectEmit(true, true, true, true);
emit MessagePassed(
nonce,
_sender,
_target,
_value,
_gasLimit,
_data
);
emit MessagePassed(nonce, _sender, _target, _value, _gasLimit, _data);
bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction({
......@@ -61,39 +54,19 @@ contract L2ToL1MessagePasserTest is CommonTest {
vm.deal(_sender, _value);
vm.prank(_sender);
messagePasser.initiateWithdrawal{ value: _value }(
_target,
_gasLimit,
_data
);
messagePasser.initiateWithdrawal{ value: _value }(_target, _gasLimit, _data);
assertEq(
messagePasser.sentMessages(withdrawalHash),
true
);
assertEq(messagePasser.sentMessages(withdrawalHash), true);
bytes32 slot = keccak256(bytes.concat(
withdrawalHash,
bytes32(0)
));
bytes32 slot = keccak256(bytes.concat(withdrawalHash, bytes32(0)));
assertEq(
vm.load(address(messagePasser), slot),
bytes32(uint256(1))
);
assertEq(vm.load(address(messagePasser), slot), bytes32(uint256(1)));
}
// Test: initiateWithdrawal should emit the correct log when called by a contract
function test_initiateWithdrawal_fromContract() external {
vm.expectEmit(true, true, true, true);
emit MessagePassed(
messagePasser.nonce(),
address(this),
address(4),
100,
64000,
hex""
);
emit MessagePassed(messagePasser.nonce(), address(this), address(4), 100, 64000, hex"");
bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction(
......@@ -110,11 +83,7 @@ contract L2ToL1MessagePasserTest is CommonTest {
emit MessagePassedExtension1(withdrawalHash);
vm.deal(address(this), 2**64);
messagePasser.initiateWithdrawal{ value: 100 }(
address(4),
64000,
hex""
);
messagePasser.initiateWithdrawal{ value: 100 }(address(4), 64000, hex"");
}
// Test: initiateWithdrawal should emit the correct log when called by an EOA
......@@ -129,31 +98,13 @@ contract L2ToL1MessagePasserTest is CommonTest {
vm.prank(alice, alice);
vm.deal(alice, 2**64);
vm.expectEmit(true, true, true, true);
emit MessagePassed(
nonce,
alice,
target,
value,
gasLimit,
data
);
emit MessagePassed(nonce, alice, target, value, gasLimit, data);
bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction(
nonce,
alice,
target,
value,
gasLimit,
data
)
Types.WithdrawalTransaction(nonce, alice, target, value, gasLimit, data)
);
messagePasser.initiateWithdrawal{ value: value }(
target,
gasLimit,
data
);
messagePasser.initiateWithdrawal{ value: value }(target, gasLimit, data);
// the sent messages mapping is filled
assertEq(messagePasser.sentMessages(withdrawalHash), true);
......
......@@ -77,7 +77,10 @@ contract OptimismMintableERC20_Test is Bridge_Initializer {
assertEq(iface2, type(ILegacyMintableERC20).interfaceId);
assert(L2Token.supportsInterface(iface2));
bytes4 iface3 = L2Token.remoteToken.selector ^ L2Token.bridge.selector ^ L2Token.mint.selector ^ L2Token.burn.selector;
bytes4 iface3 = L2Token.remoteToken.selector ^
L2Token.bridge.selector ^
L2Token.mint.selector ^
L2Token.burn.selector;
assertEq(iface3, type(IOptimismMintableERC20).interfaceId);
assert(L2Token.supportsInterface(iface3));
}
......
......@@ -25,17 +25,10 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
address local = LibRLP.computeAddress(address(L2TokenFactory), 2);
vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated(
remote,
local
);
emit StandardL2TokenCreated(remote, local);
vm.expectEmit(true, true, true, true);
emit OptimismMintableERC20Created(
local,
remote,
alice
);
emit OptimismMintableERC20Created(local, remote, alice);
vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
......@@ -50,17 +43,10 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
address local = LibRLP.computeAddress(address(L2TokenFactory), 3);
vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated(
remote,
local
);
emit StandardL2TokenCreated(remote, local);
vm.expectEmit(true, true, true, true);
emit OptimismMintableERC20Created(
local,
remote,
alice
);
emit OptimismMintableERC20Created(local, remote, alice);
vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
......
......@@ -422,13 +422,8 @@ contract OptimismPortal_FinalizeWithdrawal_Test is Portal_Initializer {
gasLimit: gasLimit,
data: hex""
});
(
bytes32 stateRoot,
bytes32 storageRoot,
,
,
bytes memory withdrawalProof
) = ffi.getFinalizeWithdrawalTransactionInputs(insufficientGasTx);
(bytes32 stateRoot, bytes32 storageRoot, , , bytes memory withdrawalProof) = ffi
.getFinalizeWithdrawalTransactionInputs(insufficientGasTx);
Types.OutputRootProof memory outputRootProof = Types.OutputRootProof({
version: bytes32(0),
stateRoot: stateRoot,
......
......@@ -30,10 +30,9 @@ contract Proxy_Test is Test {
address alice = address(64);
bytes32 internal constant IMPLEMENTATION_KEY =
bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1);
bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1);
bytes32 internal constant OWNER_KEY =
bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1);
bytes32 internal constant OWNER_KEY = bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1);
Proxy proxy;
SimpleStorage simpleStorage;
......@@ -54,10 +53,7 @@ contract Proxy_Test is Test {
proxy.upgradeTo(address(6));
bytes32 key = vm.load(address(proxy), IMPLEMENTATION_KEY);
assertEq(
address(6),
Bytes32AddressLib.fromLast20Bytes(key)
);
assertEq(address(6), Bytes32AddressLib.fromLast20Bytes(key));
vm.prank(alice);
address impl = proxy.implementation();
......@@ -70,10 +66,7 @@ contract Proxy_Test is Test {
proxy.changeAdmin(address(6));
bytes32 key = vm.load(address(proxy), OWNER_KEY);
assertEq(
address(6),
Bytes32AddressLib.fromLast20Bytes(key)
);
assertEq(address(6), Bytes32AddressLib.fromLast20Bytes(key));
vm.prank(address(6));
address owner = proxy.admin();
......@@ -186,10 +179,7 @@ contract Proxy_Test is Test {
// match a function on the implementation.
vm.expectRevert("Proxy: delegatecall to new implementation contract failed");
vm.prank(alice);
proxy.upgradeToAndCall(
address(simpleStorage),
hex""
);
proxy.upgradeToAndCall(address(simpleStorage), hex"");
// The implementation address should have not
// updated because the call to `upgradeToAndCall`
......
......@@ -62,10 +62,7 @@ contract ProxyAdmin_Test is Test {
function test_setImplementationName() external {
vm.prank(alice);
admin.setImplementationName(address(1), "foo");
assertEq(
admin.implementationName(address(1)),
"foo"
);
assertEq(admin.implementationName(address(1)), "foo");
}
function test_onlyOwnerSetAddressManager() external {
......@@ -88,10 +85,7 @@ contract ProxyAdmin_Test is Test {
}
function test_proxyType() external {
assertEq(
uint256(admin.proxyType(address(proxy))),
uint256(ProxyAdmin.ProxyType.ERC1967)
);
assertEq(uint256(admin.proxyType(address(proxy))), uint256(ProxyAdmin.ProxyType.ERC1967));
assertEq(
uint256(admin.proxyType(address(chugsplash))),
uint256(ProxyAdmin.ProxyType.CHUGSPLASH)
......@@ -186,15 +180,9 @@ contract ProxyAdmin_Test is Test {
if (proxyType == ProxyAdmin.ProxyType.ERC1967) {
assertEq(Proxy(payable(_proxy)).admin(), address(128));
} else if (proxyType == ProxyAdmin.ProxyType.CHUGSPLASH) {
assertEq(
L1ChugSplashProxy(payable(_proxy)).getOwner(),
address(128)
);
assertEq(L1ChugSplashProxy(payable(_proxy)).getOwner(), address(128));
} else if (proxyType == ProxyAdmin.ProxyType.RESOLVED) {
assertEq(
addressManager.owner(),
address(128)
);
assertEq(addressManager.owner(), address(128));
} else {
assert(false);
}
......
......@@ -13,19 +13,58 @@ library LibRLP {
function computeAddress(address deployer, uint256 nonce) internal pure returns (address) {
// The integer zero is treated as an empty byte string, and as a result it only has a length prefix, 0x80, computed via 0x80 + 0.
// A one byte integer uses its own value as its length prefix, there is no additional "0x80 + length" prefix that comes before it.
if (nonce == 0x00) return keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, bytes1(0x80))).fromLast20Bytes();
if (nonce <= 0x7f) return keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, uint8(nonce))).fromLast20Bytes();
if (nonce == 0x00)
return
keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, bytes1(0x80)))
.fromLast20Bytes();
if (nonce <= 0x7f)
return
keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, uint8(nonce)))
.fromLast20Bytes();
// Nonces greater than 1 byte all follow a consistent encoding scheme, where each value is preceded by a prefix of 0x80 + length.
if (nonce <= type(uint8).max) return keccak256(abi.encodePacked(bytes1(0xd7), bytes1(0x94), deployer, bytes1(0x81), uint8(nonce))).fromLast20Bytes();
if (nonce <= type(uint16).max) return keccak256(abi.encodePacked(bytes1(0xd8), bytes1(0x94), deployer, bytes1(0x82), uint16(nonce))).fromLast20Bytes();
if (nonce <= type(uint24).max) return keccak256(abi.encodePacked(bytes1(0xd9), bytes1(0x94), deployer, bytes1(0x83), uint24(nonce))).fromLast20Bytes();
if (nonce <= type(uint8).max)
return
keccak256(
abi.encodePacked(
bytes1(0xd7),
bytes1(0x94),
deployer,
bytes1(0x81),
uint8(nonce)
)
).fromLast20Bytes();
if (nonce <= type(uint16).max)
return
keccak256(
abi.encodePacked(
bytes1(0xd8),
bytes1(0x94),
deployer,
bytes1(0x82),
uint16(nonce)
)
).fromLast20Bytes();
if (nonce <= type(uint24).max)
return
keccak256(
abi.encodePacked(
bytes1(0xd9),
bytes1(0x94),
deployer,
bytes1(0x83),
uint24(nonce)
)
).fromLast20Bytes();
// More details about RLP encoding can be found here: https://eth.wiki/fundamentals/rlp
// 0xda = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x84 ++ nonce)
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex)
// 0x84 = 0x80 + 0x04 (0x04 = the bytes length of the nonce, 4 bytes, in hex)
// We assume nobody can have a nonce large enough to require more than 32 bytes.
return keccak256(abi.encodePacked(bytes1(0xda), bytes1(0x94), deployer, bytes1(0x84), uint32(nonce))).fromLast20Bytes();
return
keccak256(
abi.encodePacked(bytes1(0xda), bytes1(0x94), deployer, bytes1(0x84), uint32(nonce))
).fromLast20Bytes();
}
}
......@@ -6,38 +6,23 @@ import { CommonTest } from "./CommonTest.t.sol";
contract RLPWriter_Test is CommonTest {
function test_writeString_empty() external {
assertEq(
RLPWriter.writeString(""),
hex"80"
);
assertEq(RLPWriter.writeString(""), hex"80");
}
function test_writeString_bytestring00() external {
assertEq(
RLPWriter.writeString("\u0000"),
hex"00"
);
assertEq(RLPWriter.writeString("\u0000"), hex"00");
}
function test_writeString_bytestring01() external {
assertEq(
RLPWriter.writeString("\u0001"),
hex"01"
);
assertEq(RLPWriter.writeString("\u0001"), hex"01");
}
function test_writeString_bytestring7f() external {
assertEq(
RLPWriter.writeString("\u007F"),
hex"7f"
);
assertEq(RLPWriter.writeString("\u007F"), hex"7f");
}
function test_writeString_shortstring() external {
assertEq(
RLPWriter.writeString("dog"),
hex"83646f67"
);
assertEq(RLPWriter.writeString("dog"), hex"83646f67");
}
function test_writeString_shortstring2() external {
......@@ -56,72 +41,47 @@ contract RLPWriter_Test is CommonTest {
function test_writeString_longstring2() external {
assertEq(
RLPWriter.writeString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mauris magna, suscipit sed vehicula non, iaculis faucibus tortor. Proin suscipit ultricies malesuada. Duis tortor elit, dictum quis tristique eu, ultrices at risus. Morbi a est imperdiet mi ullamcorper aliquet suscipit nec lorem. Aenean quis leo mollis, vulputate elit varius, consequat enim. Nulla ultrices turpis justo, et posuere urna consectetur nec. Proin non convallis metus. Donec tempor ipsum in mauris congue sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse convallis sem vel massa faucibus, eget lacinia lacus tempor. Nulla quis ultricies purus. Proin auctor rhoncus nibh condimentum mollis. Aliquam consequat enim at metus luctus, a eleifend purus egestas. Curabitur at nibh metus. Nam bibendum, neque at auctor tristique, lorem libero aliquet arcu, non interdum tellus lectus sit amet eros. Cras rhoncus, metus ac ornare cursus, dolor justo ultrices metus, at ullamcorper volutpat"),
RLPWriter.writeString(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mauris magna, suscipit sed vehicula non, iaculis faucibus tortor. Proin suscipit ultricies malesuada. Duis tortor elit, dictum quis tristique eu, ultrices at risus. Morbi a est imperdiet mi ullamcorper aliquet suscipit nec lorem. Aenean quis leo mollis, vulputate elit varius, consequat enim. Nulla ultrices turpis justo, et posuere urna consectetur nec. Proin non convallis metus. Donec tempor ipsum in mauris congue sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse convallis sem vel massa faucibus, eget lacinia lacus tempor. Nulla quis ultricies purus. Proin auctor rhoncus nibh condimentum mollis. Aliquam consequat enim at metus luctus, a eleifend purus egestas. Curabitur at nibh metus. Nam bibendum, neque at auctor tristique, lorem libero aliquet arcu, non interdum tellus lectus sit amet eros. Cras rhoncus, metus ac ornare cursus, dolor justo ultrices metus, at ullamcorper volutpat"
),
hex"b904004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20437572616269747572206d6175726973206d61676e612c20737573636970697420736564207665686963756c61206e6f6e2c20696163756c697320666175636962757320746f72746f722e2050726f696e20737573636970697420756c74726963696573206d616c6573756164612e204475697320746f72746f7220656c69742c2064696374756d2071756973207472697374697175652065752c20756c7472696365732061742072697375732e204d6f72626920612065737420696d70657264696574206d6920756c6c616d636f7270657220616c6971756574207375736369706974206e6563206c6f72656d2e2041656e65616e2071756973206c656f206d6f6c6c69732c2076756c70757461746520656c6974207661726975732c20636f6e73657175617420656e696d2e204e756c6c6120756c74726963657320747572706973206a7573746f2c20657420706f73756572652075726e6120636f6e7365637465747572206e65632e2050726f696e206e6f6e20636f6e76616c6c6973206d657475732e20446f6e65632074656d706f7220697073756d20696e206d617572697320636f6e67756520736f6c6c696369747564696e2e20566573746962756c756d20616e746520697073756d207072696d697320696e206661756369627573206f726369206c756374757320657420756c74726963657320706f737565726520637562696c69612043757261653b2053757370656e646973736520636f6e76616c6c69732073656d2076656c206d617373612066617563696275732c2065676574206c6163696e6961206c616375732074656d706f722e204e756c6c61207175697320756c747269636965732070757275732e2050726f696e20617563746f722072686f6e637573206e69626820636f6e64696d656e74756d206d6f6c6c69732e20416c697175616d20636f6e73657175617420656e696d206174206d65747573206c75637475732c206120656c656966656e6420707572757320656765737461732e20437572616269747572206174206e696268206d657475732e204e616d20626962656e64756d2c206e6571756520617420617563746f72207472697374697175652c206c6f72656d206c696265726f20616c697175657420617263752c206e6f6e20696e74657264756d2074656c6c7573206c65637475732073697420616d65742065726f732e20437261732072686f6e6375732c206d65747573206163206f726e617265206375727375732c20646f6c6f72206a7573746f20756c747269636573206d657475732c20617420756c6c616d636f7270657220766f6c7574706174"
);
}
function test_writeUint_zero() external {
assertEq(
RLPWriter.writeUint(0x0),
hex"80"
);
assertEq(RLPWriter.writeUint(0x0), hex"80");
}
function test_writeUint_smallint() external {
assertEq(
RLPWriter.writeUint(1),
hex"01"
);
assertEq(RLPWriter.writeUint(1), hex"01");
}
function test_writeUint_smallint2() external {
assertEq(
RLPWriter.writeUint(16),
hex"10"
);
assertEq(RLPWriter.writeUint(16), hex"10");
}
function test_writeUint_smallint3() external {
assertEq(
RLPWriter.writeUint(79),
hex"4f"
);
assertEq(RLPWriter.writeUint(79), hex"4f");
}
function test_writeUint_smallint4() external {
assertEq(
RLPWriter.writeUint(127),
hex"7f"
);
assertEq(RLPWriter.writeUint(127), hex"7f");
}
function test_writeUint_mediumint() external {
assertEq(
RLPWriter.writeUint(128),
hex"8180"
);
assertEq(RLPWriter.writeUint(128), hex"8180");
}
function test_writeUint_mediumint2() external {
assertEq(
RLPWriter.writeUint(1000),
hex"8203e8"
);
assertEq(RLPWriter.writeUint(1000), hex"8203e8");
}
function test_writeUint_mediumint3() external {
assertEq(
RLPWriter.writeUint(100000),
hex"830186a0"
);
assertEq(RLPWriter.writeUint(100000), hex"830186a0");
}
function test_writeList_empty() external {
assertEq(
RLPWriter.writeList(new bytes[](0)),
hex"c0"
);
assertEq(RLPWriter.writeList(new bytes[](0)), hex"c0");
}
function test_writeList_stringList() external {
......@@ -130,10 +90,7 @@ contract RLPWriter_Test is CommonTest {
list[1] = RLPWriter.writeString("god");
list[2] = RLPWriter.writeString("cat");
assertEq(
RLPWriter.writeList(list),
hex"cc83646f6783676f6483636174"
);
assertEq(RLPWriter.writeList(list), hex"cc83646f6783676f6483636174");
}
function test_writeList_multiList() external {
......@@ -145,10 +102,7 @@ contract RLPWriter_Test is CommonTest {
list[1] = RLPWriter.writeList(list2);
list[2] = RLPWriter.writeUint(1);
assertEq(
RLPWriter.writeList(list),
hex"c6827a77c10401"
);
assertEq(RLPWriter.writeList(list), hex"c6827a77c10401");
}
function test_writeList_shortListMax1() external {
......@@ -208,7 +162,6 @@ contract RLPWriter_Test is CommonTest {
);
}
function test_writeList_listoflists() external {
// [ [ [], [] ], [] ]
bytes[] memory list = new bytes[](2);
......@@ -220,10 +173,7 @@ contract RLPWriter_Test is CommonTest {
list[0] = RLPWriter.writeList(list2);
list[1] = RLPWriter.writeList(new bytes[](0));
assertEq(
RLPWriter.writeList(list),
hex"c4c2c0c0c0"
);
assertEq(RLPWriter.writeList(list), hex"c4c2c0c0c0");
}
function test_writeList_listoflists2() external {
......@@ -242,10 +192,7 @@ contract RLPWriter_Test is CommonTest {
list[2] = RLPWriter.writeList(list3);
assertEq(
RLPWriter.writeList(list),
hex"c7c0c1c0c3c0c1c0"
);
assertEq(RLPWriter.writeList(list), hex"c7c0c1c0c3c0c1c0");
}
function test_writeList_dictTest1() external {
......
......@@ -97,7 +97,7 @@ contract ResourceMetering_Test is CommonTest {
vm.roll(initialBlockNum + 1);
meter.use(0);
(uint128 postBaseFee,,) = meter.params();
(uint128 postBaseFee, , ) = meter.params();
// Base fee increases by 1/8 the difference
assertEq(postBaseFee, 1375000000);
}
......
......@@ -20,13 +20,9 @@ contract SafeCall_Test is CommonTest {
vm.assume(to != address(vm));
vm.assume(from != address(vm));
// don't call the console
vm.assume(
to != address(0x000000000000000000636F6e736F6c652e6c6f67)
);
vm.assume(to != address(0x000000000000000000636F6e736F6c652e6c6f67));
// don't call the create2 deployer
vm.assume(
to != address(0x4e59b44847b379578588920cA78FbF26c0B4956C)
);
vm.assume(to != address(0x4e59b44847b379578588920cA78FbF26c0B4956C));
// don't send funds to self
vm.assume(from != to);
......@@ -34,19 +30,10 @@ contract SafeCall_Test is CommonTest {
vm.deal(from, value);
assertEq(from.balance, value, "from balance not dealt");
vm.expectCall(
to,
value,
data
);
vm.expectCall(to, value, data);
vm.prank(from);
bool success = SafeCall.call(
to,
gas,
value,
data
);
bool success = SafeCall.call(to, gas, value, data);
assertEq(success, true, "call not successful");
assertEq(to.balance, value, "to balance received");
......
......@@ -27,10 +27,7 @@ contract Semver_Test is CommonTest {
* @notice Test the version getter
*/
function test_version() external {
assertEq(
semver.version(),
"7.8.0"
);
assertEq(semver.version(), "7.8.0");
}
/**
......@@ -43,9 +40,6 @@ contract Semver_Test is CommonTest {
vm.prank(alice);
proxy.upgradeTo(address(semver));
assertEq(
Semver(address(proxy)).version(),
"7.8.0"
);
assertEq(Semver(address(proxy)).version(), "7.8.0");
}
}
......@@ -8,17 +8,13 @@ import { L2StandardBridge } from "../L2/L2StandardBridge.sol";
import { Predeploys } from "../libraries/Predeploys.sol";
contract SequencerFeeVault_Test is Bridge_Initializer {
SequencerFeeVault vault =
SequencerFeeVault(payable(Predeploys.SEQUENCER_FEE_WALLET));
SequencerFeeVault vault = SequencerFeeVault(payable(Predeploys.SEQUENCER_FEE_WALLET));
address constant recipient = address(256);
function setUp() public override {
super.setUp();
vm.etch(
Predeploys.SEQUENCER_FEE_WALLET,
address(new SequencerFeeVault()).code
);
vm.etch(Predeploys.SEQUENCER_FEE_WALLET, address(new SequencerFeeVault()).code);
vm.store(
Predeploys.SEQUENCER_FEE_WALLET,
......@@ -28,33 +24,21 @@ contract SequencerFeeVault_Test is Bridge_Initializer {
}
function test_minWithdrawalAmount() external {
assertEq(
vault.MIN_WITHDRAWAL_AMOUNT(),
15 ether
);
assertEq(vault.MIN_WITHDRAWAL_AMOUNT(), 15 ether);
}
function test_constructor() external {
assertEq(
vault.l1FeeWallet(),
recipient
);
assertEq(vault.l1FeeWallet(), recipient);
}
function test_receive() external {
assertEq(
address(vault).balance,
0
);
assertEq(address(vault).balance, 0);
vm.prank(alice);
(bool success,) = address(vault).call{ value: 100 }(hex"");
(bool success, ) = address(vault).call{ value: 100 }(hex"");
assertEq(success, true);
assertEq(
address(vault).balance,
100
);
assertEq(address(vault).balance, 100);
}
function test_revertWithdraw() external {
......
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