Skip to content

Commit

Permalink
merge rc/v0.53
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Sep 2, 2024
2 parents bcc1b20 + c1a459a commit 001038a
Show file tree
Hide file tree
Showing 81 changed files with 4,296 additions and 2,893 deletions.
634 changes: 364 additions & 270 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_price_aggregator_sc::{
price_aggregator_data::{OracleStatus, TimestampedPrice, TokenPair},
ContractObj, PriceAggregator, MAX_ROUND_DURATION_SECONDS,
PriceAggregator, MAX_ROUND_DURATION_SECONDS,
};

use multiversx_sc_scenario::imports::*;
Expand Down Expand Up @@ -35,7 +35,6 @@ fn world() -> ScenarioWorld {
struct PriceAggregatorTestState {
world: ScenarioWorld,
oracles: Vec<AddressValue>,
price_aggregator_whitebox: WhiteboxContract<ContractObj<DebugApi>>,
}

impl PriceAggregatorTestState {
Expand All @@ -57,16 +56,7 @@ impl PriceAggregatorTestState {
oracles.push(address_value);
}

let price_aggregator_whitebox = WhiteboxContract::new(
PRICE_AGGREGATOR_ADDRESS,
multiversx_price_aggregator_sc::contract_obj,
);

Self {
world,
oracles,
price_aggregator_whitebox,
}
Self { world, oracles }
}

fn deploy(&mut self) -> &mut Self {
Expand Down Expand Up @@ -203,9 +193,10 @@ fn test_price_aggregator_submit() {
state.submit(&state.oracles[0].clone(), 95, 100);

let current_timestamp = 100;
state
.world
.whitebox_query(&state.price_aggregator_whitebox, |sc| {

state.world.query().to(PRICE_AGGREGATOR_ADDRESS).whitebox(
multiversx_price_aggregator_sc::contract_obj,
|sc| {
let token_pair = TokenPair {
from: managed_buffer!(EGLD_TICKER),
to: managed_buffer!(USD_TICKER),
Expand Down Expand Up @@ -237,14 +228,15 @@ fn test_price_aggregator_submit() {
accepted_submissions: 1
}
);
});
},
);

// first oracle submit again - submission not accepted
state.submit(&state.oracles[0].clone(), 95, 100);

state
.world
.whitebox_query(&state.price_aggregator_whitebox, |sc| {
state.world.query().to(PRICE_AGGREGATOR_ADDRESS).whitebox(
multiversx_price_aggregator_sc::contract_obj,
|sc| {
assert_eq!(
sc.oracle_status()
.get(&managed_address!(&state.oracles[0].to_address()))
Expand All @@ -254,7 +246,8 @@ fn test_price_aggregator_submit() {
accepted_submissions: 1
}
);
});
},
);
}

#[test]
Expand Down Expand Up @@ -283,9 +276,9 @@ fn test_price_aggregator_submit_round_ok() {
// submit third
state.submit(&state.oracles[2].clone(), 105, 12_000);

state
.world
.whitebox_query(&state.price_aggregator_whitebox, |sc| {
state.world.query().to(PRICE_AGGREGATOR_ADDRESS).whitebox(
multiversx_price_aggregator_sc::contract_obj,
|sc| {
let result =
sc.latest_price_feed(managed_buffer!(EGLD_TICKER), managed_buffer!(USD_TICKER));

Expand All @@ -312,7 +305,8 @@ fn test_price_aggregator_submit_round_ok() {
decimals
}
);
});
},
);
}

#[test]
Expand All @@ -338,9 +332,9 @@ fn test_price_aggregator_discarded_round() {
// submit second - this will discard the previous submission
state.submit(&state.oracles[1].clone(), current_timestamp - 1, 11_000);

state
.world
.whitebox_query(&state.price_aggregator_whitebox, |sc| {
state.world.query().to(PRICE_AGGREGATOR_ADDRESS).whitebox(
multiversx_price_aggregator_sc::contract_obj,
|sc| {
let token_pair = TokenPair {
from: managed_buffer!(EGLD_TICKER),
to: managed_buffer!(USD_TICKER),
Expand All @@ -353,7 +347,8 @@ fn test_price_aggregator_discarded_round() {
.unwrap(),
managed_biguint!(11_000)
);
});
},
);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_price_aggregator_sc::{
price_aggregator_data::{OracleStatus, TokenPair},
ContractObj, PriceAggregator,
PriceAggregator,
};

use multiversx_sc_scenario::imports::*;
Expand Down Expand Up @@ -34,7 +34,6 @@ fn world() -> ScenarioWorld {
struct PriceAggregatorTestState {
world: ScenarioWorld,
oracles: Vec<AddressValue>,
price_aggregator_whitebox: WhiteboxContract<ContractObj<DebugApi>>,
}

impl PriceAggregatorTestState {
Expand All @@ -60,16 +59,7 @@ impl PriceAggregatorTestState {
oracles.push(address_value);
}

let price_aggregator_whitebox = WhiteboxContract::new(
PRICE_AGGREGATOR_ADDRESS,
multiversx_price_aggregator_sc::contract_obj,
);

Self {
world,
oracles,
price_aggregator_whitebox,
}
Self { world, oracles }
}

fn deploy(&mut self) -> &mut Self {
Expand Down Expand Up @@ -170,9 +160,9 @@ fn test_price_aggregator_submit() {
}

let current_timestamp = 100;
state
.world
.whitebox_query(&state.price_aggregator_whitebox, |sc| {
state.world.query().to(PRICE_AGGREGATOR_ADDRESS).whitebox(
multiversx_price_aggregator_sc::contract_obj,
|sc| {
let blockchain_timestamp = sc.blockchain().get_block_timestamp();

let token_pair = TokenPair {
Expand Down Expand Up @@ -207,7 +197,8 @@ fn test_price_aggregator_submit() {
}
);
}
});
},
);

// submit last that resets the round
state.submit(
Expand Down
Loading

0 comments on commit 001038a

Please sign in to comment.