diff --git a/src/xrc/src/api/test.rs b/src/xrc/src/api/test.rs index 74ee8553..eb561b90 100644 --- a/src/xrc/src/api/test.rs +++ b/src/xrc/src/api/test.rs @@ -1,9 +1,9 @@ -use std::{collections::HashMap, sync::RwLock}; +use std::{collections::BTreeMap, sync::RwLock}; use async_trait::async_trait; use futures::FutureExt; use ic_xrc_types::{Asset, AssetClass, ExchangeRateError, GetExchangeRateRequest}; -use maplit::hashmap; +use maplit::btreemap; use crate::{ environment::test::TestEnvironment, @@ -62,11 +62,12 @@ fn test_cxdr_rate() -> QueriedExchangeRate { struct TestCallExchangesImpl { /// Contains the responses when [CallExchanges::get_cryptocurrency_usdt_rate] is called. get_cryptocurrency_usdt_rate_responses: - HashMap>, + BTreeMap>, /// The received [CallExchanges::get_cryptocurrency_usdt_rate] calls from the test. get_cryptocurrency_usdt_rate_calls: RwLock>, /// Contains the responses when [CallExchanges::get_stablecoin_rates] is called. - get_stablecoin_rates_responses: HashMap>, + get_stablecoin_rates_responses: + BTreeMap>, /// The received [CallExchanges::get_cryptocurrency_usdt_rate] calls from the test. get_stablecoin_rates_calls: RwLock, u64)>>, } @@ -91,7 +92,7 @@ impl TestCallExchangesImplBuilder { /// Sets the responses for when [CallExchanges::get_cryptocurrency_usdt_rate] is called. fn with_get_cryptocurrency_usdt_rate_responses( mut self, - responses: HashMap>, + responses: BTreeMap>, ) -> Self { self.r#impl.get_cryptocurrency_usdt_rate_responses = responses; self @@ -100,7 +101,7 @@ impl TestCallExchangesImplBuilder { /// Sets the responses for when [CallExchanges::get_stablecoin_rates] is called. fn with_get_stablecoin_rates_responses( mut self, - responses: HashMap>, + responses: BTreeMap>, ) -> Self { self.r#impl.get_stablecoin_rates_responses = responses; self @@ -213,7 +214,7 @@ fn stablecoin_mock(symbol: &str, rates: &[u64]) -> QueriedExchangeRate { #[test] fn get_exchange_rate_fails_when_not_enough_cycles() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(QueriedExchangeRate::default()), "ICP".to_string() => Ok(QueriedExchangeRate::default()) }) @@ -237,7 +238,7 @@ fn get_exchange_rate_fails_when_not_enough_cycles() { #[should_panic(expected = "Failed to accept cycles")] fn get_exchange_rate_fails_when_unable_to_accept_cycles() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(QueriedExchangeRate::default()), "ICP".to_string() => Ok(QueriedExchangeRate::default()) }) @@ -259,7 +260,7 @@ fn get_exchange_rate_fails_when_unable_to_accept_cycles() { #[test] fn get_exchange_rate_will_not_charge_cycles_if_caller_is_privileged() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -293,7 +294,7 @@ fn get_exchange_rate_will_not_charge_cycles_if_caller_is_privileged() { #[test] fn get_exchange_rate_will_charge_cycles() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -326,7 +327,7 @@ fn get_exchange_rate_will_charge_cycles() { #[test] fn get_exchange_rate_will_charge_the_base_cost_worth_of_cycles() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -367,7 +368,7 @@ fn get_exchange_rate_will_charge_the_base_cost_worth_of_cycles() { fn get_exchange_rate_will_charge_the_base_cost_plus_outbound_cycles_worth_of_cycles_when_cache_contains_one_entry( ) { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -405,7 +406,7 @@ fn get_exchange_rate_will_charge_the_base_cost_plus_outbound_cycles_worth_of_cyc #[test] fn get_exchange_rate_will_charge_rate_limit_fee() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -432,10 +433,10 @@ fn get_exchange_rate_will_charge_rate_limit_fee() { #[test] fn get_exchange_rate_for_crypto_usd_pair() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) - .with_get_stablecoin_rates_responses(hashmap! { + .with_get_stablecoin_rates_responses(btreemap! { DAI.to_string() => Ok(stablecoin_mock(DAI, &[RATE_UNIT])), USDC.to_string() => Ok(stablecoin_mock(USDC, &[RATE_UNIT])), }) @@ -481,10 +482,10 @@ fn get_exchange_rate_for_crypto_usd_pair() { #[test] fn get_exchange_rate_for_usd_crypto_pair() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) - .with_get_stablecoin_rates_responses(hashmap! { + .with_get_stablecoin_rates_responses(btreemap! { DAI.to_string() => Ok(stablecoin_mock(DAI, &[RATE_UNIT])), USDC.to_string() => Ok(stablecoin_mock(USDC, &[RATE_UNIT])), }) @@ -533,7 +534,7 @@ fn get_exchange_rate_for_crypto_non_usd_pair() { with_forex_rate_store_mut(|store| { store.put( 0, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -551,10 +552,10 @@ fn get_exchange_rate_for_crypto_non_usd_pair() { }); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) - .with_get_stablecoin_rates_responses(hashmap! { + .with_get_stablecoin_rates_responses(btreemap! { DAI.to_string() => Ok(stablecoin_mock(DAI, &[RATE_UNIT])), USDC.to_string() => Ok(stablecoin_mock(USDC, &[RATE_UNIT])), }) @@ -602,7 +603,7 @@ fn get_exchange_rate_for_non_usd_crypto_pair() { with_forex_rate_store_mut(|store| { store.put( 0, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -620,10 +621,10 @@ fn get_exchange_rate_for_non_usd_crypto_pair() { }); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) - .with_get_stablecoin_rates_responses(hashmap! { + .with_get_stablecoin_rates_responses(btreemap! { DAI.to_string() => Ok(stablecoin_mock(DAI, &[RATE_UNIT])), USDC.to_string() => Ok(stablecoin_mock(USDC, &[RATE_UNIT])), }) @@ -671,7 +672,7 @@ fn get_exchange_rate_for_non_usd_crypto_pair_crypto_asset_not_found() { with_forex_rate_store_mut(|store| { store.put( 0, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -689,7 +690,7 @@ fn get_exchange_rate_for_non_usd_crypto_pair_crypto_asset_not_found() { }); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_stablecoin_rates_responses(hashmap! { + .with_get_stablecoin_rates_responses(btreemap! { DAI.to_string() => Ok(stablecoin_mock(DAI, &[RATE_UNIT])), USDC.to_string() => Ok(stablecoin_mock(USDC, &[RATE_UNIT])), }) @@ -751,7 +752,7 @@ fn get_exchange_rate_for_fiat_eur_usd_pair() { with_forex_rate_store_mut(|store| { store.put( 0, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -795,7 +796,7 @@ fn get_exchange_rate_for_fiat_with_unknown_symbol() { with_forex_rate_store_mut(|store| { store.put( 0, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -842,7 +843,7 @@ fn get_exchange_rate_for_fiat_with_unknown_timestamp() { with_forex_rate_store_mut(|store| { store.put( 86_400, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -880,7 +881,7 @@ fn get_exchange_rate_for_fiat_with_unknown_timestamp() { fn get_exchange_rate_will_charge_minimum_fee_if_request_is_pending() { set_inflight_tracking(vec!["BTC".to_string(), "ICP".to_string()], 0); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -908,7 +909,7 @@ fn get_exchange_rate_will_retrieve_rates_if_inflight_tracking_does_not_contain_s ) { set_inflight_tracking(vec!["AVAX".to_string(), "ICP".to_string()], 100); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -936,7 +937,7 @@ fn get_exchange_rate_will_retrieve_rates_if_inflight_tracking_contains_any_symbo { set_inflight_tracking(vec!["AVAX".to_string(), "ICP".to_string()], 0); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -962,7 +963,7 @@ fn get_exchange_rate_will_retrieve_rates_if_inflight_tracking_contains_any_symbo #[test] fn get_exchange_rate_can_retrieve_icp_usdt() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) .build(); @@ -995,7 +996,7 @@ fn get_exchange_rate_can_retrieve_icp_usdt() { #[test] fn get_exchange_rate_can_retrieve_usdt_icp() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) .build(); @@ -1031,7 +1032,7 @@ mod privileged_callers_can_bypass_pending { fn get_exchange_rate_will_allow_a_privileged_caller_to_bypass_pending_check_crypto_pair() { set_inflight_tracking(vec!["BTC".to_string(), "ICP".to_string()], 0); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -1058,10 +1059,10 @@ mod privileged_callers_can_bypass_pending { fn get_exchange_rate_will_allow_a_privileged_caller_to_bypass_pending_check_crypto_fiat_pair() { set_inflight_tracking(vec!["BTC".to_string(), "ICP".to_string()], 0); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) - .with_get_stablecoin_rates_responses(hashmap! { + .with_get_stablecoin_rates_responses(btreemap! { DAI.to_string() => Ok(stablecoin_mock(DAI, &[RATE_UNIT])), USDC.to_string() => Ok(stablecoin_mock(USDC, &[RATE_UNIT])), }) @@ -1098,7 +1099,7 @@ mod uses_previous_minute_when_timestamp_is_null_if_request_would_be_pending { }); set_inflight_tracking(vec!["BTC".to_string(), "ICP".to_string()], 60); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -1128,7 +1129,7 @@ mod uses_previous_minute_when_timestamp_is_null_if_request_would_be_pending { fn crypto_pair_when_the_cache_does_not_contain_the_rates() { set_inflight_tracking(vec!["BTC".to_string(), "ICP".to_string()], 60); let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "BTC".to_string() => Ok(btc_queried_exchange_rate_mock()), "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) @@ -1244,10 +1245,10 @@ mod uses_previous_minute_when_timestamp_is_null_if_request_would_be_pending { #[test] fn get_exchange_rate_with_unsanitized_request_to_ensure_requests_are_sanitized() { let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) - .with_get_stablecoin_rates_responses(hashmap! { + .with_get_stablecoin_rates_responses(btreemap! { DAI.to_string() => Ok(stablecoin_mock(DAI, &[RATE_UNIT])), USDC.to_string() => Ok(stablecoin_mock(USDC, &[RATE_UNIT])), }) @@ -1300,7 +1301,7 @@ fn cached_rate_with_few_collected_rates_is_ignored_for_privileged_canister() { // The exchanges return an ICP/USDT rate of 4*RATE_UNIT. let call_exchanges_impl = TestCallExchangesImpl::builder() - .with_get_cryptocurrency_usdt_rate_responses(hashmap! { + .with_get_cryptocurrency_usdt_rate_responses(btreemap! { "ICP".to_string() => Ok(icp_queried_exchange_rate_mock()) }) .build(); diff --git a/src/xrc/src/forex.rs b/src/xrc/src/forex.rs index f955c6c2..8552d176 100644 --- a/src/xrc/src/forex.rs +++ b/src/xrc/src/forex.rs @@ -14,7 +14,7 @@ use candid::{ }; use ic_xrc_types::{Asset, AssetClass, ExchangeRateError}; use std::cmp::min; -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use std::collections::{HashSet, VecDeque}; use std::mem::size_of_val; @@ -39,10 +39,10 @@ pub(crate) const COMPUTED_XDR_SYMBOL: &str = "CXDR"; const MAX_COLLECTION_DAYS: usize = 2; /// A map of multiple forex rates with one source per forex. The key is the forex symbol and the value is the corresponding rate. -pub type ForexRateMap = HashMap; +pub type ForexRateMap = BTreeMap; /// A map of multiple forex rates with possibly multiple sources per forex. The key is the forex symbol and the value is the corresponding rate and the number of sources used to compute it. -pub(crate) type ForexMultiRateMap = HashMap; +pub(crate) type ForexMultiRateMap = BTreeMap; impl AllocatedBytes for ForexMultiRateMap { fn allocated_bytes(&self) -> usize { @@ -772,7 +772,7 @@ trait IsForex { #[cfg(test)] mod test { use ic_xrc_types::{ExchangeRate, ExchangeRateMetadata}; - use maplit::hashmap; + use maplit::btreemap; use crate::DECIMALS; @@ -791,19 +791,19 @@ mod test { }; // Insert real values with the correct timestamp. - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => 1_000_000_000, "SGD".to_string() => 100_000_000, "CHF".to_string() => 700_000_000, }; collector.update("src1".to_string(), rates); - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => 1_100_000_000, "SGD".to_string() => 1_000_000_000, "CHF".to_string() => 1_000_000_000, }; collector.update("src2".to_string(), rates); - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => 800_000_000, "SGD".to_string() => 1_300_000_000, "CHF".to_string() => 2_100_000_000, @@ -826,19 +826,19 @@ mod test { // Start by executing the same logic as for the [OneDayRatesCollector] to verify that the calls are relayed correctly let first_day_timestamp = (123456789 / ONE_DAY_SECONDS) * ONE_DAY_SECONDS; - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => 1_000_000_000, "SGD".to_string() => 100_000_000, "CHF".to_string() => 700_000_000, }; collector.update("src1".to_string(), first_day_timestamp, rates); - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => 1_100_000_000, "SGD".to_string() => 1_000_000_000, "CHF".to_string() => 1_000_000_000, }; collector.update("src2".to_string(), first_day_timestamp, rates); - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => 800_000_000, "SGD".to_string() => 1_300_000_000, "CHF".to_string() => 2_100_000_000, @@ -856,7 +856,7 @@ mod test { // Add a new day let second_day_timestamp = first_day_timestamp + ONE_DAY_SECONDS; let test_rate: u64 = 700_000_000; - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => test_rate, "SGD".to_string() => test_rate, "CHF".to_string() => test_rate, @@ -873,7 +873,7 @@ mod test { // Add a third day and expect the first one to not be available let third_day_timestamp = second_day_timestamp + ONE_DAY_SECONDS; let test_rate: u64 = 800_000_000; - let rates = hashmap! { + let rates = btreemap! { "EUR".to_string() => test_rate, "SGD".to_string() => test_rate, "CHF".to_string() => test_rate, @@ -902,7 +902,7 @@ mod test { collector.update( "src1".to_string(), timestamp, - hashmap! { + btreemap! { "EUR".to_string() => 1_000_000_000, "SGD".to_string() => 100_000_000, "CHF".to_string() => 700_000_000, @@ -912,7 +912,7 @@ mod test { collector.update( "src1".to_string(), timestamp, - hashmap! { + btreemap! { "EUR".to_string() => 1_100_000_000, "SGD".to_string() => 1_000_000_000, "CHF".to_string() => 1_000_000_000, @@ -922,7 +922,7 @@ mod test { collector.update( "src3".to_string(), timestamp, - hashmap! { + btreemap! { "EUR".to_string() => 800_000_000, "SGD".to_string() => 1_300_000_000, "CHF".to_string() => 2_100_000_000, @@ -952,7 +952,7 @@ mod test { } rates_store.put( timestamp, - hashmap! { + btreemap! { COMPUTED_XDR_SYMBOL.to_string() => QueriedExchangeRate::new( Asset { @@ -988,7 +988,7 @@ mod test { add_enough_cxdr_rates_to_store(&mut store, 1234); store.put( 1234, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -1042,7 +1042,7 @@ mod test { ); store.put( 1234, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -1124,7 +1124,7 @@ mod test { add_enough_cxdr_rates_to_store(&mut store, 0); store.put( 0, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -1141,7 +1141,7 @@ mod test { add_enough_cxdr_rates_to_store(&mut store, ONE_DAY_SECONDS); store.put( ONE_DAY_SECONDS, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -1158,7 +1158,7 @@ mod test { add_enough_cxdr_rates_to_store(&mut store, ONE_DAY_SECONDS * 2); store.put( ONE_DAY_SECONDS * 2, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), @@ -1417,7 +1417,7 @@ mod test { let mut store = ForexRateStore::new(); store.put( 0, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), usd_asset(), @@ -1430,7 +1430,7 @@ mod test { }, ); - assert_eq!(store.allocated_bytes(), 273); + assert_eq!(store.allocated_bytes(), 249); } /// This function tests the "go back" mechanism where, when there are no rates for a requested timestamp, we may go back up to [MAX_DAYS_TO_GO_BACK] days. @@ -1444,7 +1444,7 @@ mod test { add_enough_cxdr_rates_to_store(&mut store, timestamp); store.put( timestamp, - hashmap! { + btreemap! { "EUR".to_string() => QueriedExchangeRate::new( eur_asset(), usd_asset(), diff --git a/src/xrc/src/forex/australia.rs b/src/xrc/src/forex/australia.rs index 193fda12..b5f51fe3 100644 --- a/src/xrc/src/forex/australia.rs +++ b/src/xrc/src/forex/australia.rs @@ -108,7 +108,7 @@ impl IsForex for ReserveBankOfAustralia { #[cfg(test)] mod test { - use maplit::hashmap; + use maplit::btreemap; use super::*; @@ -151,7 +151,7 @@ mod test { .expect("should be able to extract rates"); assert_eq!( extracted_rates, - hashmap! { + btreemap! { "INR".to_string() => 82_057_810_393, "IDR".to_string() => 14_876_441_515_650, "XDR".to_string() => 741_949_977, diff --git a/src/xrc/src/lib.rs b/src/xrc/src/lib.rs index 1439f282..b133556d 100644 --- a/src/xrc/src/lib.rs +++ b/src/xrc/src/lib.rs @@ -879,6 +879,7 @@ pub fn transform_forex_http_response(args: TransformArgs) -> HttpResponse { }; let transform_result = forex.transform_http_response_body(&sanitized.body, &context.payload); + ic_cdk::println!("{} {} {:?}", LOG_PREFIX, forex, transform_result); sanitized.body = match transform_result { Ok(body) => body, diff --git a/src/xrc/src/periodic.rs b/src/xrc/src/periodic.rs index 8266c641..33fc94b1 100644 --- a/src/xrc/src/periodic.rs +++ b/src/xrc/src/periodic.rs @@ -240,7 +240,7 @@ fn get_next_run_timestamp(timestamp: u64) -> u64 { mod test { use futures::FutureExt; - use maplit::hashmap; + use maplit::btreemap; use crate::forex::COMPUTED_XDR_SYMBOL; use crate::with_forex_rate_store; @@ -287,7 +287,7 @@ mod test { fn forex_store_can_be_updated_successfully() { let timestamp = 1666371931; let start_of_day = start_of_day_timestamp(timestamp); - let map = hashmap! { + let map = btreemap! { "EUR".to_string() => 10_000, "SGD".to_string() => 1_000, "CHF".to_string() => 7_000, @@ -417,7 +417,7 @@ mod test { collector.update( forex.to_string(), timestamp, - hashmap! { + btreemap! { "EUR".to_string() => 100 }, )