Skip to content

Commit

Permalink
checking tree initialization when inserting
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 6, 2024
1 parent a29b096 commit 881627c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions l1-contracts/test/NewInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ contract NewInboxTest is Test {
for (uint256 i = 0; i < _messages.length; i++) {
DataStructures.L1ToL2Msg memory message = _boundMessage(_messages[i]);

// We check whether a new tree is correctly initialized when the one in progress is full
uint256 numTrees = inbox.getNumTrees();
uint256 expectedNumTrees = inbox.treeInProgressFull() ? numTrees + 1 : numTrees;

inbox.sendL2Message(message.recipient, message.content, message.secretHash);

assertEq(inbox.getNumTrees(), expectedNumTrees, "Unexpected number of trees");
}

// Root of a tree waiting to be consumed should not change because we introduced a 1 block lag to prevent sequencer
Expand Down Expand Up @@ -201,8 +207,8 @@ contract NewInboxTest is Test {
(inbox.getToConsume() + 1 == inbox.getInProgress()) ? numTrees + 1 : numTrees;
bytes32 root = inbox.consume();

// We perform this check to verify that new tree initialization works as expected
assertEq(inbox.getNumTrees(), expectedNumTrees, "Unexptected number of trees");
// We check whether a new tree is correctly initialized when the one which was in progress was set as to consume
assertEq(inbox.getNumTrees(), expectedNumTrees, "Unexpected number of trees");

// We perform empty roots check only after first batch because after second one the following simple accounting
// does not work
Expand Down
4 changes: 4 additions & 0 deletions l1-contracts/test/harnesses/NewInboxHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ contract NewInboxHarness is NewInbox {
return inProgress;
}

function treeInProgressFull() external view returns (bool) {
return trees[inProgress].isFull();
}

function getToConsumeRoot() external view returns (bytes32) {
bytes32 root = EMPTY_ROOT;
if (toConsume > Constants.INITIAL_L2_BLOCK_NUM) {
Expand Down

0 comments on commit 881627c

Please sign in to comment.