From e508da13f8eeede26b30e7a11069df7f3a70a716 Mon Sep 17 00:00:00 2001 From: Marcel Ebert Date: Thu, 7 Sep 2023 17:29:03 +0200 Subject: [PATCH] Rename type and structs --- Cargo.lock | 1 - pallets/issue/src/mock.rs | 5 ++--- pallets/nomination/src/mock.rs | 5 ++--- pallets/oracle/src/lib.rs | 8 ++++---- pallets/oracle/src/mock.rs | 2 +- pallets/oracle/src/testing_utils/mock_collector.rs | 12 ++++++++---- pallets/oracle/src/testing_utils/mod.rs | 2 +- pallets/redeem/src/mock.rs | 5 ++--- pallets/replace/src/mock.rs | 5 ++--- pallets/vault-registry/src/mock.rs | 5 ++--- testchain/runtime/src/lib.rs | 4 ++-- 11 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 718f55903..cd72db898 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5378,7 +5378,6 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "sp-tracing", "spacewalk-primitives", "spin 0.9.8", "staking", diff --git a/pallets/issue/src/mock.rs b/pallets/issue/src/mock.rs index 7e2434a47..1f16a414a 100644 --- a/pallets/issue/src/mock.rs +++ b/pallets/issue/src/mock.rs @@ -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; @@ -290,7 +289,7 @@ impl oracle::Config for Test { MockConvertPrice, MockConvertMoment, >; - type DataFeedProvider = MockDataCollector; + type DataFeeder = MockDataFeeder; } parameter_types! { diff --git a/pallets/nomination/src/mock.rs b/pallets/nomination/src/mock.rs index 855cf8810..05a868334 100644 --- a/pallets/nomination/src/mock.rs +++ b/pallets/nomination/src/mock.rs @@ -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; @@ -287,7 +286,7 @@ impl oracle::Config for Test { MockConvertPrice, MockConvertMoment, >; - type DataFeedProvider = MockDataCollector; + type DataFeeder = MockDataFeeder; } impl Config for Test { diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index 702555a3a..98e48f83d 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -84,7 +84,7 @@ pub mod pallet { >; #[cfg(feature = "testing-utils")] - type DataFeedProvider: testing_utils::DataFeederExtended< + type DataFeeder: testing_utils::DataFeederExtended< OracleKey, TimestampedValue, Self::AccountId, @@ -245,7 +245,7 @@ impl Pallet { 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); @@ -259,14 +259,14 @@ impl Pallet { #[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 diff --git a/pallets/oracle/src/mock.rs b/pallets/oracle/src/mock.rs index bd8aa3f5e..fb2daf453 100644 --- a/pallets/oracle/src/mock.rs +++ b/pallets/oracle/src/mock.rs @@ -190,7 +190,7 @@ impl Config for Test { MockConvertPrice, MockConvertMoment, >; - type DataFeedProvider = crate::testing_utils::MockDataCollector; + type DataFeeder = crate::testing_utils::MockDataFeeder; } parameter_types! { diff --git a/pallets/oracle/src/testing_utils/mock_collector.rs b/pallets/oracle/src/testing_utils/mock_collector.rs index 5aa3108d8..38a3a3a9b 100644 --- a/pallets/oracle/src/testing_utils/mock_collector.rs +++ b/pallets/oracle/src/testing_utils/mock_collector.rs @@ -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( @@ -83,13 +85,15 @@ impl dia_oracle::DiaOracle for MockDiaOracle { } } -pub struct MockDataCollector( +/// 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( sp_std::marker::PhantomData, sp_std::marker::PhantomData, ); impl DataProvider> - for MockDataCollector + for MockDataFeeder { // We need to implement the DataFeeder trait to the MockDataCollector but this function is never // used @@ -100,7 +104,7 @@ impl DataProvider> DataFeeder, AccountId> - for MockDataCollector + for MockDataFeeder { fn feed_value( _who: AccountId, @@ -124,7 +128,7 @@ impl> impl> DataFeederExtended, AccountId> - for MockDataCollector + for MockDataFeeder { fn clear_all_values() -> DispatchResult { let mut coins = COINS diff --git a/pallets/oracle/src/testing_utils/mod.rs b/pallets/oracle/src/testing_utils/mod.rs index 058e619bb..87daf770c 100644 --- a/pallets/oracle/src/testing_utils/mod.rs +++ b/pallets/oracle/src/testing_utils/mod.rs @@ -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}; diff --git a/pallets/redeem/src/mock.rs b/pallets/redeem/src/mock.rs index 5a8dc36f3..f44096030 100644 --- a/pallets/redeem/src/mock.rs +++ b/pallets/redeem/src/mock.rs @@ -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}; @@ -307,7 +306,7 @@ impl oracle::Config for Test { MockConvertPrice, MockConvertMoment, >; - type DataFeedProvider = MockDataCollector; + type DataFeeder = MockDataFeeder; } parameter_types! { diff --git a/pallets/replace/src/mock.rs b/pallets/replace/src/mock.rs index 43f86a159..d84cfb21a 100644 --- a/pallets/replace/src/mock.rs +++ b/pallets/replace/src/mock.rs @@ -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; @@ -307,7 +306,7 @@ impl oracle::Config for Test { MockConvertPrice, MockConvertMoment, >; - type DataFeedProvider = MockDataCollector; + type DataFeeder = MockDataFeeder; } parameter_types! { diff --git a/pallets/vault-registry/src/mock.rs b/pallets/vault-registry/src/mock.rs index cdbdb3f34..e1ae03c73 100644 --- a/pallets/vault-registry/src/mock.rs +++ b/pallets/vault-registry/src/mock.rs @@ -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; @@ -205,7 +204,7 @@ impl oracle::Config for Test { MockConvertPrice, MockConvertMoment, >; - type DataFeedProvider = MockDataCollector; + type DataFeeder = MockDataFeeder; } pub struct CurrencyConvert; diff --git a/testchain/runtime/src/lib.rs b/testchain/runtime/src/lib.rs index 0155159ee..37ac4ccd1 100644 --- a/testchain/runtime/src/lib.rs +++ b/testchain/runtime/src/lib.rs @@ -514,7 +514,7 @@ 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; @@ -522,7 +522,7 @@ impl oracle::Config for Runtime { type DataProvider = DataProviderImpl; #[cfg(any(feature = "runtime-benchmarks", feature = "testing-utils"))] - type DataFeedProvider = MockDataCollector; + type DataFeeder = MockDataFeeder; } impl issue::Config for Runtime {