Skip to content

Commit

Permalink
Merge pull request #280 from OffchainLabs/test-1
Browse files Browse the repository at this point in the history
test: improve coverage
  • Loading branch information
gzeoneth authored Dec 17, 2024
2 parents 8653940 + 842e3f4 commit 68cc55a
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 16 deletions.
21 changes: 21 additions & 0 deletions test/foundry/AbsBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,27 @@ abstract contract AbsBridgeTest is Test {
AbsBridge(address(bridge)).setSequencerReportedSubMessageCount(123);
}

function test_updateRollupAddress() public {
vm.prank(rollup);
bridge.updateRollupAddress(IOwnable(address(1337)));
assertEq(address(bridge.rollup()), address(1337), "Invalid rollup");
}

function test_updateRollupAddress_revert_NotOwner() public {
vm.mockCall(
address(rollup),
0,
abi.encodeWithSelector(IOwnable.owner.selector),
abi.encode(address(1337))
);
vm.expectRevert(
abi.encodeWithSelector(
NotRollupOrOwner.selector, address(this), address(rollup), address(1337)
)
);
bridge.updateRollupAddress(IOwnable(address(1234)));
}

/**
*
* Event declarations
Expand Down
8 changes: 8 additions & 0 deletions test/foundry/AbsInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ abstract contract AbsInboxTest is Test {
inbox.sendL2Message(abi.encodePacked("some msg"));
}

function test_sendL2Message_revert_DataTooLarge() public {
uint256 maxDataSize = inbox.maxDataSize();
bytes memory data = new bytes(maxDataSize + 1);
vm.expectRevert(abi.encodeWithSelector(DataTooLarge.selector, maxDataSize + 1, maxDataSize));
vm.prank(user);
inbox.sendL2Message(data);
}

function test_sendL2Message_revert_NotAllowed() public {
vm.prank(rollup);
inbox.setAllowListEnabled(true);
Expand Down
37 changes: 36 additions & 1 deletion test/foundry/AbsOutbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.4;

import "forge-std/Test.sol";
import "./util/TestUtil.sol";
import "../../src/bridge/IOutbox.sol";
import "../../src/bridge/AbsOutbox.sol";
import "../../src/bridge/IBridge.sol";

abstract contract AbsOutboxTest is Test {
Expand All @@ -25,4 +25,39 @@ abstract contract AbsOutboxTest is Test {
assertEq(outbox.l2ToL1Timestamp(), 0, "Invalid l2ToL1Timestamp");
assertEq(outbox.l2ToL1OutputId(), bytes32(0), "Invalid l2ToL1OutputId");
}

function test_updateRollupAddress() public {
vm.prank(rollup);
bridge.updateRollupAddress(IOwnable(address(1337)));
vm.mockCall(
address(rollup),
0,
abi.encodeWithSelector(IOwnable.owner.selector),
abi.encode(address(this))
);
outbox.updateRollupAddress();
assertEq(address(outbox.rollup()), address(1337), "Invalid rollup");
}

function test_updateRollupAddress_revert_NotOwner() public {
vm.mockCall(
address(rollup),
0,
abi.encodeWithSelector(IOwnable.owner.selector),
abi.encode(address(1337))
);
vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337)));
outbox.updateRollupAddress();
}

function test_executeTransactionSimulation(
address from
) public {
vm.assume(from != address(0));
vm.prank(from);
vm.expectRevert(SimulationOnlyEntrypoint.selector);
outbox.executeTransactionSimulation(
0, from, address(1337), 0, 0, 0, 0, abi.encodePacked("some msg")
);
}
}
24 changes: 24 additions & 0 deletions test/foundry/AbsRollupEventInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ abstract contract AbsRollupEventInboxTest is Test {
rollupEventInbox.initialize(bridge);
}

function test_updateRollupAddress() public {
vm.prank(rollup);
bridge.updateRollupAddress(IOwnable(address(1337)));
vm.mockCall(
address(rollup),
0,
abi.encodeWithSelector(IOwnable.owner.selector),
abi.encode(address(this))
);
rollupEventInbox.updateRollupAddress();
assertEq(address(rollupEventInbox.rollup()), address(1337), "Invalid rollup");
}

function test_updateRollupAddress_revert_NotOwner() public {
vm.mockCall(
address(rollup),
0,
abi.encodeWithSelector(IOwnable.owner.selector),
abi.encode(address(1337))
);
vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337)));
rollupEventInbox.updateRollupAddress();
}

/**
*
* Event declarations
Expand Down
91 changes: 76 additions & 15 deletions test/foundry/SequencerInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract SequencerInboxTest is Test {
bool isArbHosted,
bool isDelayBufferable,
BufferConfig memory bufferConfig
) internal returns (SequencerInbox, Bridge) {
) internal returns (SequencerInbox, Bridge, address) {
RollupMock rollupMock = new RollupMock(rollupOwner);
Bridge bridgeImpl = new Bridge();
Bridge bridge =
Expand All @@ -93,7 +93,7 @@ contract SequencerInboxTest is Test {
vm.prank(rollupOwner);
bridge.setSequencerInbox(address(seqInbox));

return (seqInbox, bridge);
return (seqInbox, bridge, address(seqInboxImpl));
}

function deployFeeTokenBasedRollup() internal returns (SequencerInbox, ERC20Bridge) {
Expand Down Expand Up @@ -227,7 +227,7 @@ contract SequencerInboxTest is Test {
function testAddSequencerL2BatchFromOrigin(
BufferConfig memory bufferConfig
) public {
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, false, bufferConfig);
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, false, bufferConfig);
address delayedInboxSender = address(140);
uint8 delayedInboxKind = 3;
bytes32 messageDataHash = RAND.Bytes32();
Expand Down Expand Up @@ -355,7 +355,7 @@ contract SequencerInboxTest is Test {
abi.encodeWithSelector(ArbSys.arbOSVersion.selector),
abi.encode(uint256(11))
);
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(true, false, bufferConfig);
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(true, false, bufferConfig);

address delayedInboxSender = address(140);
uint8 delayedInboxKind = 3;
Expand Down Expand Up @@ -414,7 +414,7 @@ contract SequencerInboxTest is Test {
}

function testAddSequencerL2BatchFromOriginReverts() public {
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, false, bufferConfigDefault);
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, false, bufferConfigDefault);
address delayedInboxSender = address(140);
uint8 delayedInboxKind = 3;
bytes32 messageDataHash = RAND.Bytes32();
Expand Down Expand Up @@ -517,7 +517,7 @@ contract SequencerInboxTest is Test {
BufferConfig memory bufferConfig
) public returns (SequencerInbox, SequencerInbox) {
vm.assume(DelayBuffer.isValidBufferConfig(bufferConfig));
(SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault);
(SequencerInbox seqInbox,,) = deployRollup(false, false, bufferConfigDefault);
SequencerInbox seqInboxImpl = new SequencerInbox(maxDataSize, dummyReader4844, false, true);
vm.prank(proxyAdmin);
TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall(
Expand Down Expand Up @@ -606,7 +606,7 @@ contract SequencerInboxTest is Test {
BufferConfig memory bufferConfig
) public {
vm.assume(DelayBuffer.isValidBufferConfig(bufferConfig));
(SequencerInbox seqInbox,) = deployRollup(false, true, bufferConfig);
(SequencerInbox seqInbox,,) = deployRollup(false, true, bufferConfig);
vm.prank(rollupOwner);
seqInbox.setBufferConfig(bufferConfig);
}
Expand All @@ -615,24 +615,27 @@ contract SequencerInboxTest is Test {
BufferConfig memory bufferConfigInvalid
) public {
vm.assume(!DelayBuffer.isValidBufferConfig(bufferConfigInvalid));
(SequencerInbox seqInbox,) = deployRollup(false, true, bufferConfigDefault);
(SequencerInbox seqInbox,,) = deployRollup(false, true, bufferConfigDefault);
vm.expectRevert(abi.encodeWithSelector(BadBufferConfig.selector));
vm.prank(rollupOwner);
seqInbox.setBufferConfig(bufferConfigInvalid);
}

function testSetMaxTimeVariationOverflow(
function testSetMaxTimeVariation(
uint256 delayBlocks,
uint256 futureBlocks,
uint256 delaySeconds,
uint256 futureSeconds
) public {
vm.assume(delayBlocks > uint256(type(uint64).max));
vm.assume(futureBlocks > uint256(type(uint64).max));
vm.assume(delaySeconds > uint256(type(uint64).max));
vm.assume(futureSeconds > uint256(type(uint64).max));
(SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault);
vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector));
(SequencerInbox seqInbox,,) = deployRollup(false, false, bufferConfigDefault);
bool checkValue = true;
if (
delayBlocks > uint256(type(uint64).max) || futureBlocks > uint256(type(uint64).max)
|| delaySeconds > uint256(type(uint64).max) || futureSeconds > uint256(type(uint64).max)
) {
vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector));
checkValue = false;
}
vm.prank(rollupOwner);
seqInbox.setMaxTimeVariation(
ISequencerInbox.MaxTimeVariation({
Expand All @@ -642,5 +645,63 @@ contract SequencerInboxTest is Test {
futureSeconds: futureSeconds
})
);
(uint256 _delayBlocks, uint256 _futureBlocks, uint256 _delaySeconds, uint256 _futureSeconds)
= seqInbox.maxTimeVariation();
if (checkValue) {
assertEq(_delayBlocks, delayBlocks);
assertEq(_futureBlocks, futureBlocks);
assertEq(_delaySeconds, delaySeconds);
assertEq(_futureSeconds, futureSeconds);
}
}

function test_updateRollupAddress() public {
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, true, bufferConfigDefault);
address rollup = address(bridge.rollup());
vm.prank(rollup);
bridge.updateRollupAddress(IOwnable(address(1337)));
vm.mockCall(
address(rollup),
0,
abi.encodeWithSelector(IOwnable.owner.selector),
abi.encode(address(this))
);
seqInbox.updateRollupAddress();
assertEq(address(seqInbox.rollup()), address(1337), "Invalid rollup");
}

function test_updateRollupAddress_revert_NotOwner() public {
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, true, bufferConfigDefault);
address rollup = address(bridge.rollup());
vm.mockCall(
address(rollup),
0,
abi.encodeWithSelector(IOwnable.owner.selector),
abi.encode(address(1337))
);
vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337)));
seqInbox.updateRollupAddress();
}

function test_postUpgradeInit_revert_NotDelayBufferable() public {
(SequencerInbox seqInbox,, address seqInboxImpl) =
deployRollup(false, false, bufferConfigDefault);
vm.expectRevert(abi.encodeWithSelector(NotDelayBufferable.selector));
vm.prank(proxyAdmin);
TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall(
address(seqInboxImpl),
abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector, bufferConfigDefault)
);
}

function test_postUpgradeInit_revert_AlreadyInit() public {
(SequencerInbox seqInbox,, address seqInboxImpl) =
deployRollup(false, true, bufferConfigDefault);
vm.expectRevert(abi.encodeWithSelector(AlreadyInit.selector));
vm.prank(proxyAdmin);
TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall(
address(seqInboxImpl),
abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector, bufferConfigDefault)
);
}
}

0 comments on commit 68cc55a

Please sign in to comment.