Skip to content

Commit

Permalink
Rename type and structs
Browse files Browse the repository at this point in the history
  • Loading branch information
ebma committed Sep 7, 2023
1 parent c2d84b1 commit e508da1
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 28 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pallets/issue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub use currency::{
use oracle::{
dia::DiaOracleAdapter,
testing_utils::{
MockConvertMoment, MockConvertPrice, MockDataCollector, MockDiaOracle,
MockOracleKeyConvertor,
MockConvertMoment, MockConvertPrice, MockDataFeeder, MockDiaOracle, MockOracleKeyConvertor,
},
};
pub use primitives::CurrencyId;
Expand Down Expand Up @@ -290,7 +289,7 @@ impl oracle::Config for Test {
MockConvertPrice,
MockConvertMoment<Moment>,
>;
type DataFeedProvider = MockDataCollector<AccountId, Moment>;
type DataFeeder = MockDataFeeder<AccountId, Moment>;
}

parameter_types! {
Expand Down
5 changes: 2 additions & 3 deletions pallets/nomination/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use currency::Amount;
use oracle::{
dia::DiaOracleAdapter,
testing_utils::{
MockConvertMoment, MockConvertPrice, MockDataCollector, MockDiaOracle,
MockOracleKeyConvertor,
MockConvertMoment, MockConvertPrice, MockDataFeeder, MockDiaOracle, MockOracleKeyConvertor,
},
};
pub use primitives::CurrencyId;
Expand Down Expand Up @@ -287,7 +286,7 @@ impl oracle::Config for Test {
MockConvertPrice,
MockConvertMoment<Moment>,
>;
type DataFeedProvider = MockDataCollector<AccountId, Moment>;
type DataFeeder = MockDataFeeder<AccountId, Moment>;
}

impl Config for Test {
Expand Down
8 changes: 4 additions & 4 deletions pallets/oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub mod pallet {
>;

#[cfg(feature = "testing-utils")]
type DataFeedProvider: testing_utils::DataFeederExtended<
type DataFeeder: testing_utils::DataFeederExtended<
OracleKey,
TimestampedValue<Self::UnsignedFixedPoint, Self::Moment>,
Self::AccountId,
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<T: Config> Pallet<T> {
for (key, value) in values {
let timestamped =
orml_oracle::TimestampedValue { timestamp: Self::get_current_time(), value };
T::DataFeedProvider::feed_value(oracle.clone(), key.clone(), timestamped)
T::DataFeeder::feed_value(oracle.clone(), key.clone(), timestamped)
.expect("Expect store value by key");
if !oracle_keys.contains(&key) {
oracle_keys.push(key);
Expand All @@ -259,14 +259,14 @@ impl<T: Config> Pallet<T> {
#[cfg(feature = "testing-utils")]
pub fn _clear_values() -> DispatchResult {
use crate::testing_utils::DataFeederExtended;
T::DataFeedProvider::clear_all_values()
T::DataFeeder::clear_all_values()
}

// public only for testing purposes
#[cfg(feature = "testing-utils")]
pub fn _acquire_lock() -> MutexGuard<'static, ()> {
use crate::testing_utils::DataFeederExtended;
T::DataFeedProvider::acquire_lock()
T::DataFeeder::acquire_lock()
}

/// Public getters
Expand Down
2 changes: 1 addition & 1 deletion pallets/oracle/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Config for Test {
MockConvertPrice,
MockConvertMoment<Moment>,
>;
type DataFeedProvider = crate::testing_utils::MockDataCollector<AccountId, Moment>;
type DataFeeder = crate::testing_utils::MockDataFeeder<AccountId, Moment>;
}

parameter_types! {
Expand Down
12 changes: 8 additions & 4 deletions pallets/oracle/src/testing_utils/mock_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct Data {
pub timestamp: u64,
}

/// This struct is used to mock the DIA oracle. It implements the `DiaOracle` trait and uses the
/// static `COINS` variable to store the mock data.
pub struct MockDiaOracle;
impl dia_oracle::DiaOracle for MockDiaOracle {
fn get_coin_info(
Expand Down Expand Up @@ -83,13 +85,15 @@ impl dia_oracle::DiaOracle for MockDiaOracle {
}
}

pub struct MockDataCollector<AccountId, Moment>(
/// This struct is used to make it possible to feed values to the mock oracle. It implements the
/// `DataFeederExtended` trait and uses the static `COINS` variable to store the mock data.
pub struct MockDataFeeder<AccountId, Moment>(
sp_std::marker::PhantomData<AccountId>,
sp_std::marker::PhantomData<Moment>,
);

impl<AccountId, Moment> DataProvider<Key, TimestampedValue<UnsignedFixedPoint, Moment>>
for MockDataCollector<AccountId, Moment>
for MockDataFeeder<AccountId, Moment>
{
// We need to implement the DataFeeder trait to the MockDataCollector but this function is never
// used
Expand All @@ -100,7 +104,7 @@ impl<AccountId, Moment> DataProvider<Key, TimestampedValue<UnsignedFixedPoint, M

impl<AccountId, Moment: Into<u64>>
DataFeeder<Key, TimestampedValue<UnsignedFixedPoint, Moment>, AccountId>
for MockDataCollector<AccountId, Moment>
for MockDataFeeder<AccountId, Moment>
{
fn feed_value(
_who: AccountId,
Expand All @@ -124,7 +128,7 @@ impl<AccountId, Moment: Into<u64>>

impl<AccountId, Moment: Into<u64>>
DataFeederExtended<Key, TimestampedValue<UnsignedFixedPoint, Moment>, AccountId>
for MockDataCollector<AccountId, Moment>
for MockDataFeeder<AccountId, Moment>
{
fn clear_all_values() -> DispatchResult {
let mut coins = COINS
Expand Down
2 changes: 1 addition & 1 deletion pallets/oracle/src/testing_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod mock_collector;
pub use mock_collector::{DataFeederExtended, MockDataCollector, MockDiaOracle};
pub use mock_collector::{DataFeederExtended, MockDataFeeder, MockDiaOracle};

mod mock_convertors;
pub use mock_convertors::{MockConvertMoment, MockConvertPrice, MockOracleKeyConvertor};
5 changes: 2 additions & 3 deletions pallets/redeem/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub use currency::{
use oracle::{
dia::DiaOracleAdapter,
testing_utils::{
MockConvertMoment, MockConvertPrice, MockDataCollector, MockDiaOracle,
MockOracleKeyConvertor,
MockConvertMoment, MockConvertPrice, MockDataFeeder, MockDiaOracle, MockOracleKeyConvertor,
},
};
pub use oracle::{CurrencyId, OracleKey};
Expand Down Expand Up @@ -307,7 +306,7 @@ impl oracle::Config for Test {
MockConvertPrice,
MockConvertMoment<Moment>,
>;
type DataFeedProvider = MockDataCollector<AccountId, Moment>;
type DataFeeder = MockDataFeeder<AccountId, Moment>;
}

parameter_types! {
Expand Down
5 changes: 2 additions & 3 deletions pallets/replace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub use currency::{
use oracle::{
dia::DiaOracleAdapter,
testing_utils::{
MockConvertMoment, MockConvertPrice, MockDataCollector, MockDiaOracle,
MockOracleKeyConvertor,
MockConvertMoment, MockConvertPrice, MockDataFeeder, MockDiaOracle, MockOracleKeyConvertor,
},
};
pub use primitives::CurrencyId;
Expand Down Expand Up @@ -307,7 +306,7 @@ impl oracle::Config for Test {
MockConvertPrice,
MockConvertMoment<Moment>,
>;
type DataFeedProvider = MockDataCollector<AccountId, Moment>;
type DataFeeder = MockDataFeeder<AccountId, Moment>;
}

parameter_types! {
Expand Down
5 changes: 2 additions & 3 deletions pallets/vault-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pub use currency::testing_constants::{
use oracle::{
dia::DiaOracleAdapter,
testing_utils::{
MockConvertMoment, MockConvertPrice, MockDataCollector, MockDiaOracle,
MockOracleKeyConvertor,
MockConvertMoment, MockConvertPrice, MockDataFeeder, MockDiaOracle, MockOracleKeyConvertor,
},
};
pub use primitives::CurrencyId;
Expand Down Expand Up @@ -205,7 +204,7 @@ impl oracle::Config for Test {
MockConvertPrice,
MockConvertMoment<Moment>,
>;
type DataFeedProvider = MockDataCollector<AccountId, Moment>;
type DataFeeder = MockDataFeeder<AccountId, Moment>;
}

pub struct CurrencyConvert;
Expand Down
4 changes: 2 additions & 2 deletions testchain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,15 @@ cfg_if::cfg_if! {
}

#[cfg(any(feature = "runtime-benchmarks", feature = "testing-utils"))]
use oracle::testing_utils::MockDataCollector;
use oracle::testing_utils::MockDataFeeder;

impl oracle::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = oracle::SubstrateWeight<Runtime>;
type DataProvider = DataProviderImpl;

#[cfg(any(feature = "runtime-benchmarks", feature = "testing-utils"))]
type DataFeedProvider = MockDataCollector<AccountId, Moment>;
type DataFeeder = MockDataFeeder<AccountId, Moment>;
}

impl issue::Config for Runtime {
Expand Down

0 comments on commit e508da1

Please sign in to comment.