diff --git a/Cargo.lock b/Cargo.lock index 0e31451f5..fed8172d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5373,6 +5373,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "security", + "serial_test", "sp-arithmetic", "sp-core", "sp-io", diff --git a/pallets/oracle/Cargo.toml b/pallets/oracle/Cargo.toml index 74ce13a2e..ad89df7b6 100644 --- a/pallets/oracle/Cargo.toml +++ b/pallets/oracle/Cargo.toml @@ -46,6 +46,7 @@ orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-modul orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.40", default-features = false } orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.40", default-features = false } +serial_test = "0.9.0" [features] default = ["std"] diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index cf426e48f..4a1533cb2 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -37,7 +37,6 @@ mod default_weights; #[cfg_attr(test, cfg(feature = "testing-utils"))] mod tests; -use crate::oracle_mock::DataFeederExtended; #[cfg(feature = "testing-utils")] pub use dia_oracle::{CoinInfo, DiaOracle, PriceInfo}; #[cfg(feature = "testing-utils")] @@ -257,6 +256,7 @@ impl Pallet { // public only for testing purposes #[cfg(feature = "testing-utils")] pub fn _clear_values() -> DispatchResult { + use crate::oracle_mock::DataFeederExtended; T::DataFeedProvider::clear_all_values() } diff --git a/pallets/oracle/src/mock.rs b/pallets/oracle/src/mock.rs index f8cc0ef25..ae4b15fb4 100644 --- a/pallets/oracle/src/mock.rs +++ b/pallets/oracle/src/mock.rs @@ -243,6 +243,7 @@ where T: FnOnce(), { clear_mocks(); + let _ = Oracle::_clear_values(); ExtBuilder::build().execute_with(|| { Security::set_active_block_number(1); System::set_block_number(1); diff --git a/pallets/oracle/src/tests.rs b/pallets/oracle/src/tests.rs index 9f094fa26..2bd14d83e 100644 --- a/pallets/oracle/src/tests.rs +++ b/pallets/oracle/src/tests.rs @@ -1,6 +1,7 @@ use crate::{mock::*, CurrencyId, OracleKey}; use frame_support::{assert_err, assert_ok}; use mocktopus::mocking::*; +use serial_test::serial; use sp_arithmetic::FixedU128; use sp_runtime::FixedPointNumber; @@ -9,6 +10,7 @@ fn mine_block() { } #[test] +#[serial] fn feed_values_succeeds() { run_test(|| { let key = OracleKey::ExchangeRate(CurrencyId::AlphaNum4( @@ -63,6 +65,7 @@ mod oracle_offline_detection { } #[test] + #[serial] fn basic_oracle_offline_logic() { run_test(|| { Oracle::get_max_delay.mock_safe(move || MockResult::Return(10)); @@ -106,6 +109,7 @@ mod oracle_offline_detection { } #[test] + #[serial] fn oracle_offline_logic_with_multiple_oracles() { run_test(|| { Oracle::get_max_delay.mock_safe(move || MockResult::Return(10)); @@ -145,8 +149,11 @@ mod oracle_offline_detection { } #[test] +#[serial] fn getting_exchange_rate_fails_with_missing_exchange_rate() { run_test(|| { + let _ = Oracle::_clear_values(); + let key = OracleKey::ExchangeRate(CurrencyId::XCM(0)); assert_err!(Oracle::get_price(key), TestError::MissingExchangeRate); assert_err!(Oracle::currency_to_usd(0, CurrencyId::XCM(0)), TestError::MissingExchangeRate); @@ -155,6 +162,7 @@ fn getting_exchange_rate_fails_with_missing_exchange_rate() { } #[test] +#[serial] fn currency_to_usd() { run_test(|| { Oracle::get_price @@ -168,6 +176,7 @@ fn currency_to_usd() { } #[test] +#[serial] fn usd_to_currency() { run_test(|| { Oracle::get_price @@ -181,6 +190,7 @@ fn usd_to_currency() { } #[test] +#[serial] fn test_is_invalidated() { run_test(|| { let now = 1585776145; @@ -203,6 +213,7 @@ fn test_is_invalidated() { } #[test] +#[serial] fn begin_block_set_oracle_offline_succeeds() { run_test(|| unsafe { let mut oracle_reported = false;