-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e0080b
commit 26d5b8a
Showing
9 changed files
with
136 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod oracle_query; | ||
pub mod scheduler; | ||
|
||
pub use oracle_query::MockOracleQuery; | ||
pub use scheduler::MockScheduler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
use crate::traits::OracleQuery; | ||
use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; | ||
use scale_info::TypeInfo; | ||
use alloc::fmt::Debug; | ||
use frame_support::pallet_prelude::Weight; | ||
|
||
#[derive(Decode, Encode, MaxEncodedLen, TypeInfo)] | ||
#[derive(Clone, Debug, Decode, Encode, MaxEncodedLen, PartialEq, TypeInfo)] | ||
pub struct MockOracleQuery { | ||
weight: Weight, | ||
value: bool, | ||
} | ||
|
||
impl MockOracleQuery { | ||
fn new(value: bool) -> Self { | ||
Self { value } | ||
} | ||
} | ||
|
||
impl OracleQuery for MockOracleQuery { | ||
fn evaluate(&self) -> bool { | ||
self.value | ||
fn evaluate(&self) -> (Weight, bool) { | ||
(self.weight, self.value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use crate::{mock::runtime::Runtime, BoundedCallOf, CallOf}; | ||
use core::cell::RefCell; | ||
use frame_support::traits::schedule::{v3::Anon as ScheduleAnon, DispatchTime, Period, Priority}; | ||
use frame_system::{ | ||
pallet_prelude::{BlockNumberFor, OriginFor}, | ||
Call, Origin, | ||
}; | ||
use sp_runtime::{traits::Bounded, DispatchError, DispatchResult}; | ||
|
||
pub struct MockScheduler; | ||
|
||
impl MockScheduler { | ||
fn set_return_value(value: DispatchResult) { | ||
SCHEDULER_RETURN_VALUE.with(|v| *v.borrow_mut() = Some(value)); | ||
} | ||
|
||
fn called_once_with( | ||
when: DispatchTime<BlockNumberFor<Runtime>>, | ||
call: BoundedCallOf<Runtime>, | ||
) -> bool { | ||
if SCHEDULER_CALL_DATA.with(|value| value.borrow().len()) != 1 { | ||
return false; | ||
} | ||
|
||
let args = SCHEDULER_CALL_DATA | ||
.with(|value| value.borrow().first().expect("can't be empty").clone()); | ||
|
||
args == SchedulerCallData { when, call } | ||
} | ||
} | ||
|
||
#[derive(Clone, PartialEq)] | ||
struct SchedulerCallData { | ||
when: DispatchTime<BlockNumberFor<Runtime>>, | ||
call: BoundedCallOf<Runtime>, | ||
} | ||
|
||
impl ScheduleAnon<BlockNumberFor<Runtime>, CallOf<Runtime>, OriginFor<Runtime>> for MockScheduler { | ||
type Address = (); | ||
|
||
fn schedule( | ||
when: DispatchTime<BlockNumberFor<Runtime>>, | ||
_maybe_periodic: Option<Period<BlockNumberFor<Runtime>>>, | ||
_priority: Priority, | ||
_origin: OriginFor<Runtime>, | ||
call: BoundedCallOf<Runtime>, | ||
) -> Result<Self::Address, DispatchError> { | ||
SCHEDULER_CALL_DATA | ||
.with(|values| values.borrow_mut().push(SchedulerCallData { when, call })); | ||
|
||
SCHEDULER_RETURN_VALUE | ||
.with(|value| *value.borrow()) | ||
.expect("no return value configured for scheduler mock") | ||
} | ||
|
||
fn cancel(_address: Self::Address) -> Result<(), DispatchError> { | ||
unimplemented!(); | ||
} | ||
|
||
fn reschedule( | ||
_address: Self::Address, | ||
_when: DispatchTime<BlockNumberFor<Runtime>>, | ||
) -> Result<Self::Address, DispatchError> { | ||
unimplemented!(); | ||
} | ||
|
||
fn next_dispatch_time( | ||
_address: Self::Address, | ||
) -> Result<BlockNumberFor<Runtime>, DispatchError> { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
thread_local! { | ||
pub static SCHEDULER_CALL_DATA: RefCell<Vec<SchedulerCallData>> = | ||
const { RefCell::new(vec![]) }; | ||
pub static SCHEDULER_RETURN_VALUE: RefCell<Option<DispatchResult>> = | ||
const { RefCell::new(None) }; | ||
} |