Skip to content

Commit

Permalink
fix update validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa committed Nov 27, 2024
1 parent 242785a commit 6d561d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pallets/rolldown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ impl<T: Config> Pallet<T> {
Error::<T>::WrongRequestId
);

let last_id = lowest_id +
let last_id = lowest_id.saturating_sub(1u128) +
(update.pendingDeposits.len() as u128) +
(update.pendingCancelResolutions.len() as u128);

Expand Down
25 changes: 25 additions & 0 deletions pallets/rolldown/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,31 @@ fn reject_update_with_invalid_too_high_request_id() {
});
}

#[test]
#[serial]
fn reject_update_without_new_updates() {
ExtBuilder::new().execute_with_default_mocks(|| {
forward_to_block::<Test>(10);

let deposit_update = L1UpdateBuilder::default()
.with_requests(vec![L1UpdateRequest::Deposit(Default::default())])
.with_offset(1u128)
.build();

Rolldown::update_l2_from_l1_unsafe(RuntimeOrigin::signed(ALICE), deposit_update.clone())
.unwrap();
assert_eq!(LastProcessedRequestOnL2::<Test>::get(consts::CHAIN), 0u128.into());

forward_to_block::<Test>(16);
assert_eq!(LastProcessedRequestOnL2::<Test>::get(consts::CHAIN), 1u128.into());

assert_err!(
Rolldown::update_l2_from_l1_unsafe(RuntimeOrigin::signed(ALICE), deposit_update),
Error::<Test>::WrongRequestId
);
});
}

#[test]
#[serial]
fn reject_second_update_in_the_same_block() {
Expand Down

0 comments on commit 6d561d0

Please sign in to comment.