Skip to content

Commit

Permalink
add blackbox tests for empty contract example
Browse files Browse the repository at this point in the history
  • Loading branch information
ovstinga committed Jul 11, 2023
1 parent d16b362 commit 682b1f4
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contracts/examples/empty/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

# The mxpy output
/output*/

# Generated scenarios
/*scen.json
105 changes: 105 additions & 0 deletions contracts/examples/empty/tests/empty_blackbox_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use empty::*;
use multiversx_sc_scenario::{api::StaticApi, scenario_model::*, *};

const CWD: &str = "contracts/examples/empty";
const EMPTY_WASM: &str = "file:output/empty.wasm";
const OWNER_ADDRESS: &str = "address:owner";
const EMPTY_SC_ADDRESS: &str = "sc:empty";
const GAS_LIMIT: &str = "5,000,000";

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

blockchain.register_contract(EMPTY_WASM, empty::ContractBuilder);
blockchain
}

#[test]
fn empty_blackbox_init_raw() {
let mut world = world();
let ic = world.interpreter_context();

world
.set_state_step(
SetStateStep::new()
.put_account(OWNER_ADDRESS, Account::new().nonce(1))
.new_address(OWNER_ADDRESS, 1, EMPTY_SC_ADDRESS),
)
.sc_deploy_step(
ScDeployStep::new()
.from(OWNER_ADDRESS)
.contract_code(EMPTY_WASM, &ic)
.gas_limit(GAS_LIMIT)
.expect(TxExpect::ok().no_result()),
)
.check_state_step(
CheckStateStep::new()
.put_account(OWNER_ADDRESS, CheckAccount::new())
.put_account(EMPTY_SC_ADDRESS, CheckAccount::new()),
);
}

#[test]
fn empty_blackbox_init_call() {
let mut world = world();
let ic = world.interpreter_context();

let owner_address = OWNER_ADDRESS;
let mut empty_contract = ContractInfo::<empty::Proxy<StaticApi>>::new(EMPTY_SC_ADDRESS);

world
.start_trace()
.set_state_step(
SetStateStep::new()
.put_account(owner_address, Account::new().nonce(1))
.new_address(owner_address, 1, &empty_contract),
)
.sc_deploy_step(
ScDeployStep::new()
.from(owner_address)
.contract_code(EMPTY_WASM, &ic)
.call(empty_contract.init())
.gas_limit(GAS_LIMIT)
.expect(TxExpect::ok().no_result()),
)
.check_state_step(
CheckStateStep::new()
.put_account(owner_address, CheckAccount::new())
.put_account(&empty_contract, CheckAccount::new()),
)
.write_scenario_trace("empty_blackbox_init_call.scen.json");
}

#[test]
fn empty_blackbox_init_result() {
let mut world = world();
let ic = world.interpreter_context();

let owner_address = OWNER_ADDRESS;
let mut empty_contract = ContractInfo::<empty::Proxy<StaticApi>>::new(EMPTY_SC_ADDRESS);

world.start_trace().set_state_step(
SetStateStep::new()
.put_account(owner_address, Account::new().nonce(1))
.new_address(owner_address, 1, &empty_contract),
);

let (new_address, ()) = empty_contract
.init()
.into_blockchain_call()
.from(owner_address)
.contract_code(EMPTY_WASM, &ic)
.gas_limit(GAS_LIMIT)
.expect(TxExpect::ok().no_result())
.execute(&mut world);
assert_eq!(new_address, empty_contract.to_address());

world
.check_state_step(
CheckStateStep::new()
.put_account(owner_address, CheckAccount::new())
.put_account(&empty_contract, CheckAccount::new()),
)
.write_scenario_trace("empty_blackbox_init_result.scen.json");
}

0 comments on commit 682b1f4

Please sign in to comment.