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

[Free Calls] free-calls feedback 16Mar #201

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pallets/locker-mirror/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ benchmarks!{
ensure!(matches!(<LockedInfoByAccount<T>>::get(account.clone()), None), "There should be no value for this account");
}

set_last_processed_parachain_event {
set_last_processed_locker_event {
let caller: T::AccountId = whitelisted_caller();
let last_event_info = ProcessedEventInfo {
let last_event_info = LockerEvent {
block_number: 125,
event_index: 568,
};
<LastProcessedParachainEvent<T>>::kill();
<LastProcessedLockerEvent<T>>::kill();

let origin = if cfg!(test) {
RawOrigin::Signed(caller)
Expand All @@ -65,7 +65,7 @@ benchmarks!{
};
}: _(origin, last_event_info)
verify {
ensure!(matches!(<LastProcessedParachainEvent<T>>::get(), Some(last_event_info)), "The passed value should be stored");
ensure!(matches!(<LastProcessedLockerEvent<T>>::get(), Some(last_event_info)), "The passed value should be stored");
}


Expand Down
21 changes: 10 additions & 11 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,27 +102,27 @@ 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Last processed locker event have been set.
/// The last locker event has been processed.

LastLockerEventSet { event: LockerEvent },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LastLockerEventSet { event: LockerEvent },
LastLockerEventProcessed { event: LockerEvent },

}

#[pallet::call]
impl<T: Config> Pallet<T> {

#[pallet::weight((
<T as Config>::WeightInfo::set_last_processed_parachain_event(),
<T as Config>::WeightInfo::set_last_processed_locker_event(),
DispatchClass::Operational,
Pays::Yes,
))]
pub fn set_last_processed_parachain_event(
pub fn set_last_processed_locker_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
40 changes: 20 additions & 20 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| {
LockerMirror::set_last_processed_parachain_event(
o,
call: |origin| {
LockerMirror::set_last_processed_locker_event(
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
6 changes: 3 additions & 3 deletions pallets/locker-mirror/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sp_std::marker::PhantomData;
pub trait WeightInfo {
fn set_locked_info() -> Weight;
fn clear_locked_info() -> Weight;
fn set_last_processed_parachain_event() -> Weight;
fn set_last_processed_locker_event() -> Weight;
}

/// Weights for pallet_locker_mirror using the Substrate node and recommended hardware.
Expand All @@ -57,7 +57,7 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: unknown [0xca15211defb6ae0af15535cfecffe8c134853d48f12e991904ee9a1e3f8bd702] (r:0 w:1)
fn set_last_processed_parachain_event() -> Weight {
fn set_last_processed_locker_event() -> Weight {
(23_000_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
Expand All @@ -76,7 +76,7 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: unknown [0xca15211defb6ae0af15535cfecffe8c134853d48f12e991904ee9a1e3f8bd702] (r:0 w:1)
fn set_last_processed_parachain_event() -> Weight {
fn set_last_processed_locker_event() -> Weight {
(23_000_000 as Weight)
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
Expand Down