Skip to content

Commit 68cc55a

Browse files
authored
Merge pull request #280 from OffchainLabs/test-1
test: improve coverage
2 parents 8653940 + 842e3f4 commit 68cc55a

5 files changed

+165
-16
lines changed

test/foundry/AbsBridge.t.sol

+21
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,27 @@ abstract contract AbsBridgeTest is Test {
457457
AbsBridge(address(bridge)).setSequencerReportedSubMessageCount(123);
458458
}
459459

460+
function test_updateRollupAddress() public {
461+
vm.prank(rollup);
462+
bridge.updateRollupAddress(IOwnable(address(1337)));
463+
assertEq(address(bridge.rollup()), address(1337), "Invalid rollup");
464+
}
465+
466+
function test_updateRollupAddress_revert_NotOwner() public {
467+
vm.mockCall(
468+
address(rollup),
469+
0,
470+
abi.encodeWithSelector(IOwnable.owner.selector),
471+
abi.encode(address(1337))
472+
);
473+
vm.expectRevert(
474+
abi.encodeWithSelector(
475+
NotRollupOrOwner.selector, address(this), address(rollup), address(1337)
476+
)
477+
);
478+
bridge.updateRollupAddress(IOwnable(address(1234)));
479+
}
480+
460481
/**
461482
*
462483
* Event declarations

test/foundry/AbsInbox.t.sol

+8
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ abstract contract AbsInboxTest is Test {
255255
inbox.sendL2Message(abi.encodePacked("some msg"));
256256
}
257257

258+
function test_sendL2Message_revert_DataTooLarge() public {
259+
uint256 maxDataSize = inbox.maxDataSize();
260+
bytes memory data = new bytes(maxDataSize + 1);
261+
vm.expectRevert(abi.encodeWithSelector(DataTooLarge.selector, maxDataSize + 1, maxDataSize));
262+
vm.prank(user);
263+
inbox.sendL2Message(data);
264+
}
265+
258266
function test_sendL2Message_revert_NotAllowed() public {
259267
vm.prank(rollup);
260268
inbox.setAllowListEnabled(true);

test/foundry/AbsOutbox.t.sol

+36-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.4;
33

44
import "forge-std/Test.sol";
55
import "./util/TestUtil.sol";
6-
import "../../src/bridge/IOutbox.sol";
6+
import "../../src/bridge/AbsOutbox.sol";
77
import "../../src/bridge/IBridge.sol";
88

99
abstract contract AbsOutboxTest is Test {
@@ -25,4 +25,39 @@ abstract contract AbsOutboxTest is Test {
2525
assertEq(outbox.l2ToL1Timestamp(), 0, "Invalid l2ToL1Timestamp");
2626
assertEq(outbox.l2ToL1OutputId(), bytes32(0), "Invalid l2ToL1OutputId");
2727
}
28+
29+
function test_updateRollupAddress() public {
30+
vm.prank(rollup);
31+
bridge.updateRollupAddress(IOwnable(address(1337)));
32+
vm.mockCall(
33+
address(rollup),
34+
0,
35+
abi.encodeWithSelector(IOwnable.owner.selector),
36+
abi.encode(address(this))
37+
);
38+
outbox.updateRollupAddress();
39+
assertEq(address(outbox.rollup()), address(1337), "Invalid rollup");
40+
}
41+
42+
function test_updateRollupAddress_revert_NotOwner() public {
43+
vm.mockCall(
44+
address(rollup),
45+
0,
46+
abi.encodeWithSelector(IOwnable.owner.selector),
47+
abi.encode(address(1337))
48+
);
49+
vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337)));
50+
outbox.updateRollupAddress();
51+
}
52+
53+
function test_executeTransactionSimulation(
54+
address from
55+
) public {
56+
vm.assume(from != address(0));
57+
vm.prank(from);
58+
vm.expectRevert(SimulationOnlyEntrypoint.selector);
59+
outbox.executeTransactionSimulation(
60+
0, from, address(1337), 0, 0, 0, 0, abi.encodePacked("some msg")
61+
);
62+
}
2863
}

test/foundry/AbsRollupEventInbox.t.sol

+24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ abstract contract AbsRollupEventInboxTest is Test {
2525
rollupEventInbox.initialize(bridge);
2626
}
2727

28+
function test_updateRollupAddress() public {
29+
vm.prank(rollup);
30+
bridge.updateRollupAddress(IOwnable(address(1337)));
31+
vm.mockCall(
32+
address(rollup),
33+
0,
34+
abi.encodeWithSelector(IOwnable.owner.selector),
35+
abi.encode(address(this))
36+
);
37+
rollupEventInbox.updateRollupAddress();
38+
assertEq(address(rollupEventInbox.rollup()), address(1337), "Invalid rollup");
39+
}
40+
41+
function test_updateRollupAddress_revert_NotOwner() public {
42+
vm.mockCall(
43+
address(rollup),
44+
0,
45+
abi.encodeWithSelector(IOwnable.owner.selector),
46+
abi.encode(address(1337))
47+
);
48+
vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337)));
49+
rollupEventInbox.updateRollupAddress();
50+
}
51+
2852
/**
2953
*
3054
* Event declarations

test/foundry/SequencerInbox.t.sol

+76-15
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ contract SequencerInboxTest is Test {
6666
bool isArbHosted,
6767
bool isDelayBufferable,
6868
BufferConfig memory bufferConfig
69-
) internal returns (SequencerInbox, Bridge) {
69+
) internal returns (SequencerInbox, Bridge, address) {
7070
RollupMock rollupMock = new RollupMock(rollupOwner);
7171
Bridge bridgeImpl = new Bridge();
7272
Bridge bridge =
@@ -93,7 +93,7 @@ contract SequencerInboxTest is Test {
9393
vm.prank(rollupOwner);
9494
bridge.setSequencerInbox(address(seqInbox));
9595

96-
return (seqInbox, bridge);
96+
return (seqInbox, bridge, address(seqInboxImpl));
9797
}
9898

9999
function deployFeeTokenBasedRollup() internal returns (SequencerInbox, ERC20Bridge) {
@@ -227,7 +227,7 @@ contract SequencerInboxTest is Test {
227227
function testAddSequencerL2BatchFromOrigin(
228228
BufferConfig memory bufferConfig
229229
) public {
230-
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, false, bufferConfig);
230+
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, false, bufferConfig);
231231
address delayedInboxSender = address(140);
232232
uint8 delayedInboxKind = 3;
233233
bytes32 messageDataHash = RAND.Bytes32();
@@ -355,7 +355,7 @@ contract SequencerInboxTest is Test {
355355
abi.encodeWithSelector(ArbSys.arbOSVersion.selector),
356356
abi.encode(uint256(11))
357357
);
358-
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(true, false, bufferConfig);
358+
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(true, false, bufferConfig);
359359

360360
address delayedInboxSender = address(140);
361361
uint8 delayedInboxKind = 3;
@@ -414,7 +414,7 @@ contract SequencerInboxTest is Test {
414414
}
415415

416416
function testAddSequencerL2BatchFromOriginReverts() public {
417-
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, false, bufferConfigDefault);
417+
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, false, bufferConfigDefault);
418418
address delayedInboxSender = address(140);
419419
uint8 delayedInboxKind = 3;
420420
bytes32 messageDataHash = RAND.Bytes32();
@@ -517,7 +517,7 @@ contract SequencerInboxTest is Test {
517517
BufferConfig memory bufferConfig
518518
) public returns (SequencerInbox, SequencerInbox) {
519519
vm.assume(DelayBuffer.isValidBufferConfig(bufferConfig));
520-
(SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault);
520+
(SequencerInbox seqInbox,,) = deployRollup(false, false, bufferConfigDefault);
521521
SequencerInbox seqInboxImpl = new SequencerInbox(maxDataSize, dummyReader4844, false, true);
522522
vm.prank(proxyAdmin);
523523
TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall(
@@ -606,7 +606,7 @@ contract SequencerInboxTest is Test {
606606
BufferConfig memory bufferConfig
607607
) public {
608608
vm.assume(DelayBuffer.isValidBufferConfig(bufferConfig));
609-
(SequencerInbox seqInbox,) = deployRollup(false, true, bufferConfig);
609+
(SequencerInbox seqInbox,,) = deployRollup(false, true, bufferConfig);
610610
vm.prank(rollupOwner);
611611
seqInbox.setBufferConfig(bufferConfig);
612612
}
@@ -615,24 +615,27 @@ contract SequencerInboxTest is Test {
615615
BufferConfig memory bufferConfigInvalid
616616
) public {
617617
vm.assume(!DelayBuffer.isValidBufferConfig(bufferConfigInvalid));
618-
(SequencerInbox seqInbox,) = deployRollup(false, true, bufferConfigDefault);
618+
(SequencerInbox seqInbox,,) = deployRollup(false, true, bufferConfigDefault);
619619
vm.expectRevert(abi.encodeWithSelector(BadBufferConfig.selector));
620620
vm.prank(rollupOwner);
621621
seqInbox.setBufferConfig(bufferConfigInvalid);
622622
}
623623

624-
function testSetMaxTimeVariationOverflow(
624+
function testSetMaxTimeVariation(
625625
uint256 delayBlocks,
626626
uint256 futureBlocks,
627627
uint256 delaySeconds,
628628
uint256 futureSeconds
629629
) public {
630-
vm.assume(delayBlocks > uint256(type(uint64).max));
631-
vm.assume(futureBlocks > uint256(type(uint64).max));
632-
vm.assume(delaySeconds > uint256(type(uint64).max));
633-
vm.assume(futureSeconds > uint256(type(uint64).max));
634-
(SequencerInbox seqInbox,) = deployRollup(false, false, bufferConfigDefault);
635-
vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector));
630+
(SequencerInbox seqInbox,,) = deployRollup(false, false, bufferConfigDefault);
631+
bool checkValue = true;
632+
if (
633+
delayBlocks > uint256(type(uint64).max) || futureBlocks > uint256(type(uint64).max)
634+
|| delaySeconds > uint256(type(uint64).max) || futureSeconds > uint256(type(uint64).max)
635+
) {
636+
vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector));
637+
checkValue = false;
638+
}
636639
vm.prank(rollupOwner);
637640
seqInbox.setMaxTimeVariation(
638641
ISequencerInbox.MaxTimeVariation({
@@ -642,5 +645,63 @@ contract SequencerInboxTest is Test {
642645
futureSeconds: futureSeconds
643646
})
644647
);
648+
(uint256 _delayBlocks, uint256 _futureBlocks, uint256 _delaySeconds, uint256 _futureSeconds)
649+
= seqInbox.maxTimeVariation();
650+
if (checkValue) {
651+
assertEq(_delayBlocks, delayBlocks);
652+
assertEq(_futureBlocks, futureBlocks);
653+
assertEq(_delaySeconds, delaySeconds);
654+
assertEq(_futureSeconds, futureSeconds);
655+
}
656+
}
657+
658+
function test_updateRollupAddress() public {
659+
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, true, bufferConfigDefault);
660+
address rollup = address(bridge.rollup());
661+
vm.prank(rollup);
662+
bridge.updateRollupAddress(IOwnable(address(1337)));
663+
vm.mockCall(
664+
address(rollup),
665+
0,
666+
abi.encodeWithSelector(IOwnable.owner.selector),
667+
abi.encode(address(this))
668+
);
669+
seqInbox.updateRollupAddress();
670+
assertEq(address(seqInbox.rollup()), address(1337), "Invalid rollup");
671+
}
672+
673+
function test_updateRollupAddress_revert_NotOwner() public {
674+
(SequencerInbox seqInbox, Bridge bridge,) = deployRollup(false, true, bufferConfigDefault);
675+
address rollup = address(bridge.rollup());
676+
vm.mockCall(
677+
address(rollup),
678+
0,
679+
abi.encodeWithSelector(IOwnable.owner.selector),
680+
abi.encode(address(1337))
681+
);
682+
vm.expectRevert(abi.encodeWithSelector(NotOwner.selector, address(this), address(1337)));
683+
seqInbox.updateRollupAddress();
684+
}
685+
686+
function test_postUpgradeInit_revert_NotDelayBufferable() public {
687+
(SequencerInbox seqInbox,, address seqInboxImpl) =
688+
deployRollup(false, false, bufferConfigDefault);
689+
vm.expectRevert(abi.encodeWithSelector(NotDelayBufferable.selector));
690+
vm.prank(proxyAdmin);
691+
TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall(
692+
address(seqInboxImpl),
693+
abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector, bufferConfigDefault)
694+
);
695+
}
696+
697+
function test_postUpgradeInit_revert_AlreadyInit() public {
698+
(SequencerInbox seqInbox,, address seqInboxImpl) =
699+
deployRollup(false, true, bufferConfigDefault);
700+
vm.expectRevert(abi.encodeWithSelector(AlreadyInit.selector));
701+
vm.prank(proxyAdmin);
702+
TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall(
703+
address(seqInboxImpl),
704+
abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector, bufferConfigDefault)
705+
);
645706
}
646707
}

0 commit comments

Comments
 (0)