Skip to content

Commit

Permalink
Merge pull request #1732 from multiversx/test-managed-option-gen-proxy
Browse files Browse the repository at this point in the history
Test for ManagedOption type name
  • Loading branch information
BiancaIalangi committed Aug 20, 2024
2 parents fb98353 + d235aeb commit 46ebb5d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
8 changes: 7 additions & 1 deletion contracts/feature-tests/basic-features/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ kill_legacy_callback = true
[[proxy]]
path = "src/basic_features_proxy.rs"
add-unlabelled = false
add-endpoints = ["init", "store_bytes", "load_bytes", "returns_egld_decimal"]
add-endpoints = [
"init",
"store_bytes",
"load_bytes",
"returns_egld_decimal",
"echo_managed_option",
]
14 changes: 14 additions & 0 deletions contracts/feature-tests/basic-features/src/basic_features_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ where
To: TxTo<Env>,
Gas: TxGas<Env>,
{
/// This tests how is generated type name in proxy
pub fn echo_managed_option<
Arg0: ProxyArg<ManagedOption<Env::Api, BigUint<Env::Api>>>,
>(
self,
mo: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedOption<Env::Api, BigUint<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("echo_managed_option")
.argument(&mo)
.original_result()
}

pub fn load_bytes(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedBuffer<Env::Api>> {
Expand Down
8 changes: 7 additions & 1 deletion contracts/feature-tests/basic-features/src/echo_managed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
multiversx_sc::imports!();
use multiversx_sc::imports::*;

/// Test endpoint argument and result serialization.
#[multiversx_sc::module]
Expand All @@ -23,6 +23,12 @@ pub trait EchoManagedTypes {
ma
}

/// This tests how is generated type name in proxy
#[endpoint]
fn echo_managed_option(&self, mo: ManagedOption<BigUint>) -> ManagedOption<BigUint> {
mo
}

/// This tests that nested serialization of big ints within unmanaged types works.
#[endpoint]
fn echo_big_int_managed_vec(&self, x: ManagedVec<BigInt>) -> ManagedVec<BigInt> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use imports::{MxscPath, ReturnsResult, TestAddress, TestSCAddress};
use multiversx_sc::types::{BigUint, ManagedOption};
use multiversx_sc_scenario::{api::StaticApi, imports, ScenarioTxRun, ScenarioWorld};

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");

fn world() -> ScenarioWorld {
let mut blockchain = ScenarioWorld::new();

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

blockchain.account(OWNER_ADDRESS).nonce(1);
blockchain
.account(BASIC_FEATURES_ADDRESS)
.nonce(1)
.code(BASIC_FEATURES_PATH);

blockchain
}

#[test]
fn managed_option_test() {
let mut world = world();

let type_number: BigUint<StaticApi> = BigUint::zero();
let expected_type_managed_option: ManagedOption<StaticApi, BigUint<StaticApi>> =
ManagedOption::some(type_number);

let output = world
.tx()
.from(OWNER_ADDRESS)
.to(BASIC_FEATURES_ADDRESS)
.typed(basic_features::basic_features_proxy::BasicFeaturesProxy)
.echo_managed_option(expected_type_managed_option.clone())
.returns(ReturnsResult)
.run();

assert_eq!(output, expected_type_managed_option);
}
5 changes: 3 additions & 2 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: 403
// Endpoints: 404
// Async Callback: 1
// Total number of exported functions: 405
// Total number of exported functions: 406

#![no_std]

Expand Down Expand Up @@ -169,6 +169,7 @@ multiversx_sc_wasm_adapter::endpoints! {
echo_big_int => echo_big_int
echo_managed_buffer => echo_managed_buffer
echo_managed_address => echo_managed_address
echo_managed_option => echo_managed_option
echo_big_int_managed_vec => echo_big_int_managed_vec
echo_big_int_tuple => echo_big_int_tuple
echo_big_int_option => echo_big_int_option
Expand Down

0 comments on commit 46ebb5d

Please sign in to comment.