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

Rewards distribution blackbox #1576

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions contracts/examples/adder/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

[[proxy]]
path = "src/adder_proxy.rs"

[[proxy]]
path = "../multisig/src/adder_proxy.rs"
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crowdfunding_esdt::crowdfunding_esdt_proxy;

use multiversx_sc_scenario::imports::*;
use num_bigint::BigUint;

const CF_DEADLINE: u64 = 7 * 24 * 60 * 60; // 1 week in seconds
const CF_TOKEN_ID: &[u8] = b"CROWD-123456";
Expand All @@ -13,12 +12,12 @@ const CODE_EXPR: MxscExpr = MxscExpr("output/crowdfunding-esdt.mxsc.json");
const SC_CROWDFUNDING_ESDT_EXPR: ScExpr = ScExpr("crowdfunding-esdt");

fn world() -> ScenarioWorld {
let contract_path: &str = "mxsc:output/crowdfunding-esdt.mxsc.json";

let mut blockchain = ScenarioWorld::new();
blockchain.set_current_dir_from_workspace("contracts/examples/crowdfunding-esdt");

blockchain.register_contract(contract_path, crowdfunding_esdt::ContractBuilder);
blockchain.register_contract(
CODE_EXPR.eval_to_expr().as_str(),
crowdfunding_esdt::ContractBuilder,
);
blockchain
}

Expand All @@ -29,10 +28,9 @@ struct CrowdfundingESDTTestState {
impl CrowdfundingESDTTestState {
fn new() -> Self {
let mut world = world();
let owner_address: &str = "address:owner";

world
.account(owner_address)
.account(OWNER_ADDRESS)
.nonce(1)
.account(FIRST_USER_ADDRESS)
.nonce(1)
Expand All @@ -43,9 +41,9 @@ impl CrowdfundingESDTTestState {
.esdt_balance(CF_TOKEN_ID_EXPR, "1000");

world.set_state_step(SetStateStep::new().new_address(
owner_address,
OWNER_ADDRESS,
1,
SC_CROWDFUNDING_ESDT_EXPR.eval_to_expr().as_str(),
SC_CROWDFUNDING_ESDT_EXPR,
));

Self { world }
Expand Down Expand Up @@ -81,29 +79,23 @@ impl CrowdfundingESDTTestState {
}

fn check_deposit(&mut self, donor: AddressExpr, amount: u64) {
let value = self
.world
self.world
.query()
.to(SC_CROWDFUNDING_ESDT_EXPR)
.typed(crowdfunding_esdt_proxy::CrowdfundingProxy)
.deposit(donor.eval_to_array())
.returns(ReturnsResultConv::<BigUint>::new())
.returns(ExpectValue(amount))
.run();

assert_eq!(value, amount.into());
}

fn check_status(&mut self, expected_value: crowdfunding_esdt_proxy::Status) {
let status = self
.world
self.world
.query()
.to(SC_CROWDFUNDING_ESDT_EXPR)
.typed(crowdfunding_esdt_proxy::CrowdfundingProxy)
.status()
.returns(ReturnsResult)
.returns(ExpectValue(expected_value))
.run();

assert_eq!(status, expected_value);
}

fn claim(&mut self, address: AddressExpr) {
Expand Down
110 changes: 110 additions & 0 deletions contracts/examples/multisig/src/adder_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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 AdderProxy;

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

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

pub struct AdderProxyMethods<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> AdderProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init<
Arg0: CodecInto<BigUint<Env::Api>>,
>(
self,
initial_value: Arg0,
) -> TxProxyDeploy<Env, From, Gas, ()> {
self.wrapped_tx
.raw_deploy()
.argument(&initial_value)
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> AdderProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn upgrade<
Arg0: CodecInto<BigUint<Env::Api>>,
>(
self,
initial_value: Arg0,
) -> TxProxyUpgrade<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_upgrade()
.argument(&initial_value)
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> AdderProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn sum(
self,
) -> TxProxyCall<Env, From, To, Gas, BigUint<Env::Api>> {
self.wrapped_tx
.raw_call("getSum")
.original_result()
}

/// Add desired amount to the storage variable.
pub fn add<
Arg0: CodecInto<BigUint<Env::Api>>,
>(
self,
value: Arg0,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call("add")
.argument(&value)
.original_result()
}
}
Loading
Loading