Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa committed Feb 16, 2024
1 parent ef04780 commit c28afa2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
21 changes: 15 additions & 6 deletions pallets/rolldown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::{
StorageHasher,
};
use frame_system::{ensure_signed, pallet_prelude::*};
use messages::{UpdateType, PendingRequestType};
use messages::{PendingRequestType, UpdateType};
use sp_runtime::traits::SaturatedConversion;

use alloy_sol_types::SolValue;
Expand Down Expand Up @@ -219,26 +219,35 @@ pub mod pallet {
ensure!(!requests.order.is_empty(), Error::<T>::EmptyUpdate);
ensure!(requests.order.len() <= 10, Error::<T>::TooManyRequests);


let withdraws_count = requests.pendingWithdraws.len();
let deposits_count = requests.pendingDeposits.len();
let cancels_count = requests.pendingCancelResultions.len();
let l2_updates_count = requests.pendingL2UpdatesToRemove.len();

ensure!(
requests.order.iter().filter(|e| **e == PendingRequestType::DEPOSIT).count() == deposits_count,
requests.order.iter().filter(|e| **e == PendingRequestType::DEPOSIT).count() ==
deposits_count,

Check warning on line 229 in pallets/rolldown/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/rolldown/src/lib.rs#L229

Added line #L229 was not covered by tests
Error::<T>::InvalidUpdate
);
ensure!(
requests.order.iter().filter(|e| **e == PendingRequestType::WITHDRAWAL).count() == withdraws_count,
requests.order.iter().filter(|e| **e == PendingRequestType::WITHDRAWAL).count() ==
withdraws_count,
Error::<T>::InvalidUpdate

Check warning on line 235 in pallets/rolldown/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/rolldown/src/lib.rs#L234-L235

Added lines #L234 - L235 were not covered by tests
);
ensure!(
requests.order.iter().filter(|e| **e == PendingRequestType::CANCEL_RESOLUTION).count() == cancels_count,
requests
.order
.iter()

Check warning on line 240 in pallets/rolldown/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/rolldown/src/lib.rs#L239-L240

Added lines #L239 - L240 were not covered by tests
.filter(|e| **e == PendingRequestType::CANCEL_RESOLUTION)
.count() == cancels_count,
Error::<T>::InvalidUpdate

Check warning on line 243 in pallets/rolldown/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/rolldown/src/lib.rs#L242-L243

Added lines #L242 - L243 were not covered by tests
);
ensure!(
requests.order.iter().filter(|e| **e == PendingRequestType::L2_UPDATES_TO_REMOVE).count() == l2_updates_count,
requests
.order
.iter()

Check warning on line 248 in pallets/rolldown/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/rolldown/src/lib.rs#L247-L248

Added lines #L247 - L248 were not covered by tests
.filter(|e| **e == PendingRequestType::L2_UPDATES_TO_REMOVE)
.count() == l2_updates_count,
Error::<T>::InvalidUpdate

Check warning on line 251 in pallets/rolldown/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/rolldown/src/lib.rs#L250-L251

Added lines #L250 - L251 were not covered by tests
);

Expand Down
54 changes: 25 additions & 29 deletions pallets/rolldown/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ fn each_request_executed_only_once() {
forward_to_block::<Test>(11);
Rolldown::update_l2_from_l1(RuntimeOrigin::signed(BOB), update).unwrap();


forward_to_block::<Test>(14);
assert!(!pending_updates::<Test>::contains_key(sp_core::U256::from(0u128)));
assert_eq!(TokensOf::<Test>::free_balance(ETH_TOKEN_ADDRESS_MGX, &CHARLIE), 0_u128);
Expand Down Expand Up @@ -369,44 +368,41 @@ fn cancel_request() {
#[test]
#[serial]
fn reject_update_with_too_many_requests() {
ExtBuilder::new()
.execute_with_default_mocks(|| {
forward_to_block::<Test>(10);
ExtBuilder::new().execute_with_default_mocks(|| {
forward_to_block::<Test>(10);

let requests =
vec![
L1UpdateRequest::Withdraw(messages::Withdraw {
depositRecipient: ETH_RECIPIENT_ACCOUNT,
tokenAddress: ETH_TOKEN_ADDRESS,
amount: sp_core::U256::from(MILLION),
}); 11];
let requests = vec![
L1UpdateRequest::Withdraw(messages::Withdraw {
depositRecipient: ETH_RECIPIENT_ACCOUNT,
tokenAddress: ETH_TOKEN_ADDRESS,
amount: sp_core::U256::from(MILLION),
});
11
];

let withdraw_update = create_l1_update(requests);
let withdraw_update = create_l1_update(requests);

assert_err!(
Rolldown::update_l2_from_l1(RuntimeOrigin::signed(ALICE), withdraw_update),
Error::<Test>::TooManyRequests
);
});
assert_err!(
Rolldown::update_l2_from_l1(RuntimeOrigin::signed(ALICE), withdraw_update),
Error::<Test>::TooManyRequests
);
});
}

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

let update = L1Update {
order: vec![messages::PendingRequestType::DEPOSIT],
.. Default::default()
};
let update =
L1Update { order: vec![messages::PendingRequestType::DEPOSIT], ..Default::default() };

assert_err!(
Rolldown::update_l2_from_l1(RuntimeOrigin::signed(ALICE), update),
Error::<Test>::InvalidUpdate
);
});
assert_err!(
Rolldown::update_l2_from_l1(RuntimeOrigin::signed(ALICE), update),
Error::<Test>::InvalidUpdate
);
});
}

#[test]
Expand Down

0 comments on commit c28afa2

Please sign in to comment.