Skip to content

Commit

Permalink
Add blackbox test for builtin_func_features
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinCarabas committed Jan 13, 2025
1 parent 6fe9d6e commit 213d255
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

multiversx_sc::imports!();

pub mod builtin_func_features_proxy;
pub mod esdt_features;

/// Test contract for investigating async calls.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct BuiltinFuncFeaturesProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for BuiltinFuncFeaturesProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = BuiltinFuncFeaturesProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
BuiltinFuncFeaturesProxyMethods { wrapped_tx: tx }
}
}

pub struct BuiltinFuncFeaturesProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> BuiltinFuncFeaturesProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
Arg1: ProxyArg<TokenIdentifier<Env::Api>>,
>(
self,
fungible_token_id: Arg0,
non_fungible_token_id: Arg1,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.argument(&fungible_token_id)
.argument(&non_fungible_token_id)
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> BuiltinFuncFeaturesProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn call_set_user_name<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<ManagedBuffer<Env::Api>>,
>(
self,
address: Arg0,
name: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("call_set_user_name")
.argument(&address)
.argument(&name)
.original_result()
}

pub fn call_delete_user_name<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("call_delete_user_name")
.argument(&address)
.original_result()
}

pub fn transfer_fungible_promise_no_callback<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<BigUint<Env::Api>>,
>(
self,
to: Arg0,
amount: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("transferFungiblePromiseNoCallback")
.argument(&to)
.argument(&amount)
.original_result()
}

pub fn transfer_fungible_promise_with_callback<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<BigUint<Env::Api>>,
>(
self,
to: Arg0,
amount: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("transferFungiblePromiseWithCallback")
.argument(&to)
.argument(&amount)
.original_result()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use multiversx_sc_scenario::imports::*;

use builtin_func_features::*;

const OWNER_ADDRESS: TestAddress = TestAddress::new("owner");
const USER_ADDRESS: TestAddress = TestAddress::new("user");

const BUILTIN_FEATURES_FUNC_ADDRESS: TestSCAddress = TestSCAddress::new("builtin-func-features");
const CODE_PATH: MxscPath = MxscPath::new("output/builtin-func-features.mxsc.json");

const FUNGIBLE_TOKEN_ID: TestTokenIdentifier = TestTokenIdentifier::new("FUNG-123456");
const NON_FUNGIBLE_TOKEN_ID: TestTokenIdentifier = TestTokenIdentifier::new("NONFUNG-123456");

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

blockchain.set_current_dir_from_workspace(
"contracts/feature-tests/composability/builtin-func-features",
);
blockchain.register_contract(CODE_PATH, builtin_func_features::ContractBuilder);
blockchain
}

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

world
.account(USER_ADDRESS)
.nonce(1)
.balance(1000)
.esdt_balance(FUNGIBLE_TOKEN_ID, 1000)
.esdt_balance(NON_FUNGIBLE_TOKEN_ID, 1000);

world.start_trace();

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

let new_address = world
.tx()
.from(OWNER_ADDRESS)
.typed(builtin_func_features_proxy::BuiltinFuncFeaturesProxy)
.init(FUNGIBLE_TOKEN_ID, NON_FUNGIBLE_TOKEN_ID)
.code(CODE_PATH)
.new_address(BUILTIN_FEATURES_FUNC_ADDRESS)
.returns(ReturnsNewAddress)
.run();

assert_eq!(new_address, BUILTIN_FEATURES_FUNC_ADDRESS.to_address());

world
.tx()
.from(OWNER_ADDRESS)
.to(BUILTIN_FEATURES_FUNC_ADDRESS)
.typed(builtin_func_features_proxy::BuiltinFuncFeaturesProxy)
.transfer_fungible_promise_no_callback(USER_ADDRESS, 1000u64)
.run();

world
.check_account(USER_ADDRESS)
.esdt_balance(FUNGIBLE_TOKEN_ID, 1000u64);

world
.check_account(BUILTIN_FEATURES_FUNC_ADDRESS)
.esdt_balance(FUNGIBLE_TOKEN_ID, 0u64);
}

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

world
.account(USER_ADDRESS)
.nonce(1)
.balance(1000)
.esdt_balance(FUNGIBLE_TOKEN_ID, 1000)
.esdt_balance(NON_FUNGIBLE_TOKEN_ID, 1000);

world.start_trace();

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

let new_address = world
.tx()
.from(OWNER_ADDRESS)
.typed(builtin_func_features_proxy::BuiltinFuncFeaturesProxy)
.init(FUNGIBLE_TOKEN_ID, NON_FUNGIBLE_TOKEN_ID)
.code(CODE_PATH)
.new_address(BUILTIN_FEATURES_FUNC_ADDRESS)
.returns(ReturnsNewAddress)
.run();

assert_eq!(new_address, BUILTIN_FEATURES_FUNC_ADDRESS.to_address());

world
.tx()
.from(OWNER_ADDRESS)
.to(BUILTIN_FEATURES_FUNC_ADDRESS)
.typed(builtin_func_features_proxy::BuiltinFuncFeaturesProxy)
.transfer_fungible_promise_with_callback(USER_ADDRESS, 1000u64)
.run();

world
.check_account(USER_ADDRESS)
.esdt_balance(FUNGIBLE_TOKEN_ID, 1000u64);

world
.check_account(BUILTIN_FEATURES_FUNC_ADDRESS)
.esdt_balance(FUNGIBLE_TOKEN_ID, 0u64);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 3
// Endpoints: 4
// Async Callback (empty): 1
// Total number of exported functions: 5
// Promise callbacks: 1
// Total number of exported functions: 7

#![no_std]

Expand All @@ -21,6 +22,8 @@ multiversx_sc_wasm_adapter::endpoints! {
call_set_user_name => call_set_user_name
call_delete_user_name => call_delete_user_name
transferFungiblePromiseNoCallback => transfer_fungible_promise_no_callback
transferFungiblePromiseWithCallback => transfer_fungible_promise_with_callback
transfer_callback => transfer_callback
)
}

Expand Down

0 comments on commit 213d255

Please sign in to comment.