Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
free-calls feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Mar 18, 2022
1 parent 75280e6 commit 6c77f4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
17 changes: 8 additions & 9 deletions pallets/locker-mirror/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub mod pallet {
pub expires_at: Option<BlockNumber>,
}

/// Information about a parachain event.
/// Information about a locker event that was dispatched in the parachain.
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct ProcessedEventInfo {
pub struct LockerEvent {
/// The parachain block number at which the event was found.
pub block_number: ParachainBlockNumber,

Expand Down Expand Up @@ -91,8 +91,7 @@ pub mod pallet {

/// Stores information about last processed event on the parachain.
#[pallet::storage]
#[pallet::getter(fn last_processed_parachain_event)]
pub type LastProcessedParachainEvent<T: Config> = StorageValue<_, ProcessedEventInfo>;
pub type LastProcessedLockerEvent<T: Config> = StorageValue<_, LockerEvent>;

#[pallet::event]
#[pallet::generate_deposit(pub (super) fn deposit_event)]
Expand All @@ -103,8 +102,8 @@ pub mod pallet {
/// Locked information is cleared for an account.
LockedInfoCleared { who: T::AccountId },

/// Last processed event have been set.
LastProcessedEventSet { event: ProcessedEventInfo },
/// Last processed locker event have been set.
LastLockerEventSet { event: LockerEvent },
}

#[pallet::call]
Expand All @@ -117,13 +116,13 @@ pub mod pallet {
))]
pub fn set_last_processed_parachain_event(
origin: OriginFor<T>,
last_processed_event_info: ProcessedEventInfo,
last_processed_locker_event: LockerEvent,
) -> DispatchResultWithPostInfo {
let _ = T::OracleOrigin::ensure_origin(origin)?;

<LastProcessedParachainEvent<T>>::put(last_processed_event_info.clone());
<LastProcessedLockerEvent<T>>::put(last_processed_locker_event.clone());

Self::deposit_event(Event::LastProcessedEventSet { event: last_processed_event_info });
Self::deposit_event(Event::LastLockerEventSet { event: last_processed_locker_event });

Ok(Pays::No.into())
}
Expand Down
38 changes: 19 additions & 19 deletions pallets/locker-mirror/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(non_snake_case)]
use frame_benchmarking::account;
use crate::{mock::*, LockedInfoByAccount, BalanceOf, Config, LockedInfoOf, ProcessedEventInfo, LastProcessedParachainEvent, LockedInfo};
use crate::{mock::*, LockedInfoByAccount, BalanceOf, Config, LockedInfoOf, LockerEvent, LastProcessedLockerEvent, LockedInfo};
use frame_support::{assert_ok, assert_err, assert_noop, assert_storage_noop};
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::weights::{Pays, PostDispatchInfo};
Expand Down Expand Up @@ -66,9 +66,9 @@ fn set_locked_info_call_with_origin_fixture() -> CallFixtureType!() {
initialization: || {
assert_eq!(<LockedInfoByAccount<Test>>::iter().count(), 0);
},
call: |o| {
call: |origin| {
LockerMirror::set_locked_info(
o,
origin,
subject_account_n(23),
LOCKED_INFO.clone(),
)
Expand Down Expand Up @@ -98,9 +98,9 @@ fn clear_locked_info_call_with_origin_fixture() -> CallFixtureType!() {
);
assert_eq!(<LockedInfoByAccount<Test>>::iter().count(), 1);
},
call: |o| {
call: |origin| {
LockerMirror::clear_locked_info(
o,
origin,
subject_account_n(32),
)
},
Expand All @@ -112,22 +112,22 @@ fn clear_locked_info_call_with_origin_fixture() -> CallFixtureType!() {

#[fixture]
fn set_last_processed_parachain_event_call_with_origin_fixture() -> CallFixtureType!() {
static EVENT: ProcessedEventInfo = ProcessedEventInfo {
static EVENT: LockerEvent = LockerEvent {
block_number: 11u32,
event_index: 34u32,
};
CallFixture!(
initialization: || {
assert_eq!(<LastProcessedParachainEvent<Test>>::get(), None);
assert_eq!(<LastProcessedLockerEvent<Test>>::get(), None);
},
call: |o| {
call: |origin| {
LockerMirror::set_last_processed_parachain_event(
o,
origin,
EVENT.clone(),
)
},
assertion: || {
assert_eq!(<LastProcessedParachainEvent<Test>>::get().unwrap(), EVENT.clone());
assert_eq!(<LastProcessedLockerEvent<Test>>::get().unwrap(), EVENT.clone());
},
)
}
Expand All @@ -137,15 +137,15 @@ fn set_last_processed_parachain_event_call_with_origin_fixture() -> CallFixtureT
#[case::set_locked_info(set_locked_info_call_with_origin_fixture())]
#[case::clear_locked_info(clear_locked_info_call_with_origin_fixture())]
#[case::set_last_processed_parachain_event(set_last_processed_parachain_event_call_with_origin_fixture())]
fn call_cases(
fn common_cases(
#[case]
call_fixture: CallFixtureType!(),
) {}

////////////////


#[apply(call_cases)]
#[apply(common_cases)]
fn should_fail_noop_when_unsigned(
#[case]
call_fixture: CallFixtureType!(),
Expand All @@ -156,7 +156,7 @@ fn should_fail_noop_when_unsigned(
});
}

#[apply(call_cases)]
#[apply(common_cases)]
fn should_fail_noop_when_non_oracle(
#[case]
call_fixture: CallFixtureType!(),
Expand All @@ -174,8 +174,8 @@ fn should_fail_noop_when_non_oracle(
});
}

#[apply(call_cases)]
fn should_ok_if_when_oracle(
#[apply(common_cases)]
fn should_ok_when_oracle(
#[case]
call_fixture: CallFixtureType!(),
) {
Expand All @@ -191,7 +191,7 @@ fn should_ok_if_when_oracle(
});
}

#[apply(call_cases)]
#[apply(common_cases)]
fn should_pay_when_caller_is_not_oracle(
#[case]
call_fixture: CallFixtureType!(),
Expand All @@ -214,7 +214,7 @@ fn should_pay_when_caller_is_not_oracle(
}


#[apply(call_cases)]
#[apply(common_cases)]
fn should_not_pay_when_caller_is_oracle(
#[case]
call_fixture: CallFixtureType!(),
Expand All @@ -233,8 +233,8 @@ fn should_not_pay_when_caller_is_oracle(
});
}

#[apply(call_cases)]
fn check_storage_is_mutated_correctly(
#[apply(common_cases)]
fn check_if_storage_is_mutated_correctly(
#[case]
call_fixture: CallFixtureType!(),
) {
Expand Down

0 comments on commit 6c77f4a

Please sign in to comment.