Skip to content

Commit

Permalink
managed decimal test fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed May 30, 2024
1 parent dcdf16a commit 9100774
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ where
.argument(&bi)
.original_result()
}

pub fn returns_egld_decimal(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ManagedDecimal<Env::Api, ConstDecimals<18>>> {
self.wrapped_tx
.raw_call("returns_egld_decimal")
.original_result()
}
}

#[type_abi]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,54 @@
use multiversx_sc::types::{
BigUint, ConstDecimals, ContractCallWithEgld, ManagedAddress, ManagedDecimal,
};
use multiversx_sc_scenario::{api::StaticApi, scenario_model::*, *};
use imports::{MxscPath, ReturnsResult, TestAddress, TestSCAddress};
use multiversx_sc::types::{BigUint, ConstDecimals, ManagedDecimal};
use multiversx_sc_scenario::{api::StaticApi, imports, ScenarioTxRun, ScenarioWorld};

const BASIC_FEATURES_PATH_EXPR: &str = "file:../output/basic-features.wasm";
const OWNER_ADDRESS_EXPR: &str = "address:owner";
const BASIC_FEATURES_ADDRESS_EXPR: &str = "sc:basic-features";

type BasicFeatures = ContractInfo<basic_features::Proxy<StaticApi>>;
const OWNER_ADDRESS: TestAddress = TestAddress::new("owner");
const BASIC_FEATURES_ADDRESS: TestSCAddress = TestSCAddress::new("basic-features");
const BASIC_FEATURES_PATH: MxscPath = MxscPath::new("output/basic-features.mxsc.json");

struct BasicFeaturesState {
world: ScenarioWorld,
basic_features: BasicFeatures,
}

impl BasicFeaturesState {
fn new() -> Self {
let mut world = world();
let basic_features_code = world.code_expression(BASIC_FEATURES_PATH_EXPR);

world.set_state_step(
SetStateStep::new()
.put_account(
OWNER_ADDRESS_EXPR,
Account::new().nonce(1).balance(BigUintValue::from(100u64)),
)
.put_account(
BASIC_FEATURES_ADDRESS_EXPR,
Account::new().nonce(1).code(basic_features_code),
),
);
let basic_features_code =
world.code_expression(BASIC_FEATURES_PATH.eval_to_expr().as_str());

let basic_features = BasicFeatures::new(BASIC_FEATURES_ADDRESS_EXPR);
world.account(OWNER_ADDRESS).nonce(1).balance(100);
world
.account(BASIC_FEATURES_ADDRESS)
.nonce(1)
.code(basic_features_code);

Self {
world,
basic_features,
}
Self { world }
}
}
fn world() -> ScenarioWorld {
let mut blockchain = ScenarioWorld::new();
blockchain.set_current_dir_from_workspace("contracts/feature-tests/basic-features");

blockchain.register_contract(BASIC_FEATURES_PATH_EXPR, basic_features::ContractBuilder);
blockchain.register_contract(BASIC_FEATURES_PATH, basic_features::ContractBuilder);
blockchain
}

#[test]
fn egld_decimal_blackbox_test() {
let mut state = BasicFeaturesState::new();

let sc_call =
ContractCallWithEgld::<StaticApi, ManagedDecimal<StaticApi, ConstDecimals<18>>>::new(
ManagedAddress::from(state.basic_features.to_address()),
"returns_egld_decimal",
BigUint::from(5u64),
);

let egld_decimal: ManagedDecimal<StaticApi, ConstDecimals<18>> = state
let egld_decimal_result = state
.world
.sc_call_get_result(ScCallStep::new().call(sc_call).from("address:owner"));
.tx()
.from(OWNER_ADDRESS)
.to(BASIC_FEATURES_ADDRESS)
.typed(basic_features::basic_features_proxy::BasicFeaturesProxy)
.returns_egld_decimal()
.egld(5)
.returns(ReturnsResult)
.run();

assert_eq!(
egld_decimal,
egld_decimal_result,
ManagedDecimal::<StaticApi, ConstDecimals<18>>::const_decimals_from_raw(BigUint::from(
5u64
))
Expand Down
8 changes: 4 additions & 4 deletions contracts/feature-tests/basic-features/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 389
// Endpoints: 395
// Async Callback: 1
// Total number of exported functions: 391
// Total number of exported functions: 397

#![no_std]

Expand Down Expand Up @@ -406,13 +406,13 @@ multiversx_sc_wasm_adapter::endpoints! {
contains_unordered_at_address => contains_unordered_at_address
get_by_index => get_by_index
fill_set_mapper => fill_set_mapper
fill_map_mapper => fill_map_mapper
fill_unordered_set_mapper => fill_unordered_set_mapper
managed_decimal_addition => managed_decimal_addition
managed_decimal_subtraction => managed_decimal_subtraction
managed_decimal_eq => managed_decimal_eq
managed_decimal_trunc => managed_decimal_trunc
managed_decimal_into_raw_units => managed_decimal_into_raw_units
fill_map_mapper => fill_map_mapper
fill_unordered_set_mapper => fill_unordered_set_mapper
)
}

Expand Down

0 comments on commit 9100774

Please sign in to comment.