Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitebox v2 deprecated #1744

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use multiversx_sc_scenario::imports::*;
use std::iter::zip;

use rewards_distribution::{
rewards_distribution_proxy, ContractObj, RewardsDistribution, DIVISION_SAFETY_CONSTANT,
rewards_distribution_proxy, RewardsDistribution, DIVISION_SAFETY_CONSTANT,
};

const ALICE_ADDRESS: TestAddress = TestAddress::new("alice");
Expand All @@ -31,7 +31,6 @@ fn world() -> ScenarioWorld {

struct RewardsDistributionTestState {
world: ScenarioWorld,
rewards_distribution_whitebox: WhiteboxContract<ContractObj<DebugApi>>,
}

impl RewardsDistributionTestState {
Expand All @@ -40,15 +39,7 @@ impl RewardsDistributionTestState {

world.account(OWNER_ADDRESS).nonce(1);

let rewards_distribution_whitebox = WhiteboxContract::new(
REWARDS_DISTRIBUTION_ADDRESS,
rewards_distribution::contract_obj,
);

Self {
world,
rewards_distribution_whitebox,
}
Self { world }
}

fn deploy_seed_nft_minter_contract(&mut self) -> &mut Self {
Expand Down Expand Up @@ -110,10 +101,12 @@ fn test_compute_brackets() {
.owner(OWNER_ADDRESS)
.code(REWARDS_DISTRIBUTION_PATH);

state.world.whitebox_call(
&state.rewards_distribution_whitebox,
ScCallStep::new().from(OWNER_ADDRESS),
|sc| {
state
.world
.tx()
.from(OWNER_ADDRESS)
.to(REWARDS_DISTRIBUTION_ADDRESS)
.whitebox(rewards_distribution::contract_obj, |sc| {
let brackets = utils::to_brackets(&[
(10, 2_000),
(90, 6_000),
Expand All @@ -140,8 +133,7 @@ fn test_compute_brackets() {
assert_eq!(computed.end_index, expected_end_index);
assert_eq!(computed.nft_reward_percent, expected_reward_percent);
}
},
);
});
}

#[test]
Expand Down
Loading
Loading