Skip to content

Commit

Permalink
unified - payable blackbox
Browse files Browse the repository at this point in the history
  • Loading branch information
BiancaIalangi committed Dec 2, 2024
1 parent 320a314 commit d1095ad
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![no_std]
#![allow(clippy::type_complexity)]

multiversx_sc::imports!();
use multiversx_sc::imports::*;

pub mod payable_features_proxy;

/// Contract that only tests the call value features,
/// i.e. the framework/Arwen functionality for accepting EGLD and ESDT payments.
Expand Down
184 changes: 184 additions & 0 deletions contracts/feature-tests/payable-features/src/payable_features_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// 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 PayableFeaturesProxy;

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

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

pub struct PayableFeaturesProxyMethods<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> PayableFeaturesProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
self,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> PayableFeaturesProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn echo_call_value(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, ManagedVec<Env::Api, EsdtTokenPayment<Env::Api>>>> {
self.wrapped_tx
.raw_call("echo_call_value")
.original_result()
}

pub fn payment_multiple(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ManagedVec<Env::Api, EsdtTokenPayment<Env::Api>>> {
self.wrapped_tx
.raw_call("payment_multiple")
.original_result()
}

pub fn payment_array_3(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue3<EsdtTokenPayment<Env::Api>, EsdtTokenPayment<Env::Api>, EsdtTokenPayment<Env::Api>>> {
self.wrapped_tx
.raw_call("payment_array_3")
.original_result()
}

pub fn payable_any_1(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_any_1")
.original_result()
}

pub fn payable_any_2(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_any_2")
.original_result()
}

pub fn payable_any_3(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_any_3")
.original_result()
}

pub fn payable_any_4(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_any_4")
.original_result()
}

pub fn payable_egld_1(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_egld_1")
.original_result()
}

pub fn payable_egld_2(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_egld_2")
.original_result()
}

pub fn payable_egld_3(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_egld_3")
.original_result()
}

pub fn payable_egld_4(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_egld_4")
.original_result()
}

pub fn payable_token_1(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_token_1")
.original_result()
}

pub fn payable_token_2(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, TokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_token_2")
.original_result()
}

pub fn payable_token_3(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_token_3")
.original_result()
}

pub fn payable_token_4(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, TokenIdentifier<Env::Api>>> {
self.wrapped_tx
.raw_call("payable_token_4")
.original_result()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use multiversx_sc_scenario::imports::*;
use payable_features::payable_features_proxy;

const PF_PATH_EXPR: &str = "mxsc:output/payable-features.mxsc.json";
const PF_PATH_EXPR: MxscPath = MxscPath::new("output/payable-features.mxsc.json");
const PAYABLE_FEATURES_ADDRESS: TestSCAddress = TestSCAddress::new("payable-features");
const USER: TestAddress = TestAddress::new("an-account");
const TOKEN_1: TestTokenIdentifier = TestTokenIdentifier::new("TOK-000001");
const TOKEN_2: TestTokenIdentifier = TestTokenIdentifier::new("TOK-000002");
const TOKEN_3: TestTokenIdentifier = TestTokenIdentifier::new("TOK-000003");
const SFT: TestTokenIdentifier = TestTokenIdentifier::new("SFT-123");

fn world() -> ScenarioWorld {
let mut blockchain = ScenarioWorld::new();
Expand All @@ -13,33 +20,41 @@ fn world() -> ScenarioWorld {
#[test]
fn payable_multi() {
let mut world = world();
let pf_code = world.code_expression(PF_PATH_EXPR);

world
.set_state_step(
SetStateStep::new()
.put_account("sc:payable-features", Account::new().code(pf_code))
.put_account(
"address:an-account",
Account::new()
.balance("10000")
.esdt_balance("str:TOK-000001", "1000")
.esdt_balance("str:TOK-000002", "500")
.esdt_balance("str:TOK-000003", "500")
.esdt_nft_balance("str:SFT-123", 5u32, 10u32, Option::<()>::None)
),
)
.sc_call(
ScCallStep::new()
.from("address:an-account")
.to("sc:payable-features")
.function("echo_call_value")
.esdt_transfer("str:TOK-000001", 0, "100")
.esdt_transfer("str:TOK-000002", 0, "400")
.expect(
TxExpect::ok()
.result("0")
.result("nested:str:TOK-000001|u64:0|biguint:100|nested:str:TOK-000002|u64:0|biguint:400")
),
);
.account(USER)
.balance(10000)
.esdt_balance(TOKEN_1, 1000)
.esdt_balance(TOKEN_2, 500)
.esdt_balance(TOKEN_3, 500)
.esdt_nft_balance(SFT, 5, 10, ());

world
.tx()
.from(USER)
.typed(payable_features_proxy::PayableFeaturesProxy)
.init()
.new_address(PAYABLE_FEATURES_ADDRESS)
.code(PF_PATH_EXPR)
.run();

let result = world
.tx()
.from(USER)
.to(PAYABLE_FEATURES_ADDRESS)
.typed(payable_features_proxy::PayableFeaturesProxy)
.echo_call_value()
.esdt(TestEsdtTransfer(TOKEN_1, 0, 100))
.esdt(TestEsdtTransfer(TOKEN_2, 0, 400))
.returns(ReturnsResultUnmanaged)
.run();

assert_eq!(result.0 .0, RustBigUint::from(0u32));
assert_eq!(
result.0 .1,
vec![
EsdtTokenPayment::new(TOKEN_1.to_token_identifier(), 0, BigUint::from(100u32)),
EsdtTokenPayment::new(TOKEN_2.to_token_identifier(), 0, BigUint::from(400u32))
]
);
}

0 comments on commit d1095ad

Please sign in to comment.