Commit 01ed5651 authored by Maurelian's avatar Maurelian

ctb: Format forge tests with prettier

parent 1518a4f5
# Deps and test files # Deps and test files
node_modules node_modules
lib lib
contracts/test/*.t.sol
contracts/vendor/*.sol contracts/vendor/*.sol
# build output # build output
......
...@@ -142,10 +142,7 @@ contract L2OutputOracle_Initializer is CommonTest { ...@@ -142,10 +142,7 @@ contract L2OutputOracle_Initializer is CommonTest {
vm.label(address(oracle), "L2OutputOracle"); vm.label(address(oracle), "L2OutputOracle");
// Set the L2ToL1MessagePasser at the correct address // Set the L2ToL1MessagePasser at the correct address
vm.etch( vm.etch(Predeploys.L2_TO_L1_MESSAGE_PASSER, address(new L2ToL1MessagePasser()).code);
Predeploys.L2_TO_L1_MESSAGE_PASSER,
address(new L2ToL1MessagePasser()).code
);
vm.label(Predeploys.L2_TO_L1_MESSAGE_PASSER, "L2ToL1MessagePasser"); vm.label(Predeploys.L2_TO_L1_MESSAGE_PASSER, "L2ToL1MessagePasser");
} }
...@@ -185,10 +182,7 @@ contract Messenger_Initializer is L2OutputOracle_Initializer { ...@@ -185,10 +182,7 @@ contract Messenger_Initializer is L2OutputOracle_Initializer {
uint256 gasLimit uint256 gasLimit
); );
event SentMessageExtension1( event SentMessageExtension1(address indexed sender, uint256 value);
address indexed sender,
uint256 value
);
event MessagePassed( event MessagePassed(
uint256 indexed nonce, uint256 indexed nonce,
...@@ -273,12 +267,7 @@ contract Bridge_Initializer is Messenger_Initializer { ...@@ -273,12 +267,7 @@ contract Bridge_Initializer is Messenger_Initializer {
ERC20 BadL2Token; ERC20 BadL2Token;
OptimismMintableERC20 RemoteL1Token; OptimismMintableERC20 RemoteL1Token;
event ETHDepositInitiated( event ETHDepositInitiated(address indexed from, address indexed to, uint256 amount, bytes data);
address indexed from,
address indexed to,
uint256 amount,
bytes data
);
event ETHWithdrawalFinalized( event ETHWithdrawalFinalized(
address indexed from, address indexed from,
...@@ -332,19 +321,9 @@ contract Bridge_Initializer is Messenger_Initializer { ...@@ -332,19 +321,9 @@ contract Bridge_Initializer is Messenger_Initializer {
bytes data bytes data
); );
event ETHBridgeInitiated( event ETHBridgeInitiated(address indexed from, address indexed to, uint256 amount, bytes data);
address indexed from,
address indexed to,
uint256 amount,
bytes data
);
event ETHBridgeFinalized( event ETHBridgeFinalized(address indexed from, address indexed to, uint256 amount, bytes data);
address indexed from,
address indexed to,
uint256 amount,
bytes data
);
event ERC20BridgeInitiated( event ERC20BridgeInitiated(
address indexed localToken, address indexed localToken,
...@@ -400,9 +379,7 @@ contract Bridge_Initializer is Messenger_Initializer { ...@@ -400,9 +379,7 @@ contract Bridge_Initializer is Messenger_Initializer {
Predeploys.L2_STANDARD_BRIDGE Predeploys.L2_STANDARD_BRIDGE
); );
vm.etch(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY, address(factory).code); vm.etch(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY, address(factory).code);
L2TokenFactory = OptimismMintableERC20Factory( L2TokenFactory = OptimismMintableERC20Factory(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY);
Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY
);
vm.etch(Predeploys.LEGACY_ERC20_ETH, address(new LegacyERC20ETH()).code); vm.etch(Predeploys.LEGACY_ERC20_ETH, address(new LegacyERC20ETH()).code);
...@@ -571,9 +548,10 @@ contract FFIInterface is Test { ...@@ -571,9 +548,10 @@ contract FFIInterface is Test {
return abi.decode(result, (bytes32)); return abi.decode(result, (bytes32));
} }
function encodeDepositTransaction( function encodeDepositTransaction(Types.UserDepositTransaction calldata txn)
Types.UserDepositTransaction calldata txn external
) external returns (bytes memory) { returns (bytes memory)
{
string[] memory cmds = new string[](12); string[] memory cmds = new string[](12);
cmds[0] = "node"; cmds[0] = "node";
cmds[1] = "dist/scripts/differential-testing.js"; cmds[1] = "dist/scripts/differential-testing.js";
...@@ -651,18 +629,19 @@ contract Reverter { ...@@ -651,18 +629,19 @@ contract Reverter {
// Useful for testing reentrancy guards // Useful for testing reentrancy guards
contract CallerCaller { contract CallerCaller {
event WhatHappened( event WhatHappened(bool success, bytes returndata);
bool success,
bytes returndata
);
fallback() external { fallback() external {
(bool success, bytes memory returndata) = msg.sender.call(msg.data); (bool success, bytes memory returndata) = msg.sender.call(msg.data);
emit WhatHappened(success, returndata); emit WhatHappened(success, returndata);
assembly { assembly {
switch success switch success
case 0 { revert(add(returndata, 0x20), mload(returndata)) } case 0 {
default { return(add(returndata, 0x20), mload(returndata)) } revert(add(returndata, 0x20), mload(returndata))
}
default {
return(add(returndata, 0x20), mload(returndata))
}
} }
} }
} }
...@@ -30,17 +30,11 @@ contract CrossDomainOwnable_Test is CommonTest { ...@@ -30,17 +30,11 @@ contract CrossDomainOwnable_Test is CommonTest {
// Check that making a call can set the value properly // Check that making a call can set the value properly
function test_onlyOwner() external { function test_onlyOwner() external {
assertEq( assertEq(setter.value(), 0);
setter.value(),
0
);
vm.prank(AddressAliasHelper.applyL1ToL2Alias(setter.owner())); vm.prank(AddressAliasHelper.applyL1ToL2Alias(setter.owner()));
setter.set(1); setter.set(1);
assertEq( assertEq(setter.value(), 1);
setter.value(),
1
);
} }
} }
...@@ -63,10 +57,7 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer { ...@@ -63,10 +57,7 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer {
0, 0,
10000, 10000,
false, false,
abi.encodeWithSelector( abi.encodeWithSelector(XDomainSetter.set.selector, 1)
XDomainSetter.set.selector,
1
)
); );
// Simulate the operation of the `op-node` by parsing data // Simulate the operation of the `op-node` by parsing data
...@@ -79,19 +70,13 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer { ...@@ -79,19 +70,13 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer {
// It is the expected topic // It is the expected topic
bytes32 topic = log.topics[0]; bytes32 topic = log.topics[0];
assertEq( assertEq(topic, keccak256("TransactionDeposited(address,address,uint256,bytes)"));
topic,
keccak256("TransactionDeposited(address,address,uint256,bytes)")
);
// from is indexed and the first argument to the event. // from is indexed and the first argument to the event.
bytes32 _from = log.topics[1]; bytes32 _from = log.topics[1];
address from = Bytes32AddressLib.fromLast20Bytes(_from); address from = Bytes32AddressLib.fromLast20Bytes(_from);
assertEq( assertEq(AddressAliasHelper.undoL1ToL2Alias(from), alice);
AddressAliasHelper.undoL1ToL2Alias(from),
alice
);
// Make a call from the "from" value received from the log. // Make a call from the "from" value received from the log.
// In theory the opaque data could be parsed from the log // In theory the opaque data could be parsed from the log
...@@ -99,9 +84,6 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer { ...@@ -99,9 +84,6 @@ contract CrossDomainOwnableThroughPortal_Test is Portal_Initializer {
// directly on the setter is good enough. // directly on the setter is good enough.
vm.prank(from); vm.prank(from);
setter.set(1); setter.set(1);
assertEq( assertEq(setter.value(), 1);
setter.value(),
1
);
} }
} }
...@@ -19,7 +19,7 @@ contract XDomainSetter2 is CrossDomainOwnable2 { ...@@ -19,7 +19,7 @@ contract XDomainSetter2 is CrossDomainOwnable2 {
contract CrossDomainOwnable2_Test is Messenger_Initializer { contract CrossDomainOwnable2_Test is Messenger_Initializer {
XDomainSetter2 setter; XDomainSetter2 setter;
function setUp() override public { function setUp() public override {
super.setUp(); super.setUp();
vm.prank(alice); vm.prank(alice);
setter = new XDomainSetter2(); setter = new XDomainSetter2();
...@@ -47,10 +47,7 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer { ...@@ -47,10 +47,7 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer {
address target = address(setter); address target = address(setter);
uint256 value = 0; uint256 value = 0;
uint256 minGasLimit = 0; uint256 minGasLimit = 0;
bytes memory message = abi.encodeWithSelector( bytes memory message = abi.encodeWithSelector(XDomainSetter2.set.selector, 1);
XDomainSetter2.set.selector,
1
);
bytes32 hash = Hashing.hashCrossDomainMessage( bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(nonce, 1), Encoding.encodeVersionedNonce(nonce, 1),
...@@ -76,10 +73,7 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer { ...@@ -76,10 +73,7 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer {
message message
); );
assertEq( assertEq(setter.value(), 0);
setter.value(),
0
);
} }
function test_onlyOwner() external { function test_onlyOwner() external {
...@@ -94,15 +88,9 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer { ...@@ -94,15 +88,9 @@ contract CrossDomainOwnable2_Test is Messenger_Initializer {
address(setter), address(setter),
0, 0,
0, 0,
abi.encodeWithSelector( abi.encodeWithSelector(XDomainSetter2.set.selector, 2)
XDomainSetter2.set.selector,
2
)
); );
assertEq( assertEq(setter.value(), 2);
setter.value(),
2
);
} }
} }
...@@ -21,9 +21,6 @@ contract DeployerWhitelist_Test is CommonTest { ...@@ -21,9 +21,6 @@ contract DeployerWhitelist_Test is CommonTest {
vm.prank(list.owner()); vm.prank(list.owner());
list.setOwner(address(1)); list.setOwner(address(1));
assertEq( assertEq(bytes32(uint256(1)), vm.load(address(list), bytes32(uint256(0))));
bytes32(uint256(1)),
vm.load(address(list), bytes32(uint256(0)))
);
} }
} }
...@@ -22,15 +22,9 @@ contract Encoding_Test is CommonTest { ...@@ -22,15 +22,9 @@ contract Encoding_Test is CommonTest {
uint256 nonce = uint256(Encoding.encodeVersionedNonce(_nonce, _version)); uint256 nonce = uint256(Encoding.encodeVersionedNonce(_nonce, _version));
(uint256 decodedNonce, uint256 decodedVersion) = ffi.decodeVersionedNonce(nonce); (uint256 decodedNonce, uint256 decodedVersion) = ffi.decodeVersionedNonce(nonce);
assertEq( assertEq(_version, uint16(decodedVersion));
_version,
uint16(decodedVersion)
);
assertEq( assertEq(_nonce, uint240(decodedNonce));
_nonce,
uint240(decodedNonce)
);
} }
function test_encodeCrossDomainMessage_differential( function test_encodeCrossDomainMessage_differential(
...@@ -91,9 +85,6 @@ contract Encoding_Test is CommonTest { ...@@ -91,9 +85,6 @@ contract Encoding_Test is CommonTest {
bytes memory txn = Encoding.encodeDepositTransaction(t); bytes memory txn = Encoding.encodeDepositTransaction(t);
bytes memory _txn = ffi.encodeDepositTransaction(t); bytes memory _txn = ffi.encodeDepositTransaction(t);
assertEq( assertEq(txn, _txn);
txn,
_txn
);
} }
} }
...@@ -7,7 +7,6 @@ import { L1Block } from "../L2/L1Block.sol"; ...@@ -7,7 +7,6 @@ import { L1Block } from "../L2/L1Block.sol";
import { Predeploys } from "../libraries/Predeploys.sol"; import { Predeploys } from "../libraries/Predeploys.sol";
contract GasPriceOracle_Test is CommonTest { contract GasPriceOracle_Test is CommonTest {
event OverheadUpdated(uint256); event OverheadUpdated(uint256);
event ScalarUpdated(uint256); event ScalarUpdated(uint256);
event DecimalsUpdated(uint256); event DecimalsUpdated(uint256);
...@@ -18,10 +17,7 @@ contract GasPriceOracle_Test is CommonTest { ...@@ -18,10 +17,7 @@ contract GasPriceOracle_Test is CommonTest {
function setUp() external { function setUp() external {
// place the L1Block contract at the predeploy address // place the L1Block contract at the predeploy address
vm.etch( vm.etch(Predeploys.L1_BLOCK_ATTRIBUTES, address(new L1Block()).code);
Predeploys.L1_BLOCK_ATTRIBUTES,
address(new L1Block()).code
);
l1Block = L1Block(Predeploys.L1_BLOCK_ATTRIBUTES); l1Block = L1Block(Predeploys.L1_BLOCK_ATTRIBUTES);
depositor = l1Block.DEPOSITOR_ACCOUNT(); depositor = l1Block.DEPOSITOR_ACCOUNT();
...@@ -39,13 +35,7 @@ contract GasPriceOracle_Test is CommonTest { ...@@ -39,13 +35,7 @@ contract GasPriceOracle_Test is CommonTest {
uint64 sequenceNumber = 0; uint64 sequenceNumber = 0;
vm.prank(depositor); vm.prank(depositor);
l1Block.setL1BlockValues( l1Block.setL1BlockValues(number, timestamp, basefee, hash, sequenceNumber);
number,
timestamp,
basefee,
hash,
sequenceNumber
);
} }
function test_owner() external { function test_owner() external {
...@@ -57,26 +47,17 @@ contract GasPriceOracle_Test is CommonTest { ...@@ -57,26 +47,17 @@ contract GasPriceOracle_Test is CommonTest {
// the overhead is at slot 3 // the overhead is at slot 3
vm.prank(gasOracle.owner()); vm.prank(gasOracle.owner());
gasOracle.setOverhead(456); gasOracle.setOverhead(456);
assertEq( assertEq(456, uint256(vm.load(address(gasOracle), bytes32(uint256(3)))));
456,
uint256(vm.load(address(gasOracle), bytes32(uint256(3))))
);
// scalar is at slot 4 // scalar is at slot 4
vm.prank(gasOracle.owner()); vm.prank(gasOracle.owner());
gasOracle.setScalar(333); gasOracle.setScalar(333);
assertEq( assertEq(333, uint256(vm.load(address(gasOracle), bytes32(uint256(4)))));
333,
uint256(vm.load(address(gasOracle), bytes32(uint256(4))))
);
// decimals is at slot 5 // decimals is at slot 5
vm.prank(gasOracle.owner()); vm.prank(gasOracle.owner());
gasOracle.setDecimals(222); gasOracle.setDecimals(222);
assertEq( assertEq(222, uint256(vm.load(address(gasOracle), bytes32(uint256(5)))));
222,
uint256(vm.load(address(gasOracle), bytes32(uint256(5))))
);
} }
function test_l1BaseFee() external { function test_l1BaseFee() external {
...@@ -99,10 +80,7 @@ contract GasPriceOracle_Test is CommonTest { ...@@ -99,10 +80,7 @@ contract GasPriceOracle_Test is CommonTest {
function test_setGasPriceReverts() external { function test_setGasPriceReverts() external {
vm.prank(gasOracle.owner()); vm.prank(gasOracle.owner());
(bool success, bytes memory returndata) = address(gasOracle).call( (bool success, bytes memory returndata) = address(gasOracle).call(
abi.encodeWithSignature( abi.encodeWithSignature("setGasPrice(uint256)", 1)
"setGasPrice(uint256)",
1
)
); );
assertEq(success, false); assertEq(success, false);
...@@ -112,10 +90,7 @@ contract GasPriceOracle_Test is CommonTest { ...@@ -112,10 +90,7 @@ contract GasPriceOracle_Test is CommonTest {
function test_setL1BaseFeeReverts() external { function test_setL1BaseFeeReverts() external {
vm.prank(gasOracle.owner()); vm.prank(gasOracle.owner());
(bool success, bytes memory returndata) = address(gasOracle).call( (bool success, bytes memory returndata) = address(gasOracle).call(
abi.encodeWithSignature( abi.encodeWithSignature("setL1BaseFee(uint256)", 1)
"setL1BaseFee(uint256)",
1
)
); );
assertEq(success, false); assertEq(success, false);
......
...@@ -17,10 +17,7 @@ contract Hashing_Test is CommonTest { ...@@ -17,10 +17,7 @@ contract Hashing_Test is CommonTest {
0x1 0x1
); );
assertEq( assertEq(sourceHash, 0xf923fb07134d7d287cb52c770cc619e17e82606c21a875c92f4c63b65280a5cc);
sourceHash,
0xf923fb07134d7d287cb52c770cc619e17e82606c21a875c92f4c63b65280a5cc
);
} }
function test_hashCrossDomainMessage_differential( function test_hashCrossDomainMessage_differential(
...@@ -65,24 +62,10 @@ contract Hashing_Test is CommonTest { ...@@ -65,24 +62,10 @@ contract Hashing_Test is CommonTest {
bytes memory _data bytes memory _data
) external { ) external {
bytes32 hash = Hashing.hashWithdrawal( bytes32 hash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction( Types.WithdrawalTransaction(_nonce, _sender, _target, _value, _gasLimit, _data)
_nonce,
_sender,
_target,
_value,
_gasLimit,
_data
)
); );
bytes32 _hash = ffi.hashWithdrawal( bytes32 _hash = ffi.hashWithdrawal(_nonce, _sender, _target, _value, _gasLimit, _data);
_nonce,
_sender,
_target,
_value,
_gasLimit,
_data
);
assertEq(hash, _hash); assertEq(hash, _hash);
} }
......
...@@ -16,7 +16,13 @@ contract L1BlockTest is CommonTest { ...@@ -16,7 +16,13 @@ contract L1BlockTest is CommonTest {
lb.setL1BlockValues(uint64(1), uint64(2), 3, NON_ZERO_HASH, uint64(4)); 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); vm.prank(depositor);
lb.setL1BlockValues(n, t, b, h, s); lb.setL1BlockValues(n, t, b, h, s);
assertEq(lb.number(), n); assertEq(lb.number(), n);
...@@ -48,6 +54,12 @@ contract L1BlockTest is CommonTest { ...@@ -48,6 +54,12 @@ contract L1BlockTest is CommonTest {
function test_updateValues() external { function test_updateValues() external {
vm.prank(depositor); 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 { ...@@ -144,7 +144,9 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender))); vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.prank(address(op)); 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( L1Messenger.relayMessage(
0, // nonce 0, // nonce
sender, sender,
...@@ -168,7 +170,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -168,7 +170,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.expectEmit(true, true, true, true); 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); emit RelayedMessage(hash);
...@@ -196,11 +205,25 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -196,11 +205,25 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.prank(address(op)); vm.prank(address(op));
vm.expectRevert("CrossDomainMessenger: message cannot be replayed"); 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.store(address(op), 0, bytes32(abi.encode(sender)));
vm.expectRevert("CrossDomainMessenger: message cannot be replayed"); 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 // 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 { ...@@ -212,7 +235,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.expectRevert( vm.expectRevert(
"CrossDomainMessenger: value must be zero unless message is from a system address" "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 // relayMessage: the xDomainMessageSender is reset to the original value
...@@ -224,7 +254,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -224,7 +254,14 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender))); vm.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.prank(address(op)); 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"); vm.expectRevert("CrossDomainMessenger: xDomainMessageSender is not set");
L1Messenger.xDomainMessageSender(); L1Messenger.xDomainMessageSender();
...@@ -248,13 +285,20 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -248,13 +285,20 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
vm.expectCall(target, hex"1111"); 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.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.etch(target, address(new Reverter()).code); vm.etch(target, address(new Reverter()).code);
vm.deal(address(op), value); vm.deal(address(op), value);
vm.prank(address(op)); vm.prank(address(op));
L1Messenger.relayMessage{value: value}( L1Messenger.relayMessage{ value: value }(
Encoding.encodeVersionedNonce(0, 1), // nonce Encoding.encodeVersionedNonce(0, 1), // nonce
sender, sender,
target, target,
...@@ -303,14 +347,24 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -303,14 +347,24 @@ contract L1CrossDomainMessenger_Test is Messenger_Initializer {
hex"1111" 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.store(address(op), bytes32(senderSlotIndex), bytes32(abi.encode(sender)));
vm.etch(target, address(new CallerCaller()).code); vm.etch(target, address(new CallerCaller()).code);
vm.expectEmit(true, true, true, true, target); 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.prank(address(op));
vm.expectCall(target, message); vm.expectCall(target, message);
......
...@@ -21,20 +21,11 @@ contract L1StandardBridge_Getter_Test is Bridge_Initializer { ...@@ -21,20 +21,11 @@ contract L1StandardBridge_Getter_Test is Bridge_Initializer {
contract L1StandardBridge_Initialize_Test is Bridge_Initializer { contract L1StandardBridge_Initialize_Test is Bridge_Initializer {
function test_initialize_success() external { function test_initialize_success() external {
assertEq( assertEq(address(L1Bridge.messenger()), address(L1Messenger));
address(L1Bridge.messenger()),
address(L1Messenger)
);
assertEq( assertEq(address(L1Bridge.otherBridge()), Predeploys.L2_STANDARD_BRIDGE);
address(L1Bridge.otherBridge()),
Predeploys.L2_STANDARD_BRIDGE
);
assertEq( assertEq(address(L2Bridge), Predeploys.L2_STANDARD_BRIDGE);
address(L2Bridge),
Predeploys.L2_STANDARD_BRIDGE
);
} }
} }
...@@ -66,7 +57,7 @@ contract L1StandardBridge_Receive_Test is Bridge_Initializer { ...@@ -66,7 +57,7 @@ contract L1StandardBridge_Receive_Test is Bridge_Initializer {
); );
vm.prank(alice, alice); vm.prank(alice, alice);
(bool success,) = address(L1Bridge).call{ value: 100 }(hex""); (bool success, ) = address(L1Bridge).call{ value: 100 }(hex"");
assertEq(success, true); assertEq(success, true);
assertEq(address(op).balance, 100); assertEq(address(op).balance, 100);
} }
...@@ -137,12 +128,7 @@ contract L1StandardBridge_DepositETHTo_Test is Bridge_Initializer { ...@@ -137,12 +128,7 @@ contract L1StandardBridge_DepositETHTo_Test is Bridge_Initializer {
// depositETHTo on the L1 bridge should be called // depositETHTo on the L1 bridge should be called
vm.expectCall( vm.expectCall(
address(L1Bridge), address(L1Bridge),
abi.encodeWithSelector( abi.encodeWithSelector(L1Bridge.depositETHTo.selector, bob, 1000, hex"dead")
L1Bridge.depositETHTo.selector,
bob,
1000,
hex"dead"
)
); );
// the L1 bridge should call // the L1 bridge should call
...@@ -176,6 +162,7 @@ contract L1StandardBridge_DepositETHTo_TestFail is Bridge_Initializer {} ...@@ -176,6 +162,7 @@ contract L1StandardBridge_DepositETHTo_TestFail is Bridge_Initializer {}
contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer { contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
using stdStorage for StdStorage; using stdStorage for StdStorage;
// depositERC20 // depositERC20
// - updates bridge.deposits // - updates bridge.deposits
// - emits ERC20DepositInitiated // - emits ERC20DepositInitiated
...@@ -183,14 +170,7 @@ contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer { ...@@ -183,14 +170,7 @@ contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
// - only callable by EOA // - only callable by EOA
function test_depositERC20_succeeds() external { function test_depositERC20_succeeds() external {
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit ERC20DepositInitiated( emit ERC20DepositInitiated(address(L1Token), address(L2Token), alice, alice, 100, hex"");
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
deal(address(L1Token), alice, 100000, true); deal(address(L1Token), alice, 100000, true);
...@@ -201,24 +181,13 @@ contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer { ...@@ -201,24 +181,13 @@ contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
// to itself // to itself
vm.expectCall( vm.expectCall(
address(L1Token), address(L1Token),
abi.encodeWithSelector( abi.encodeWithSelector(ERC20.transferFrom.selector, alice, address(L1Bridge), 100)
ERC20.transferFrom.selector,
alice,
address(L1Bridge),
100
)
); );
// TODO: optimismPortal.depositTransaction call + event // TODO: optimismPortal.depositTransaction call + event
vm.prank(alice); vm.prank(alice);
L1Bridge.depositERC20( L1Bridge.depositERC20(address(L1Token), address(L2Token), 100, 10000, hex"");
address(L1Token),
address(L2Token),
100,
10000,
hex""
);
assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 100); assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 100);
} }
...@@ -231,13 +200,7 @@ contract L1StandardBridge_DepositERC20_TestFail is Bridge_Initializer { ...@@ -231,13 +200,7 @@ contract L1StandardBridge_DepositERC20_TestFail is Bridge_Initializer {
vm.expectRevert("StandardBridge: function can only be called from an EOA"); vm.expectRevert("StandardBridge: function can only be called from an EOA");
vm.prank(alice, alice); vm.prank(alice, alice);
L1Bridge.depositERC20( L1Bridge.depositERC20(address(0), address(0), 100, 100, hex"");
address(0),
address(0),
100,
100,
hex""
);
} }
} }
...@@ -249,14 +212,7 @@ contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer { ...@@ -249,14 +212,7 @@ contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer {
// - callable by a contract // - callable by a contract
function test_depositERC20To_success() external { function test_depositERC20To_success() external {
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit ERC20DepositInitiated( emit ERC20DepositInitiated(address(L1Token), address(L2Token), alice, bob, 1000, hex"");
address(L1Token),
address(L2Token),
alice,
bob,
1000,
hex""
);
deal(address(L1Token), alice, 100000, true); deal(address(L1Token), alice, 100000, true);
...@@ -265,23 +221,11 @@ contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer { ...@@ -265,23 +221,11 @@ contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer {
vm.expectCall( vm.expectCall(
address(L1Token), address(L1Token),
abi.encodeWithSelector( abi.encodeWithSelector(ERC20.transferFrom.selector, alice, address(L1Bridge), 1000)
ERC20.transferFrom.selector,
alice,
address(L1Bridge),
1000
)
); );
vm.prank(alice); vm.prank(alice);
L1Bridge.depositERC20To( L1Bridge.depositERC20To(address(L1Token), address(L2Token), bob, 1000, 10000, hex"");
address(L1Token),
address(L2Token),
bob,
1000,
10000,
hex""
);
assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 1000); assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 1000);
} }
...@@ -297,17 +241,9 @@ contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer { ...@@ -297,17 +241,9 @@ contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer {
uint256 aliceBalance = alice.balance; uint256 aliceBalance = alice.balance;
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit ETHWithdrawalFinalized( emit ETHWithdrawalFinalized(alice, alice, 100, hex"");
alice,
alice,
100,
hex""
);
vm.expectCall( vm.expectCall(alice, hex"");
alice,
hex""
);
vm.mockCall( vm.mockCall(
address(L1Bridge.messenger()), address(L1Bridge.messenger()),
...@@ -317,12 +253,7 @@ contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer { ...@@ -317,12 +253,7 @@ contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer {
// ensure that the messenger has ETH to call with // ensure that the messenger has ETH to call with
vm.deal(address(L1Bridge.messenger()), 100); vm.deal(address(L1Bridge.messenger()), 100);
vm.prank(address(L1Bridge.messenger())); vm.prank(address(L1Bridge.messenger()));
L1Bridge.finalizeETHWithdrawal{ value: 100 }( L1Bridge.finalizeETHWithdrawal{ value: 100 }(alice, alice, 100, hex"");
alice,
alice,
100,
hex""
);
assertEq(address(L1Bridge.messenger()).balance, 0); assertEq(address(L1Bridge.messenger()).balance, 0);
assertEq(aliceBalance + 100, alice.balance); assertEq(aliceBalance + 100, alice.balance);
...@@ -353,22 +284,11 @@ contract L1StandardBridge_FinalizeERC20Withdrawal_Test is Bridge_Initializer { ...@@ -353,22 +284,11 @@ contract L1StandardBridge_FinalizeERC20Withdrawal_Test is Bridge_Initializer {
assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 100); assertEq(L1Bridge.deposits(address(L1Token), address(L2Token)), 100);
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit ERC20WithdrawalFinalized( emit ERC20WithdrawalFinalized(address(L1Token), address(L2Token), alice, alice, 100, hex"");
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
vm.expectCall( vm.expectCall(
address(L1Token), address(L1Token),
abi.encodeWithSelector( abi.encodeWithSelector(ERC20.transfer.selector, alice, 100)
ERC20.transfer.selector,
alice,
100
)
); );
vm.mockCall( vm.mockCall(
...@@ -431,7 +351,9 @@ contract L1StandardBridge_FinalizeERC20Withdrawal_TestFail is Bridge_Initializer ...@@ -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 // Todo: move these next two contracts into a test file specific to the direction agnostic
// StandardBridge interface // StandardBridge interface
contract L1StandardBridge_FinalizeBridgeETH_Test is Bridge_Initializer {} contract L1StandardBridge_FinalizeBridgeETH_Test is Bridge_Initializer {
}
contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer { contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
function test_finalizeBridgeETH_revert_incorrectValue() external { function test_finalizeBridgeETH_revert_incorrectValue() external {
...@@ -444,12 +366,7 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer { ...@@ -444,12 +366,7 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
vm.deal(messenger, 100); vm.deal(messenger, 100);
vm.prank(messenger); vm.prank(messenger);
vm.expectRevert("StandardBridge: amount sent does not match amount required"); vm.expectRevert("StandardBridge: amount sent does not match amount required");
L1Bridge.finalizeBridgeETH{value: 50}( L1Bridge.finalizeBridgeETH{ value: 50 }(alice, alice, 100, hex"");
alice,
alice,
100,
hex""
);
} }
function test_finalizeBridgeETH_revert_sendToSelf() external { function test_finalizeBridgeETH_revert_sendToSelf() external {
...@@ -462,12 +379,7 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer { ...@@ -462,12 +379,7 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
vm.deal(messenger, 100); vm.deal(messenger, 100);
vm.prank(messenger); vm.prank(messenger);
vm.expectRevert("StandardBridge: cannot send to self"); vm.expectRevert("StandardBridge: cannot send to self");
L1Bridge.finalizeBridgeETH{value: 100}( L1Bridge.finalizeBridgeETH{ value: 100 }(alice, address(L1Bridge), 100, hex"");
alice,
address(L1Bridge),
100,
hex""
);
} }
function test_finalizeBridgeETH_revert_sendToMessenger() external { function test_finalizeBridgeETH_revert_sendToMessenger() external {
...@@ -480,11 +392,6 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer { ...@@ -480,11 +392,6 @@ contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
vm.deal(messenger, 100); vm.deal(messenger, 100);
vm.prank(messenger); vm.prank(messenger);
vm.expectRevert("StandardBridge: cannot send to messenger"); vm.expectRevert("StandardBridge: cannot send to messenger");
L1Bridge.finalizeBridgeETH{value: 100}( L1Bridge.finalizeBridgeETH{ value: 100 }(alice, messenger, 100, hex"");
alice,
messenger,
100,
hex""
);
} }
} }
...@@ -32,10 +32,7 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -32,10 +32,7 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
function test_L2MessengerMessageVersion() external { function test_L2MessengerMessageVersion() external {
(, uint16 version) = Encoding.decodeVersionedNonce(L2Messenger.messageNonce()); (, uint16 version) = Encoding.decodeVersionedNonce(L2Messenger.messageNonce());
assertEq( assertEq(version, L2Messenger.MESSAGE_VERSION());
version,
L2Messenger.MESSAGE_VERSION()
);
} }
function test_L2MessengerSendMessage() external { function test_L2MessengerSendMessage() external {
...@@ -83,10 +80,7 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -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));
L2Messenger.sendMessage(recipient, hex"aa", uint32(500_000)); L2Messenger.sendMessage(recipient, hex"aa", uint32(500_000));
// the nonce increments for each message sent // the nonce increments for each message sent
assertEq( assertEq(nonce + 2, L2Messenger.messageNonce());
nonce + 2,
L2Messenger.messageNonce()
);
} }
function test_L2MessengerXDomainSenderReverts() external { function test_L2MessengerXDomainSenderReverts() external {
...@@ -101,7 +95,9 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -101,7 +95,9 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
vm.prank(caller); 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( L2Messenger.relayMessage(
0, // nonce 0, // nonce
sender, sender,
...@@ -158,7 +154,14 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -158,7 +154,14 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
vm.prank(caller); vm.prank(caller);
vm.expectRevert("CrossDomainMessenger: message cannot be replayed"); 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 // relayMessage: the xDomainMessageSender is reset to the original value
...@@ -168,7 +171,14 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -168,7 +171,14 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
address caller = AddressAliasHelper.applyL1ToL2Alias(address(L1Messenger)); address caller = AddressAliasHelper.applyL1ToL2Alias(address(L1Messenger));
vm.prank(caller); 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"); vm.expectRevert("CrossDomainMessenger: xDomainMessageSender is not set");
L2Messenger.xDomainMessageSender(); L2Messenger.xDomainMessageSender();
...@@ -191,12 +201,19 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -191,12 +201,19 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
address caller = AddressAliasHelper.applyL1ToL2Alias(address(L1Messenger)); address caller = AddressAliasHelper.applyL1ToL2Alias(address(L1Messenger));
uint256 value = 100; 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.etch(target, address(new Reverter()).code);
vm.deal(address(caller), value); vm.deal(address(caller), value);
vm.prank(caller); vm.prank(caller);
L2Messenger.relayMessage{value: value}( L2Messenger.relayMessage{ value: value }(
Encoding.encodeVersionedNonce(0, 1), // nonce Encoding.encodeVersionedNonce(0, 1), // nonce
sender, sender,
target, target,
...@@ -246,13 +263,23 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer { ...@@ -246,13 +263,23 @@ contract L2CrossDomainMessenger_Test is Messenger_Initializer {
hex"1111" 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.etch(target, address(new CallerCaller()).code);
vm.expectEmit(true, true, true, true, target); 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.prank(caller);
vm.expectCall(target, message); vm.expectCall(target, message);
......
...@@ -29,9 +29,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer { ...@@ -29,9 +29,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
} }
function testCannot_constructWithBadTimestamp() external { function testCannot_constructWithBadTimestamp() external {
vm.expectRevert( vm.expectRevert("L2OutputOracle: starting L2 timestamp must be less than current time");
"L2OutputOracle: starting L2 timestamp must be less than current time"
);
new L2OutputOracle( new L2OutputOracle(
submissionInterval, submissionInterval,
...@@ -78,7 +76,9 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer { ...@@ -78,7 +76,9 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
assertEq(proposal.timestamp, block.timestamp); assertEq(proposal.timestamp, block.timestamp);
// The block number is too low: // 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); oracle.getL2Output(0);
// The block number is larger than the latest proposed output: // The block number is larger than the latest proposed output:
...@@ -292,9 +292,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer { ...@@ -292,9 +292,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
test_proposingAnotherOutput(); test_proposingAnotherOutput();
uint256 latestBlockNumber = oracle.latestBlockNumber(); uint256 latestBlockNumber = oracle.latestBlockNumber();
Types.OutputProposal memory proposalToDelete = oracle.getL2Output( Types.OutputProposal memory proposalToDelete = oracle.getL2Output(latestBlockNumber);
latestBlockNumber
);
Types.OutputProposal memory newLatestOutput = oracle.getL2Output( Types.OutputProposal memory newLatestOutput = oracle.getL2Output(
latestBlockNumber - submissionInterval latestBlockNumber - submissionInterval
); );
...@@ -334,9 +332,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer { ...@@ -334,9 +332,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
test_proposingAnotherOutput(); test_proposingAnotherOutput();
uint256 previousBlockNumber = oracle.latestBlockNumber() - submissionInterval; uint256 previousBlockNumber = oracle.latestBlockNumber() - submissionInterval;
Types.OutputProposal memory proposalToDelete = oracle.getL2Output( Types.OutputProposal memory proposalToDelete = oracle.getL2Output(previousBlockNumber);
previousBlockNumber
);
vm.prank(owner); vm.prank(owner);
vm.expectRevert( vm.expectRevert(
...@@ -349,9 +345,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer { ...@@ -349,9 +345,7 @@ contract L2OutputOracleTest is L2OutputOracle_Initializer {
test_proposingAnotherOutput(); test_proposingAnotherOutput();
uint256 latestBlockNumber = oracle.latestBlockNumber(); uint256 latestBlockNumber = oracle.latestBlockNumber();
Types.OutputProposal memory proposalToDelete = oracle.getL2Output( Types.OutputProposal memory proposalToDelete = oracle.getL2Output(latestBlockNumber);
latestBlockNumber
);
// Modify the timestamp so that it does not match. // Modify the timestamp so that it does not match.
proposalToDelete.timestamp -= 1; proposalToDelete.timestamp -= 1;
...@@ -378,9 +372,7 @@ contract L2OutputOracleUpgradeable_Test is L2OutputOracle_Initializer { ...@@ -378,9 +372,7 @@ contract L2OutputOracleUpgradeable_Test is L2OutputOracle_Initializer {
assertEq(startingTimestamp, oracleImpl.STARTING_TIMESTAMP()); assertEq(startingTimestamp, oracleImpl.STARTING_TIMESTAMP());
assertEq(l2BlockTime, oracleImpl.L2_BLOCK_TIME()); assertEq(l2BlockTime, oracleImpl.L2_BLOCK_TIME());
Types.OutputProposal memory initOutput = oracleImpl.getL2Output( Types.OutputProposal memory initOutput = oracleImpl.getL2Output(startingBlockNumber);
startingBlockNumber
);
assertEq(genesisL2Output, initOutput.outputRoot); assertEq(genesisL2Output, initOutput.outputRoot);
assertEq(initL1Time, initOutput.timestamp); assertEq(initL1Time, initOutput.timestamp);
......
...@@ -15,15 +15,9 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -15,15 +15,9 @@ contract L2StandardBridge_Test is Bridge_Initializer {
} }
function test_initialize() external { function test_initialize() external {
assertEq( assertEq(address(L2Bridge.messenger()), address(L2Messenger));
address(L2Bridge.messenger()),
address(L2Messenger)
);
assertEq( assertEq(address(L2Bridge.otherBridge()), address(L1Bridge));
address(L2Bridge.otherBridge()),
address(L1Bridge)
);
} }
// receive // receive
...@@ -40,7 +34,7 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -40,7 +34,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
// TODO: events from each contract // TODO: events from each contract
vm.prank(alice, alice); vm.prank(alice, alice);
(bool success,) = address(L2Bridge).call{ value: 100 }(hex""); (bool success, ) = address(L2Bridge).call{ value: 100 }(hex"");
assertEq(success, true); assertEq(success, true);
assertEq(address(messagePasser).balance, 100); assertEq(address(messagePasser).balance, 100);
} }
...@@ -52,12 +46,7 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -52,12 +46,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.expectRevert("StandardBridge: bridging ETH must include sufficient ETH value"); vm.expectRevert("StandardBridge: bridging ETH must include sufficient ETH value");
vm.prank(alice, alice); vm.prank(alice, alice);
L2Bridge.withdraw( L2Bridge.withdraw(address(Predeploys.LEGACY_ERC20_ETH), 100, 1000, hex"");
address(Predeploys.LEGACY_ERC20_ETH),
100,
1000,
hex""
);
} }
// withdraw // withdraw
...@@ -70,12 +59,7 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -70,12 +59,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
assertEq(L2Token.balanceOf(alice), 100); assertEq(L2Token.balanceOf(alice), 100);
vm.prank(alice, alice); vm.prank(alice, alice);
L2Bridge.withdraw( L2Bridge.withdraw(address(L2Token), 100, 1000, hex"");
address(L2Token),
100,
1000,
hex""
);
// TODO: events and calls // TODO: events and calls
...@@ -87,12 +71,7 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -87,12 +71,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
deal(address(L2Token), address(this), 100, true); deal(address(L2Token), address(this), 100, true);
vm.expectRevert("StandardBridge: function can only be called from an EOA"); vm.expectRevert("StandardBridge: function can only be called from an EOA");
L2Bridge.withdraw( L2Bridge.withdraw(address(L2Token), 100, 1000, hex"");
address(L2Token),
100,
1000,
hex""
);
} }
// withdrawTo // withdrawTo
...@@ -103,13 +82,7 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -103,13 +82,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
deal(address(L2Token), alice, 100, true); deal(address(L2Token), alice, 100, true);
vm.prank(alice, alice); vm.prank(alice, alice);
L2Bridge.withdrawTo( L2Bridge.withdrawTo(address(L2Token), bob, 100, 1000, hex"");
address(L2Token),
bob,
100,
1000,
hex""
);
// TODO: events and calls // TODO: events and calls
...@@ -138,23 +111,9 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -138,23 +111,9 @@ contract L2StandardBridge_Test is Bridge_Initializer {
hex"" hex""
); );
vm.expectEmit(true, true, true, true, address(L2Bridge)); vm.expectEmit(true, true, true, true, address(L2Bridge));
emit DepositFinalized( emit DepositFinalized(address(L1Token), address(L2Token), alice, alice, 100, hex"");
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
vm.prank(address(L2Messenger)); vm.prank(address(L2Messenger));
L2Bridge.finalizeDeposit( L2Bridge.finalizeDeposit(address(L1Token), address(L2Token), alice, alice, 100, hex"");
address(L1Token),
address(L2Token),
alice,
alice,
100,
hex""
);
} }
function test_finalizeBridgeETH_incorrectValueReverts() external { function test_finalizeBridgeETH_incorrectValueReverts() external {
...@@ -166,12 +125,7 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -166,12 +125,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.deal(address(L2Messenger), 100); vm.deal(address(L2Messenger), 100);
vm.prank(address(L2Messenger)); vm.prank(address(L2Messenger));
vm.expectRevert("StandardBridge: amount sent does not match amount required"); vm.expectRevert("StandardBridge: amount sent does not match amount required");
L2Bridge.finalizeBridgeETH{value: 50}( L2Bridge.finalizeBridgeETH{ value: 50 }(alice, alice, 100, hex"");
alice,
alice,
100,
hex""
);
} }
function test_finalizeBridgeETH_sendToSelfReverts() external { function test_finalizeBridgeETH_sendToSelfReverts() external {
...@@ -183,12 +137,7 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -183,12 +137,7 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.deal(address(L2Messenger), 100); vm.deal(address(L2Messenger), 100);
vm.prank(address(L2Messenger)); vm.prank(address(L2Messenger));
vm.expectRevert("StandardBridge: cannot send to self"); vm.expectRevert("StandardBridge: cannot send to self");
L2Bridge.finalizeBridgeETH{value: 100}( L2Bridge.finalizeBridgeETH{ value: 100 }(alice, address(L2Bridge), 100, hex"");
alice,
address(L2Bridge),
100,
hex""
);
} }
function test_finalizeBridgeETH_sendToMessengerReverts() external { function test_finalizeBridgeETH_sendToMessengerReverts() external {
...@@ -200,11 +149,6 @@ contract L2StandardBridge_Test is Bridge_Initializer { ...@@ -200,11 +149,6 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.deal(address(L2Messenger), 100); vm.deal(address(L2Messenger), 100);
vm.prank(address(L2Messenger)); vm.prank(address(L2Messenger));
vm.expectRevert("StandardBridge: cannot send to messenger"); vm.expectRevert("StandardBridge: cannot send to messenger");
L2Bridge.finalizeBridgeETH{value: 100}( L2Bridge.finalizeBridgeETH{ value: 100 }(alice, address(L2Messenger), 100, hex"");
alice,
address(L2Messenger),
100,
hex""
);
} }
} }
...@@ -22,7 +22,7 @@ contract L2ToL1MessagePasserTest is CommonTest { ...@@ -22,7 +22,7 @@ contract L2ToL1MessagePasserTest is CommonTest {
event WithdrawerBalanceBurnt(uint256 indexed amount); event WithdrawerBalanceBurnt(uint256 indexed amount);
function setUp() virtual public { function setUp() public virtual {
messagePasser = new L2ToL1MessagePasser(); messagePasser = new L2ToL1MessagePasser();
} }
...@@ -36,14 +36,7 @@ contract L2ToL1MessagePasserTest is CommonTest { ...@@ -36,14 +36,7 @@ contract L2ToL1MessagePasserTest is CommonTest {
uint256 nonce = messagePasser.nonce(); uint256 nonce = messagePasser.nonce();
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit MessagePassed( emit MessagePassed(nonce, _sender, _target, _value, _gasLimit, _data);
nonce,
_sender,
_target,
_value,
_gasLimit,
_data
);
bytes32 withdrawalHash = Hashing.hashWithdrawal( bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction({ Types.WithdrawalTransaction({
...@@ -61,39 +54,19 @@ contract L2ToL1MessagePasserTest is CommonTest { ...@@ -61,39 +54,19 @@ contract L2ToL1MessagePasserTest is CommonTest {
vm.deal(_sender, _value); vm.deal(_sender, _value);
vm.prank(_sender); vm.prank(_sender);
messagePasser.initiateWithdrawal{ value: _value }( messagePasser.initiateWithdrawal{ value: _value }(_target, _gasLimit, _data);
_target,
_gasLimit,
_data
);
assertEq( assertEq(messagePasser.sentMessages(withdrawalHash), true);
messagePasser.sentMessages(withdrawalHash),
true
);
bytes32 slot = keccak256(bytes.concat( bytes32 slot = keccak256(bytes.concat(withdrawalHash, bytes32(0)));
withdrawalHash,
bytes32(0)
));
assertEq( assertEq(vm.load(address(messagePasser), slot), bytes32(uint256(1)));
vm.load(address(messagePasser), slot),
bytes32(uint256(1))
);
} }
// Test: initiateWithdrawal should emit the correct log when called by a contract // Test: initiateWithdrawal should emit the correct log when called by a contract
function test_initiateWithdrawal_fromContract() external { function test_initiateWithdrawal_fromContract() external {
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit MessagePassed( emit MessagePassed(messagePasser.nonce(), address(this), address(4), 100, 64000, hex"");
messagePasser.nonce(),
address(this),
address(4),
100,
64000,
hex""
);
bytes32 withdrawalHash = Hashing.hashWithdrawal( bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction( Types.WithdrawalTransaction(
...@@ -110,11 +83,7 @@ contract L2ToL1MessagePasserTest is CommonTest { ...@@ -110,11 +83,7 @@ contract L2ToL1MessagePasserTest is CommonTest {
emit MessagePassedExtension1(withdrawalHash); emit MessagePassedExtension1(withdrawalHash);
vm.deal(address(this), 2**64); vm.deal(address(this), 2**64);
messagePasser.initiateWithdrawal{ value: 100 }( messagePasser.initiateWithdrawal{ value: 100 }(address(4), 64000, hex"");
address(4),
64000,
hex""
);
} }
// Test: initiateWithdrawal should emit the correct log when called by an EOA // Test: initiateWithdrawal should emit the correct log when called by an EOA
...@@ -129,31 +98,13 @@ contract L2ToL1MessagePasserTest is CommonTest { ...@@ -129,31 +98,13 @@ contract L2ToL1MessagePasserTest is CommonTest {
vm.prank(alice, alice); vm.prank(alice, alice);
vm.deal(alice, 2**64); vm.deal(alice, 2**64);
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit MessagePassed( emit MessagePassed(nonce, alice, target, value, gasLimit, data);
nonce,
alice,
target,
value,
gasLimit,
data
);
bytes32 withdrawalHash = Hashing.hashWithdrawal( bytes32 withdrawalHash = Hashing.hashWithdrawal(
Types.WithdrawalTransaction( Types.WithdrawalTransaction(nonce, alice, target, value, gasLimit, data)
nonce,
alice,
target,
value,
gasLimit,
data
)
); );
messagePasser.initiateWithdrawal{ value: value }( messagePasser.initiateWithdrawal{ value: value }(target, gasLimit, data);
target,
gasLimit,
data
);
// the sent messages mapping is filled // the sent messages mapping is filled
assertEq(messagePasser.sentMessages(withdrawalHash), true); assertEq(messagePasser.sentMessages(withdrawalHash), true);
......
...@@ -77,7 +77,10 @@ contract OptimismMintableERC20_Test is Bridge_Initializer { ...@@ -77,7 +77,10 @@ contract OptimismMintableERC20_Test is Bridge_Initializer {
assertEq(iface2, type(ILegacyMintableERC20).interfaceId); assertEq(iface2, type(ILegacyMintableERC20).interfaceId);
assert(L2Token.supportsInterface(iface2)); 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); assertEq(iface3, type(IOptimismMintableERC20).interfaceId);
assert(L2Token.supportsInterface(iface3)); assert(L2Token.supportsInterface(iface3));
} }
......
...@@ -25,17 +25,10 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer { ...@@ -25,17 +25,10 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
address local = LibRLP.computeAddress(address(L2TokenFactory), 2); address local = LibRLP.computeAddress(address(L2TokenFactory), 2);
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated( emit StandardL2TokenCreated(remote, local);
remote,
local
);
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit OptimismMintableERC20Created( emit OptimismMintableERC20Created(local, remote, alice);
local,
remote,
alice
);
vm.prank(alice); vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP"); L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
...@@ -50,17 +43,10 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer { ...@@ -50,17 +43,10 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
address local = LibRLP.computeAddress(address(L2TokenFactory), 3); address local = LibRLP.computeAddress(address(L2TokenFactory), 3);
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit StandardL2TokenCreated( emit StandardL2TokenCreated(remote, local);
remote,
local
);
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
emit OptimismMintableERC20Created( emit OptimismMintableERC20Created(local, remote, alice);
local,
remote,
alice
);
vm.prank(alice); vm.prank(alice);
L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP"); L2TokenFactory.createStandardL2Token(remote, "Beep", "BOOP");
......
...@@ -422,13 +422,8 @@ contract OptimismPortal_FinalizeWithdrawal_Test is Portal_Initializer { ...@@ -422,13 +422,8 @@ contract OptimismPortal_FinalizeWithdrawal_Test is Portal_Initializer {
gasLimit: gasLimit, gasLimit: gasLimit,
data: hex"" data: hex""
}); });
( (bytes32 stateRoot, bytes32 storageRoot, , , bytes memory withdrawalProof) = ffi
bytes32 stateRoot, .getFinalizeWithdrawalTransactionInputs(insufficientGasTx);
bytes32 storageRoot,
,
,
bytes memory withdrawalProof
) = ffi.getFinalizeWithdrawalTransactionInputs(insufficientGasTx);
Types.OutputRootProof memory outputRootProof = Types.OutputRootProof({ Types.OutputRootProof memory outputRootProof = Types.OutputRootProof({
version: bytes32(0), version: bytes32(0),
stateRoot: stateRoot, stateRoot: stateRoot,
......
...@@ -30,10 +30,9 @@ contract Proxy_Test is Test { ...@@ -30,10 +30,9 @@ contract Proxy_Test is Test {
address alice = address(64); address alice = address(64);
bytes32 internal constant IMPLEMENTATION_KEY = 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 internal constant OWNER_KEY = bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1);
bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1);
Proxy proxy; Proxy proxy;
SimpleStorage simpleStorage; SimpleStorage simpleStorage;
...@@ -54,10 +53,7 @@ contract Proxy_Test is Test { ...@@ -54,10 +53,7 @@ contract Proxy_Test is Test {
proxy.upgradeTo(address(6)); proxy.upgradeTo(address(6));
bytes32 key = vm.load(address(proxy), IMPLEMENTATION_KEY); bytes32 key = vm.load(address(proxy), IMPLEMENTATION_KEY);
assertEq( assertEq(address(6), Bytes32AddressLib.fromLast20Bytes(key));
address(6),
Bytes32AddressLib.fromLast20Bytes(key)
);
vm.prank(alice); vm.prank(alice);
address impl = proxy.implementation(); address impl = proxy.implementation();
...@@ -70,10 +66,7 @@ contract Proxy_Test is Test { ...@@ -70,10 +66,7 @@ contract Proxy_Test is Test {
proxy.changeAdmin(address(6)); proxy.changeAdmin(address(6));
bytes32 key = vm.load(address(proxy), OWNER_KEY); bytes32 key = vm.load(address(proxy), OWNER_KEY);
assertEq( assertEq(address(6), Bytes32AddressLib.fromLast20Bytes(key));
address(6),
Bytes32AddressLib.fromLast20Bytes(key)
);
vm.prank(address(6)); vm.prank(address(6));
address owner = proxy.admin(); address owner = proxy.admin();
...@@ -186,10 +179,7 @@ contract Proxy_Test is Test { ...@@ -186,10 +179,7 @@ contract Proxy_Test is Test {
// match a function on the implementation. // match a function on the implementation.
vm.expectRevert("Proxy: delegatecall to new implementation contract failed"); vm.expectRevert("Proxy: delegatecall to new implementation contract failed");
vm.prank(alice); vm.prank(alice);
proxy.upgradeToAndCall( proxy.upgradeToAndCall(address(simpleStorage), hex"");
address(simpleStorage),
hex""
);
// The implementation address should have not // The implementation address should have not
// updated because the call to `upgradeToAndCall` // updated because the call to `upgradeToAndCall`
......
...@@ -62,10 +62,7 @@ contract ProxyAdmin_Test is Test { ...@@ -62,10 +62,7 @@ contract ProxyAdmin_Test is Test {
function test_setImplementationName() external { function test_setImplementationName() external {
vm.prank(alice); vm.prank(alice);
admin.setImplementationName(address(1), "foo"); admin.setImplementationName(address(1), "foo");
assertEq( assertEq(admin.implementationName(address(1)), "foo");
admin.implementationName(address(1)),
"foo"
);
} }
function test_onlyOwnerSetAddressManager() external { function test_onlyOwnerSetAddressManager() external {
...@@ -88,10 +85,7 @@ contract ProxyAdmin_Test is Test { ...@@ -88,10 +85,7 @@ contract ProxyAdmin_Test is Test {
} }
function test_proxyType() external { function test_proxyType() external {
assertEq( assertEq(uint256(admin.proxyType(address(proxy))), uint256(ProxyAdmin.ProxyType.ERC1967));
uint256(admin.proxyType(address(proxy))),
uint256(ProxyAdmin.ProxyType.ERC1967)
);
assertEq( assertEq(
uint256(admin.proxyType(address(chugsplash))), uint256(admin.proxyType(address(chugsplash))),
uint256(ProxyAdmin.ProxyType.CHUGSPLASH) uint256(ProxyAdmin.ProxyType.CHUGSPLASH)
...@@ -186,15 +180,9 @@ contract ProxyAdmin_Test is Test { ...@@ -186,15 +180,9 @@ contract ProxyAdmin_Test is Test {
if (proxyType == ProxyAdmin.ProxyType.ERC1967) { if (proxyType == ProxyAdmin.ProxyType.ERC1967) {
assertEq(Proxy(payable(_proxy)).admin(), address(128)); assertEq(Proxy(payable(_proxy)).admin(), address(128));
} else if (proxyType == ProxyAdmin.ProxyType.CHUGSPLASH) { } else if (proxyType == ProxyAdmin.ProxyType.CHUGSPLASH) {
assertEq( assertEq(L1ChugSplashProxy(payable(_proxy)).getOwner(), address(128));
L1ChugSplashProxy(payable(_proxy)).getOwner(),
address(128)
);
} else if (proxyType == ProxyAdmin.ProxyType.RESOLVED) { } else if (proxyType == ProxyAdmin.ProxyType.RESOLVED) {
assertEq( assertEq(addressManager.owner(), address(128));
addressManager.owner(),
address(128)
);
} else { } else {
assert(false); assert(false);
} }
......
...@@ -13,19 +13,58 @@ library LibRLP { ...@@ -13,19 +13,58 @@ library LibRLP {
function computeAddress(address deployer, uint256 nonce) internal pure returns (address) { 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. // 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. // 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 == 0x00)
if (nonce <= 0x7f) return keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, uint8(nonce))).fromLast20Bytes(); 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. // 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(uint8).max)
if (nonce <= type(uint16).max) return keccak256(abi.encodePacked(bytes1(0xd8), bytes1(0x94), deployer, bytes1(0x82), uint16(nonce))).fromLast20Bytes(); return
if (nonce <= type(uint24).max) return keccak256(abi.encodePacked(bytes1(0xd9), bytes1(0x94), deployer, bytes1(0x83), uint24(nonce))).fromLast20Bytes(); 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 // 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) // 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) // 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) // 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. // 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,15 +6,9 @@ import { CommonTest } from "./CommonTest.t.sol"; ...@@ -6,15 +6,9 @@ import { CommonTest } from "./CommonTest.t.sol";
contract RLPReader_Test is CommonTest { contract RLPReader_Test is CommonTest {
function testReadBool() external { function testReadBool() external {
assertEq( assertEq(RLPReader.readBool(hex"01"), true);
RLPReader.readBool(hex"01"),
true
);
assertEq( assertEq(RLPReader.readBool(hex"00"), false);
RLPReader.readBool(hex"00"),
false
);
} }
function test_readBoolInvalidValue() external { function test_readBoolInvalidValue() external {
...@@ -35,10 +29,7 @@ contract RLPReader_Test is CommonTest { ...@@ -35,10 +29,7 @@ contract RLPReader_Test is CommonTest {
} }
function test_readAddressSmall() external { function test_readAddressSmall() external {
assertEq( assertEq(RLPReader.readAddress(hex"12"), address(0));
RLPReader.readAddress(hex"12"),
address(0)
);
} }
function test_readAddressTooLarge() external { function test_readAddressTooLarge() external {
...@@ -52,24 +43,15 @@ contract RLPReader_Test is CommonTest { ...@@ -52,24 +43,15 @@ contract RLPReader_Test is CommonTest {
} }
function test_readBytes_bytestring00() external { function test_readBytes_bytestring00() external {
assertEq( assertEq(RLPReader.readBytes(hex"00"), hex"00");
RLPReader.readBytes(hex"00"),
hex"00"
);
} }
function test_readBytes_bytestring01() external { function test_readBytes_bytestring01() external {
assertEq( assertEq(RLPReader.readBytes(hex"01"), hex"01");
RLPReader.readBytes(hex"01"),
hex"01"
);
} }
function test_readBytes_bytestring7f() external { function test_readBytes_bytestring7f() external {
assertEq( assertEq(RLPReader.readBytes(hex"7f"), hex"7f");
RLPReader.readBytes(hex"7f"),
hex"7f"
);
} }
function test_readBytes_revertListItem() external { function test_readBytes_revertListItem() external {
...@@ -94,98 +76,76 @@ contract RLPReader_Test is CommonTest { ...@@ -94,98 +76,76 @@ contract RLPReader_Test is CommonTest {
function test_readBytes32_revertOnTooLong() external { function test_readBytes32_revertOnTooLong() external {
vm.expectRevert("RLPReader: invalid RLP bytes32 value"); vm.expectRevert("RLPReader: invalid RLP bytes32 value");
RLPReader.readBytes32(hex"11110000000000000000000000000000000000000000000000000000000000000000"); RLPReader.readBytes32(
hex"11110000000000000000000000000000000000000000000000000000000000000000"
);
} }
function test_readString_emptyString() external { function test_readString_emptyString() external {
assertEq( assertEq(RLPReader.readString(hex"80"), hex"");
RLPReader.readString(hex"80"),
hex""
);
} }
function test_readString_shortString() external { function test_readString_shortString() external {
assertEq( assertEq(RLPReader.readString(hex"83646f67"), "dog");
RLPReader.readString(hex"83646f67"),
"dog"
);
} }
function test_readString_shortString2() external { function test_readString_shortString2() external {
assertEq( assertEq(
RLPReader.readString(hex"b74c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c69"), RLPReader.readString(
hex"b74c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c69"
),
"Lorem ipsum dolor sit amet, consectetur adipisicing eli" "Lorem ipsum dolor sit amet, consectetur adipisicing eli"
); );
} }
function test_readString_longString() external { function test_readString_longString() external {
assertEq( assertEq(
RLPReader.readString(hex"b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"), RLPReader.readString(
hex"b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"
),
"Lorem ipsum dolor sit amet, consectetur adipisicing elit" "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
); );
} }
function test_readString_longString2() external { function test_readString_longString2() external {
assertEq( assertEq(
RLPReader.readString(hex"b904004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20437572616269747572206d6175726973206d61676e612c20737573636970697420736564207665686963756c61206e6f6e2c20696163756c697320666175636962757320746f72746f722e2050726f696e20737573636970697420756c74726963696573206d616c6573756164612e204475697320746f72746f7220656c69742c2064696374756d2071756973207472697374697175652065752c20756c7472696365732061742072697375732e204d6f72626920612065737420696d70657264696574206d6920756c6c616d636f7270657220616c6971756574207375736369706974206e6563206c6f72656d2e2041656e65616e2071756973206c656f206d6f6c6c69732c2076756c70757461746520656c6974207661726975732c20636f6e73657175617420656e696d2e204e756c6c6120756c74726963657320747572706973206a7573746f2c20657420706f73756572652075726e6120636f6e7365637465747572206e65632e2050726f696e206e6f6e20636f6e76616c6c6973206d657475732e20446f6e65632074656d706f7220697073756d20696e206d617572697320636f6e67756520736f6c6c696369747564696e2e20566573746962756c756d20616e746520697073756d207072696d697320696e206661756369627573206f726369206c756374757320657420756c74726963657320706f737565726520637562696c69612043757261653b2053757370656e646973736520636f6e76616c6c69732073656d2076656c206d617373612066617563696275732c2065676574206c6163696e6961206c616375732074656d706f722e204e756c6c61207175697320756c747269636965732070757275732e2050726f696e20617563746f722072686f6e637573206e69626820636f6e64696d656e74756d206d6f6c6c69732e20416c697175616d20636f6e73657175617420656e696d206174206d65747573206c75637475732c206120656c656966656e6420707572757320656765737461732e20437572616269747572206174206e696268206d657475732e204e616d20626962656e64756d2c206e6571756520617420617563746f72207472697374697175652c206c6f72656d206c696265726f20616c697175657420617263752c206e6f6e20696e74657264756d2074656c6c7573206c65637475732073697420616d65742065726f732e20437261732072686f6e6375732c206d65747573206163206f726e617265206375727375732c20646f6c6f72206a7573746f20756c747269636573206d657475732c20617420756c6c616d636f7270657220766f6c7574706174"), RLPReader.readString(
hex"b904004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20437572616269747572206d6175726973206d61676e612c20737573636970697420736564207665686963756c61206e6f6e2c20696163756c697320666175636962757320746f72746f722e2050726f696e20737573636970697420756c74726963696573206d616c6573756164612e204475697320746f72746f7220656c69742c2064696374756d2071756973207472697374697175652065752c20756c7472696365732061742072697375732e204d6f72626920612065737420696d70657264696574206d6920756c6c616d636f7270657220616c6971756574207375736369706974206e6563206c6f72656d2e2041656e65616e2071756973206c656f206d6f6c6c69732c2076756c70757461746520656c6974207661726975732c20636f6e73657175617420656e696d2e204e756c6c6120756c74726963657320747572706973206a7573746f2c20657420706f73756572652075726e6120636f6e7365637465747572206e65632e2050726f696e206e6f6e20636f6e76616c6c6973206d657475732e20446f6e65632074656d706f7220697073756d20696e206d617572697320636f6e67756520736f6c6c696369747564696e2e20566573746962756c756d20616e746520697073756d207072696d697320696e206661756369627573206f726369206c756374757320657420756c74726963657320706f737565726520637562696c69612043757261653b2053757370656e646973736520636f6e76616c6c69732073656d2076656c206d617373612066617563696275732c2065676574206c6163696e6961206c616375732074656d706f722e204e756c6c61207175697320756c747269636965732070757275732e2050726f696e20617563746f722072686f6e637573206e69626820636f6e64696d656e74756d206d6f6c6c69732e20416c697175616d20636f6e73657175617420656e696d206174206d65747573206c75637475732c206120656c656966656e6420707572757320656765737461732e20437572616269747572206174206e696268206d657475732e204e616d20626962656e64756d2c206e6571756520617420617563746f72207472697374697175652c206c6f72656d206c696265726f20616c697175657420617263752c206e6f6e20696e74657264756d2074656c6c7573206c65637475732073697420616d65742065726f732e20437261732072686f6e6375732c206d65747573206163206f726e617265206375727375732c20646f6c6f72206a7573746f20756c747269636573206d657475732c20617420756c6c616d636f7270657220766f6c7574706174"
),
"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" "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"
); );
} }
function test_readUint256_zero() external { function test_readUint256_zero() external {
assertEq( assertEq(RLPReader.readUint256(hex"80"), 0);
RLPReader.readUint256(hex"80"),
0
);
} }
function test_readUint256_smallInt() external { function test_readUint256_smallInt() external {
assertEq( assertEq(RLPReader.readUint256(hex"01"), 1);
RLPReader.readUint256(hex"01"),
1
);
} }
function test_readUint256_smallInt2() external { function test_readUint256_smallInt2() external {
assertEq( assertEq(RLPReader.readUint256(hex"10"), 16);
RLPReader.readUint256(hex"10"),
16
);
} }
function test_readUint256_smallInt3() external { function test_readUint256_smallInt3() external {
assertEq( assertEq(RLPReader.readUint256(hex"4f"), 79);
RLPReader.readUint256(hex"4f"),
79
);
} }
function test_readUint256_smallInt4() external { function test_readUint256_smallInt4() external {
assertEq( assertEq(RLPReader.readUint256(hex"7f"), 127);
RLPReader.readUint256(hex"7f"),
127
);
} }
function test_readUint256_mediumInt1() external { function test_readUint256_mediumInt1() external {
assertEq( assertEq(RLPReader.readUint256(hex"8180"), 128);
RLPReader.readUint256(hex"8180"),
128
);
} }
function test_readUint256_mediumInt2() external { function test_readUint256_mediumInt2() external {
assertEq( assertEq(RLPReader.readUint256(hex"8203e8"), 1000);
RLPReader.readUint256(hex"8203e8"),
1000
);
} }
function test_readUint256_mediumInt3() external { function test_readUint256_mediumInt3() external {
assertEq( assertEq(RLPReader.readUint256(hex"830186a0"), 100000);
RLPReader.readUint256(hex"830186a0"),
100000
);
} }
function test_readList_empty() external { function test_readList_empty() external {
...@@ -211,7 +171,9 @@ contract RLPReader_Test is CommonTest { ...@@ -211,7 +171,9 @@ contract RLPReader_Test is CommonTest {
} }
function test_readList_shortListMax1() external { function test_readList_shortListMax1() external {
RLPReader.RLPItem[] memory list = RLPReader.readList(hex"f784617364668471776572847a78637684617364668471776572847a78637684617364668471776572847a78637684617364668471776572"); RLPReader.RLPItem[] memory list = RLPReader.readList(
hex"f784617364668471776572847a78637684617364668471776572847a78637684617364668471776572847a78637684617364668471776572"
);
assertEq(list.length, 11); assertEq(list.length, 11);
assertEq(RLPReader.readRawBytes(list[0]), hex"8461736466"); assertEq(RLPReader.readRawBytes(list[0]), hex"8461736466");
...@@ -228,7 +190,9 @@ contract RLPReader_Test is CommonTest { ...@@ -228,7 +190,9 @@ contract RLPReader_Test is CommonTest {
} }
function test_readList_longList1() external { function test_readList_longList1() external {
RLPReader.RLPItem[] memory list = RLPReader.readList(hex"f840cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376"); RLPReader.RLPItem[] memory list = RLPReader.readList(
hex"f840cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376"
);
assertEq(list.length, 4); assertEq(list.length, 4);
assertEq(RLPReader.readRawBytes(list[0]), hex"cf84617364668471776572847a786376"); assertEq(RLPReader.readRawBytes(list[0]), hex"cf84617364668471776572847a786376");
...@@ -238,7 +202,9 @@ contract RLPReader_Test is CommonTest { ...@@ -238,7 +202,9 @@ contract RLPReader_Test is CommonTest {
} }
function test_readList_longList2() external { function test_readList_longList2() external {
RLPReader.RLPItem[] memory list = RLPReader.readList(hex"f90200cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376"); RLPReader.RLPItem[] memory list = RLPReader.readList(
hex"f90200cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376"
);
assertEq(list.length, 32); assertEq(list.length, 32);
for (uint256 i = 0; i < 32; i++) { for (uint256 i = 0; i < 32; i++) {
...@@ -263,7 +229,9 @@ contract RLPReader_Test is CommonTest { ...@@ -263,7 +229,9 @@ contract RLPReader_Test is CommonTest {
} }
function test_readList_dictTest1() external { function test_readList_dictTest1() external {
RLPReader.RLPItem[] memory list = RLPReader.readList(hex"ecca846b6579318476616c31ca846b6579328476616c32ca846b6579338476616c33ca846b6579348476616c34"); RLPReader.RLPItem[] memory list = RLPReader.readList(
hex"ecca846b6579318476616c31ca846b6579328476616c32ca846b6579338476616c33ca846b6579348476616c34"
);
assertEq(list.length, 4); assertEq(list.length, 4);
assertEq(RLPReader.readRawBytes(list[0]), hex"ca846b6579318476616c31"); assertEq(RLPReader.readRawBytes(list[0]), hex"ca846b6579318476616c31");
...@@ -284,7 +252,9 @@ contract RLPReader_Test is CommonTest { ...@@ -284,7 +252,9 @@ contract RLPReader_Test is CommonTest {
function test_readList_notLongEnough() external { function test_readList_notLongEnough() external {
vm.expectRevert("RLPReader: invalid RLP short list"); vm.expectRevert("RLPReader: invalid RLP short list");
RLPReader.readList(hex"efdebdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); RLPReader.readList(
hex"efdebdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
);
} }
function test_readList_int32Overflow() external { function test_readList_int32Overflow() external {
...@@ -299,12 +269,16 @@ contract RLPReader_Test is CommonTest { ...@@ -299,12 +269,16 @@ contract RLPReader_Test is CommonTest {
function test_readList_incorrectLengthInArray() external { function test_readList_incorrectLengthInArray() external {
vm.expectRevert("RLPReader: invalid RLP list value"); vm.expectRevert("RLPReader: invalid RLP list value");
RLPReader.readList(hex"b9002100dc2b275d0f74e8a53e6f4ec61b27f24278820be3f82ea2110e582081b0565df0"); RLPReader.readList(
hex"b9002100dc2b275d0f74e8a53e6f4ec61b27f24278820be3f82ea2110e582081b0565df0"
);
} }
function test_readList_leadingZerosInLongLengthArray1() external { function test_readList_leadingZerosInLongLengthArray1() external {
vm.expectRevert("RLPReader: invalid RLP list value"); vm.expectRevert("RLPReader: invalid RLP list value");
RLPReader.readList(hex"b90040000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"); RLPReader.readList(
hex"b90040000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"
);
} }
function test_readList_leadingZerosInLongLengthArray2() external { function test_readList_leadingZerosInLongLengthArray2() external {
...@@ -314,7 +288,9 @@ contract RLPReader_Test is CommonTest { ...@@ -314,7 +288,9 @@ contract RLPReader_Test is CommonTest {
function test_readList_leadingZerosInLongLengthList1() external { function test_readList_leadingZerosInLongLengthList1() external {
vm.expectRevert("RLPReader: provided RLP list exceeds max list length"); vm.expectRevert("RLPReader: provided RLP list exceeds max list length");
RLPReader.readList(hex"fb00000040000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"); RLPReader.readList(
hex"fb00000040000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"
);
} }
function test_readList_nonOptimalLongLengthArray1() external { function test_readList_nonOptimalLongLengthArray1() external {
......
...@@ -6,38 +6,23 @@ import { CommonTest } from "./CommonTest.t.sol"; ...@@ -6,38 +6,23 @@ import { CommonTest } from "./CommonTest.t.sol";
contract RLPWriter_Test is CommonTest { contract RLPWriter_Test is CommonTest {
function test_writeString_empty() external { function test_writeString_empty() external {
assertEq( assertEq(RLPWriter.writeString(""), hex"80");
RLPWriter.writeString(""),
hex"80"
);
} }
function test_writeString_bytestring00() external { function test_writeString_bytestring00() external {
assertEq( assertEq(RLPWriter.writeString("\u0000"), hex"00");
RLPWriter.writeString("\u0000"),
hex"00"
);
} }
function test_writeString_bytestring01() external { function test_writeString_bytestring01() external {
assertEq( assertEq(RLPWriter.writeString("\u0001"), hex"01");
RLPWriter.writeString("\u0001"),
hex"01"
);
} }
function test_writeString_bytestring7f() external { function test_writeString_bytestring7f() external {
assertEq( assertEq(RLPWriter.writeString("\u007F"), hex"7f");
RLPWriter.writeString("\u007F"),
hex"7f"
);
} }
function test_writeString_shortstring() external { function test_writeString_shortstring() external {
assertEq( assertEq(RLPWriter.writeString("dog"), hex"83646f67");
RLPWriter.writeString("dog"),
hex"83646f67"
);
} }
function test_writeString_shortstring2() external { function test_writeString_shortstring2() external {
...@@ -56,72 +41,47 @@ contract RLPWriter_Test is CommonTest { ...@@ -56,72 +41,47 @@ contract RLPWriter_Test is CommonTest {
function test_writeString_longstring2() external { function test_writeString_longstring2() external {
assertEq( 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" hex"b904004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20437572616269747572206d6175726973206d61676e612c20737573636970697420736564207665686963756c61206e6f6e2c20696163756c697320666175636962757320746f72746f722e2050726f696e20737573636970697420756c74726963696573206d616c6573756164612e204475697320746f72746f7220656c69742c2064696374756d2071756973207472697374697175652065752c20756c7472696365732061742072697375732e204d6f72626920612065737420696d70657264696574206d6920756c6c616d636f7270657220616c6971756574207375736369706974206e6563206c6f72656d2e2041656e65616e2071756973206c656f206d6f6c6c69732c2076756c70757461746520656c6974207661726975732c20636f6e73657175617420656e696d2e204e756c6c6120756c74726963657320747572706973206a7573746f2c20657420706f73756572652075726e6120636f6e7365637465747572206e65632e2050726f696e206e6f6e20636f6e76616c6c6973206d657475732e20446f6e65632074656d706f7220697073756d20696e206d617572697320636f6e67756520736f6c6c696369747564696e2e20566573746962756c756d20616e746520697073756d207072696d697320696e206661756369627573206f726369206c756374757320657420756c74726963657320706f737565726520637562696c69612043757261653b2053757370656e646973736520636f6e76616c6c69732073656d2076656c206d617373612066617563696275732c2065676574206c6163696e6961206c616375732074656d706f722e204e756c6c61207175697320756c747269636965732070757275732e2050726f696e20617563746f722072686f6e637573206e69626820636f6e64696d656e74756d206d6f6c6c69732e20416c697175616d20636f6e73657175617420656e696d206174206d65747573206c75637475732c206120656c656966656e6420707572757320656765737461732e20437572616269747572206174206e696268206d657475732e204e616d20626962656e64756d2c206e6571756520617420617563746f72207472697374697175652c206c6f72656d206c696265726f20616c697175657420617263752c206e6f6e20696e74657264756d2074656c6c7573206c65637475732073697420616d65742065726f732e20437261732072686f6e6375732c206d65747573206163206f726e617265206375727375732c20646f6c6f72206a7573746f20756c747269636573206d657475732c20617420756c6c616d636f7270657220766f6c7574706174"
); );
} }
function test_writeUint_zero() external { function test_writeUint_zero() external {
assertEq( assertEq(RLPWriter.writeUint(0x0), hex"80");
RLPWriter.writeUint(0x0),
hex"80"
);
} }
function test_writeUint_smallint() external { function test_writeUint_smallint() external {
assertEq( assertEq(RLPWriter.writeUint(1), hex"01");
RLPWriter.writeUint(1),
hex"01"
);
} }
function test_writeUint_smallint2() external { function test_writeUint_smallint2() external {
assertEq( assertEq(RLPWriter.writeUint(16), hex"10");
RLPWriter.writeUint(16),
hex"10"
);
} }
function test_writeUint_smallint3() external { function test_writeUint_smallint3() external {
assertEq( assertEq(RLPWriter.writeUint(79), hex"4f");
RLPWriter.writeUint(79),
hex"4f"
);
} }
function test_writeUint_smallint4() external { function test_writeUint_smallint4() external {
assertEq( assertEq(RLPWriter.writeUint(127), hex"7f");
RLPWriter.writeUint(127),
hex"7f"
);
} }
function test_writeUint_mediumint() external { function test_writeUint_mediumint() external {
assertEq( assertEq(RLPWriter.writeUint(128), hex"8180");
RLPWriter.writeUint(128),
hex"8180"
);
} }
function test_writeUint_mediumint2() external { function test_writeUint_mediumint2() external {
assertEq( assertEq(RLPWriter.writeUint(1000), hex"8203e8");
RLPWriter.writeUint(1000),
hex"8203e8"
);
} }
function test_writeUint_mediumint3() external { function test_writeUint_mediumint3() external {
assertEq( assertEq(RLPWriter.writeUint(100000), hex"830186a0");
RLPWriter.writeUint(100000),
hex"830186a0"
);
} }
function test_writeList_empty() external { function test_writeList_empty() external {
assertEq( assertEq(RLPWriter.writeList(new bytes[](0)), hex"c0");
RLPWriter.writeList(new bytes[](0)),
hex"c0"
);
} }
function test_writeList_stringList() external { function test_writeList_stringList() external {
...@@ -130,10 +90,7 @@ contract RLPWriter_Test is CommonTest { ...@@ -130,10 +90,7 @@ contract RLPWriter_Test is CommonTest {
list[1] = RLPWriter.writeString("god"); list[1] = RLPWriter.writeString("god");
list[2] = RLPWriter.writeString("cat"); list[2] = RLPWriter.writeString("cat");
assertEq( assertEq(RLPWriter.writeList(list), hex"cc83646f6783676f6483636174");
RLPWriter.writeList(list),
hex"cc83646f6783676f6483636174"
);
} }
function test_writeList_multiList() external { function test_writeList_multiList() external {
...@@ -145,10 +102,7 @@ contract RLPWriter_Test is CommonTest { ...@@ -145,10 +102,7 @@ contract RLPWriter_Test is CommonTest {
list[1] = RLPWriter.writeList(list2); list[1] = RLPWriter.writeList(list2);
list[2] = RLPWriter.writeUint(1); list[2] = RLPWriter.writeUint(1);
assertEq( assertEq(RLPWriter.writeList(list), hex"c6827a77c10401");
RLPWriter.writeList(list),
hex"c6827a77c10401"
);
} }
function test_writeList_shortListMax1() external { function test_writeList_shortListMax1() external {
...@@ -208,7 +162,6 @@ contract RLPWriter_Test is CommonTest { ...@@ -208,7 +162,6 @@ contract RLPWriter_Test is CommonTest {
); );
} }
function test_writeList_listoflists() external { function test_writeList_listoflists() external {
// [ [ [], [] ], [] ] // [ [ [], [] ], [] ]
bytes[] memory list = new bytes[](2); bytes[] memory list = new bytes[](2);
...@@ -220,10 +173,7 @@ contract RLPWriter_Test is CommonTest { ...@@ -220,10 +173,7 @@ contract RLPWriter_Test is CommonTest {
list[0] = RLPWriter.writeList(list2); list[0] = RLPWriter.writeList(list2);
list[1] = RLPWriter.writeList(new bytes[](0)); list[1] = RLPWriter.writeList(new bytes[](0));
assertEq( assertEq(RLPWriter.writeList(list), hex"c4c2c0c0c0");
RLPWriter.writeList(list),
hex"c4c2c0c0c0"
);
} }
function test_writeList_listoflists2() external { function test_writeList_listoflists2() external {
...@@ -242,10 +192,7 @@ contract RLPWriter_Test is CommonTest { ...@@ -242,10 +192,7 @@ contract RLPWriter_Test is CommonTest {
list[2] = RLPWriter.writeList(list3); list[2] = RLPWriter.writeList(list3);
assertEq( assertEq(RLPWriter.writeList(list), hex"c7c0c1c0c3c0c1c0");
RLPWriter.writeList(list),
hex"c7c0c1c0c3c0c1c0"
);
} }
function test_writeList_dictTest1() external { function test_writeList_dictTest1() external {
......
...@@ -97,7 +97,7 @@ contract ResourceMetering_Test is CommonTest { ...@@ -97,7 +97,7 @@ contract ResourceMetering_Test is CommonTest {
vm.roll(initialBlockNum + 1); vm.roll(initialBlockNum + 1);
meter.use(0); meter.use(0);
(uint128 postBaseFee,,) = meter.params(); (uint128 postBaseFee, , ) = meter.params();
// Base fee increases by 1/8 the difference // Base fee increases by 1/8 the difference
assertEq(postBaseFee, 1375000000); assertEq(postBaseFee, 1375000000);
} }
......
...@@ -20,13 +20,9 @@ contract SafeCall_Test is CommonTest { ...@@ -20,13 +20,9 @@ contract SafeCall_Test is CommonTest {
vm.assume(to != address(vm)); vm.assume(to != address(vm));
vm.assume(from != address(vm)); vm.assume(from != address(vm));
// don't call the console // don't call the console
vm.assume( vm.assume(to != address(0x000000000000000000636F6e736F6c652e6c6f67));
to != address(0x000000000000000000636F6e736F6c652e6c6f67)
);
// don't call the create2 deployer // don't call the create2 deployer
vm.assume( vm.assume(to != address(0x4e59b44847b379578588920cA78FbF26c0B4956C));
to != address(0x4e59b44847b379578588920cA78FbF26c0B4956C)
);
// don't send funds to self // don't send funds to self
vm.assume(from != to); vm.assume(from != to);
...@@ -34,19 +30,10 @@ contract SafeCall_Test is CommonTest { ...@@ -34,19 +30,10 @@ contract SafeCall_Test is CommonTest {
vm.deal(from, value); vm.deal(from, value);
assertEq(from.balance, value, "from balance not dealt"); assertEq(from.balance, value, "from balance not dealt");
vm.expectCall( vm.expectCall(to, value, data);
to,
value,
data
);
vm.prank(from); vm.prank(from);
bool success = SafeCall.call( bool success = SafeCall.call(to, gas, value, data);
to,
gas,
value,
data
);
assertEq(success, true, "call not successful"); assertEq(success, true, "call not successful");
assertEq(to.balance, value, "to balance received"); assertEq(to.balance, value, "to balance received");
......
...@@ -27,10 +27,7 @@ contract Semver_Test is CommonTest { ...@@ -27,10 +27,7 @@ contract Semver_Test is CommonTest {
* @notice Test the version getter * @notice Test the version getter
*/ */
function test_version() external { function test_version() external {
assertEq( assertEq(semver.version(), "7.8.0");
semver.version(),
"7.8.0"
);
} }
/** /**
...@@ -43,9 +40,6 @@ contract Semver_Test is CommonTest { ...@@ -43,9 +40,6 @@ contract Semver_Test is CommonTest {
vm.prank(alice); vm.prank(alice);
proxy.upgradeTo(address(semver)); proxy.upgradeTo(address(semver));
assertEq( assertEq(Semver(address(proxy)).version(), "7.8.0");
Semver(address(proxy)).version(),
"7.8.0"
);
} }
} }
...@@ -8,17 +8,13 @@ import { L2StandardBridge } from "../L2/L2StandardBridge.sol"; ...@@ -8,17 +8,13 @@ import { L2StandardBridge } from "../L2/L2StandardBridge.sol";
import { Predeploys } from "../libraries/Predeploys.sol"; import { Predeploys } from "../libraries/Predeploys.sol";
contract SequencerFeeVault_Test is Bridge_Initializer { contract SequencerFeeVault_Test is Bridge_Initializer {
SequencerFeeVault vault = SequencerFeeVault vault = SequencerFeeVault(payable(Predeploys.SEQUENCER_FEE_WALLET));
SequencerFeeVault(payable(Predeploys.SEQUENCER_FEE_WALLET));
address constant recipient = address(256); address constant recipient = address(256);
function setUp() public override { function setUp() public override {
super.setUp(); super.setUp();
vm.etch( vm.etch(Predeploys.SEQUENCER_FEE_WALLET, address(new SequencerFeeVault()).code);
Predeploys.SEQUENCER_FEE_WALLET,
address(new SequencerFeeVault()).code
);
vm.store( vm.store(
Predeploys.SEQUENCER_FEE_WALLET, Predeploys.SEQUENCER_FEE_WALLET,
...@@ -28,33 +24,21 @@ contract SequencerFeeVault_Test is Bridge_Initializer { ...@@ -28,33 +24,21 @@ contract SequencerFeeVault_Test is Bridge_Initializer {
} }
function test_minWithdrawalAmount() external { function test_minWithdrawalAmount() external {
assertEq( assertEq(vault.MIN_WITHDRAWAL_AMOUNT(), 15 ether);
vault.MIN_WITHDRAWAL_AMOUNT(),
15 ether
);
} }
function test_constructor() external { function test_constructor() external {
assertEq( assertEq(vault.l1FeeWallet(), recipient);
vault.l1FeeWallet(),
recipient
);
} }
function test_receive() external { function test_receive() external {
assertEq( assertEq(address(vault).balance, 0);
address(vault).balance,
0
);
vm.prank(alice); vm.prank(alice);
(bool success,) = address(vault).call{ value: 100 }(hex""); (bool success, ) = address(vault).call{ value: 100 }(hex"");
assertEq(success, true); assertEq(success, true);
assertEq( assertEq(address(vault).balance, 100);
address(vault).balance,
100
);
} }
function test_revertWithdraw() external { 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