Skip to content

Commit

Permalink
Serialize oracle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ebma committed Aug 31, 2023
1 parent a6b2ebc commit 47e4896
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions pallets/oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion pallets/oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -257,6 +256,7 @@ impl<T: Config> Pallet<T> {
// public only for testing purposes
#[cfg(feature = "testing-utils")]
pub fn _clear_values() -> DispatchResult {
use crate::oracle_mock::DataFeederExtended;
T::DataFeedProvider::clear_all_values()
}

Expand Down
1 change: 1 addition & 0 deletions pallets/oracle/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions pallets/oracle/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -9,6 +10,7 @@ fn mine_block() {
}

#[test]
#[serial]
fn feed_values_succeeds() {
run_test(|| {
let key = OracleKey::ExchangeRate(CurrencyId::AlphaNum4(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -155,6 +162,7 @@ fn getting_exchange_rate_fails_with_missing_exchange_rate() {
}

#[test]
#[serial]
fn currency_to_usd() {
run_test(|| {
Oracle::get_price
Expand All @@ -168,6 +176,7 @@ fn currency_to_usd() {
}

#[test]
#[serial]
fn usd_to_currency() {
run_test(|| {
Oracle::get_price
Expand All @@ -181,6 +190,7 @@ fn usd_to_currency() {
}

#[test]
#[serial]
fn test_is_invalidated() {
run_test(|| {
let now = 1585776145;
Expand All @@ -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;
Expand Down

0 comments on commit 47e4896

Please sign in to comment.