Skip to content

Commit

Permalink
fix: expose testutils Asset object for MockClient usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mootz12 committed Oct 23, 2023
1 parent a3037c2 commit 15e4e08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 1 addition & 4 deletions mock-sep-40/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use sep_40_oracle::Asset;
use soroban_sdk::{
panic_with_error, unwrap::UnwrapOptimized, Address, Env, Symbol, Vec,
};
use soroban_sdk::{panic_with_error, unwrap::UnwrapOptimized, Address, Env, Symbol, Vec};

use crate::error::PriceOracleError;

pub(crate) const LEDGER_THRESHOLD: u32 = 120960; // 7 days at 5s a block
pub(crate) const LEDGER_BUMP: u32 = 138240; // 8 days at 5s a block


pub fn bump_instance(env: &Env) {
env.storage().instance().bump(LEDGER_THRESHOLD, LEDGER_BUMP);
}
Expand Down
12 changes: 7 additions & 5 deletions mock-sep-40/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#![cfg(test)]

use sep_40_oracle::Asset;
use soroban_sdk::{testutils::{Address as _, Ledger, LedgerInfo}, Address, Env, Vec, vec, Symbol};
use soroban_sdk::{
testutils::{Address as _, Ledger, LedgerInfo},
vec, Address, Env, Symbol, Vec,
};

use super::*;

Expand All @@ -20,7 +23,6 @@ fn setup_price_feed_oracle<'a>(
(oracle_id, oracle_client)
}


#[test]
fn test_stable_price_feed() {
let env = Env::default();
Expand Down Expand Up @@ -55,7 +57,7 @@ fn test_stable_price_feed() {
let prices: Vec<i128> = vec![&env, 94_234_1234567, 1_1021304];
oracle_client.set_price_stable(&prices);

// verify price data can be fetched
// verify price data can be fetched
let price_1 = oracle_client.lastprice(&asset_1).unwrap();
assert_eq!(price_1.price, prices.get_unchecked(0));
assert_eq!(price_1.timestamp, start_time);
Expand Down Expand Up @@ -120,7 +122,7 @@ fn test_price_feed() {
let prices_1: Vec<i128> = vec![&env, 94_234_1234567, 1_1021304];
oracle_client.set_price(&prices_1, &start_time);

// verify price data can be fetched
// verify price data can be fetched
let result_1 = oracle_client.lastprice(&asset_1).unwrap();
assert_eq!(result_1.price, prices_1.get_unchecked(0));
assert_eq!(result_1.timestamp, start_time);
Expand Down Expand Up @@ -190,4 +192,4 @@ fn test_price_feed() {
let result_2_1 = result_2_vec.get_unchecked(1);
assert_eq!(result_2_1.price, prices_1.get_unchecked(1));
assert_eq!(result_2_1.timestamp, start_time);
}
}
5 changes: 4 additions & 1 deletion sep-40/src/testutils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ mod wasm {
soroban_sdk::contractimport!(file = "./src/testutils/mock_sep_40_oracle.wasm");
}

pub use wasm::{Client as MockPriceOracleClient, Contract as MockPriceOracle, PriceOracleError, WASM as MockPriceOracleWASM};
pub use wasm::{
Asset, Client as MockPriceOracleClient, Contract as MockPriceOracle, PriceOracleError,
WASM as MockPriceOracleWASM,
};

0 comments on commit 15e4e08

Please sign in to comment.