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

Testing framework & interactor syntax harmonization #1162

Merged
merged 10 commits into from
Jul 14, 2023
97 changes: 49 additions & 48 deletions contracts/examples/adder/interact/src/adder_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use multiversx_sc_snippets::{
mandos_system::ScenarioRunner,
num_bigint::BigUint,
scenario_format::interpret_trait::{InterpretableFrom, InterpreterContext},
scenario_model::{IntoBlockchainCall, Scenario, TransferStep, TxExpect},
scenario_model::{ScCallStep, ScDeployStep, ScQueryStep, Scenario, TransferStep, TxExpect},
standalone::retrieve_account_as_scenario_set_state,
test_wallets, ContractInfo,
},
Expand Down Expand Up @@ -95,30 +95,27 @@ impl AdderInteract {
async fn deploy(&mut self) {
self.set_state().await;

let mut typed_sc_deploy = self
.state
.default_adder()
.init(BigUint::from(0u64))
.into_blockchain_call()
.from(&self.wallet_address)
.code_metadata(CodeMetadata::all())
.contract_code("file:../output/adder.wasm", &InterpreterContext::default())
.gas_limit("70,000,000")
.expect(TxExpect::ok());

self.interactor.sc_deploy(&mut typed_sc_deploy).await;

let result = typed_sc_deploy.response().new_deployed_address();
if result.is_err() {
println!("deploy failed: {}", result.err().unwrap());
return;
}

let new_address_bech32 = bech32::encode(&result.unwrap());
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
self.state.set_adder_address(&new_address_expr);
self.interactor
.sc_deploy_use_result(
ScDeployStep::new()
.call(self.state.default_adder().init(BigUint::from(0u64)))
.from(&self.wallet_address)
.code_metadata(CodeMetadata::all())
.contract_code("file:../output/adder.wasm", &InterpreterContext::default())
.gas_limit("5,000,000")
.expect(TxExpect::ok()),
|new_address, tr| {
tr.result
.unwrap_or_else(|err| panic!("deploy failed: {}", err.message));

let new_address_bech32 = bech32::encode(&new_address);
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
self.state.set_adder_address(&new_address_expr);
},
)
.await;
}

async fn multi_deploy(&mut self, count: &u8) {
Expand All @@ -132,11 +129,8 @@ impl AdderInteract {

let mut steps = Vec::new();
for _ in 0..*count {
let typed_sc_deploy = self
.state
.default_adder()
.init(BigUint::from(0u64))
.into_blockchain_call()
let typed_sc_deploy = ScDeployStep::new()
.call(self.state.default_adder().init(0u32))
.from(&self.wallet_address)
.code_metadata(CodeMetadata::all())
.contract_code("file:../output/adder.wasm", &InterpreterContext::default())
Expand Down Expand Up @@ -175,28 +169,35 @@ impl AdderInteract {
}

async fn add(&mut self, value: u64) {
let mut typed_sc_call = self
.state
.adder()
.add(BigUint::from(value))
.into_blockchain_call()
.from(&self.wallet_address)
.gas_limit("70,000,000")
.expect(TxExpect::ok());

self.interactor.sc_call(&mut typed_sc_call).await;

let result = typed_sc_call.response().handle_signal_error_event();
if result.is_err() {
println!("performing add failed with: {}", result.err().unwrap());
return;
}
self.interactor
.sc_call_use_result(
ScCallStep::new()
.call(self.state.adder().add(value))
.from(&self.wallet_address)
.gas_limit("5,000,000")
.expect(TxExpect::ok()),
|tr| {
tr.result.unwrap_or_else(|err| {
panic!("performing add failed with: {}", err.message)
});
},
)
.await;

println!("successfully performed add");
}

async fn print_sum(&mut self) {
let sum: SingleValue<BigUint> = self.interactor.vm_query(self.state.adder().sum()).await;
println!("sum: {}", sum.into());
self.interactor
.sc_query_use_result(
ScQueryStep::new()
.call(self.state.adder().sum())
.expect(TxExpect::ok()),
|tr| {
let sum: SingleValue<BigUint> = tr.result.unwrap();
println!("sum: {}", sum.into());
},
)
.await;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ impl State {

/// Returns the adder contract
pub fn adder(&self) -> AdderContract {
AdderContract::new(self.adder_address.clone().unwrap())
AdderContract::new(
self.adder_address
.clone()
.expect("no known adder contract, deploy first"),
)
}

/// Returns the adder contract with default address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@
.put_account(owner_address, Account::new().nonce(1))
.new_address(owner_address, 1, "sc:adder"),
)
.sc_deploy_step(
.sc_deploy_use_result(

Check failure on line 27 in contracts/examples/adder/tests/adder_mandos_constructed_with_calls_test.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/examples/adder/tests/adder_mandos_constructed_with_calls_test.rs#L27

error[E0283]: type annotations needed for `multiversx_sc_scenario::scenario_model::TypedResponse<RequestedResult>` --> contracts/examples/adder/tests/adder_mandos_constructed_with_calls_test.rs:34:27 | 27 | .sc_deploy_use_result( | -------------------- type must be known at this point ... 34 | |new_address, _| { | ^ | = note: multiple `impl`s satisfying `_: multiversx_sc::multiversx_sc_codec::CodecFrom<()>` found in the `multiversx_sc_codec` crate: - impl<T, U> multiversx_sc::multiversx_sc_codec::CodecFrom<U> for multiversx_sc::multiversx_sc_codec::multi_types::OptionalValue<T> where T: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, T: multiversx_sc::multiversx_sc_codec::TopDecodeMulti, U: multiversx_sc::multiversx_sc_codec::CodecFrom<T>, U: multiversx_sc::multiversx_sc_codec::CodecFromSelf, U: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, U: multiversx_sc::multiversx_sc_codec::TopDecodeMulti; - impl<T> multiversx_sc::multiversx_sc_codec::CodecFrom<T> for T where T: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, T: multiversx_sc::multiversx_sc_codec::TopDecodeMulti, T: multiversx_sc::multiversx_sc_codec::CodecFromSelf; - impl<T> multiversx_sc::multiversx_sc_codec::CodecFrom<T> for multiversx_sc::multiversx_sc_codec::multi_types::PlaceholderOutput where T: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, T: multiversx_sc::multiversx_sc_codec::CodecFromSelf; note: required by a bound in `multiversx_sc_scenario::facade::scenario_world_steps::<impl multiversx_sc_scenario::ScenarioWorld>::sc_deploy_use_result` --> /home/runner/work/mx-sdk-rs/mx-sdk-rs/framework/scenario/src/facade/scenario_world_steps.rs:169:26 | 169 | RequestedResult: CodecFrom<OriginalResult>, | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `multiversx_sc_scenario::facade::scenario_world_steps::<impl ScenarioWorld>::sc_deploy_use_result` help: consider giving this closure parameter an explicit type, where the type for type parameter `RequestedResult` is specified | 34 | |new_address, _: multiversx_sc_scenario::scenario_model::TypedResponse<RequestedResult>| { | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Raw output
contracts/examples/adder/tests/adder_mandos_constructed_with_calls_test.rs:27:10:e:error[E0283]: type annotations needed for `multiversx_sc_scenario::scenario_model::TypedResponse<RequestedResult>`
   --> contracts/examples/adder/tests/adder_mandos_constructed_with_calls_test.rs:34:27
    |
27  |         .sc_deploy_use_result(
    |          -------------------- type must be known at this point
...
34  |             |new_address, _| {
    |                           ^
    |
    = note: multiple `impl`s satisfying `_: multiversx_sc::multiversx_sc_codec::CodecFrom<()>` found in the `multiversx_sc_codec` crate:
            - impl<T, U> multiversx_sc::multiversx_sc_codec::CodecFrom<U> for multiversx_sc::multiversx_sc_codec::multi_types::OptionalValue<T>
              where T: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, T: multiversx_sc::multiversx_sc_codec::TopDecodeMulti, U: multiversx_sc::multiversx_sc_codec::CodecFrom<T>, U: multiversx_sc::multiversx_sc_codec::CodecFromSelf, U: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, U: multiversx_sc::multiversx_sc_codec::TopDecodeMulti;
            - impl<T> multiversx_sc::multiversx_sc_codec::CodecFrom<T> for T
              where T: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, T: multiversx_sc::multiversx_sc_codec::TopDecodeMulti, T: multiversx_sc::multiversx_sc_codec::CodecFromSelf;
            - impl<T> multiversx_sc::multiversx_sc_codec::CodecFrom<T> for multiversx_sc::multiversx_sc_codec::multi_types::PlaceholderOutput
              where T: multiversx_sc::multiversx_sc_codec::TopEncodeMulti, T: multiversx_sc::multiversx_sc_codec::CodecFromSelf;
note: required by a bound in `multiversx_sc_scenario::facade::scenario_world_steps::<impl multiversx_sc_scenario::ScenarioWorld>::sc_deploy_use_result`
   --> /home/runner/work/mx-sdk-rs/mx-sdk-rs/framework/scenario/src/facade/scenario_world_steps.rs:169:26
    |
169 |         RequestedResult: CodecFrom<OriginalResult>,
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `multiversx_sc_scenario::facade::scenario_world_steps::<impl ScenarioWorld>::sc_deploy_use_result`
help: consider giving this closure parameter an explicit type, where the type for type parameter `RequestedResult` is specified
    |
34  |             |new_address, _: multiversx_sc_scenario::scenario_model::TypedResponse<RequestedResult>| {
    |                            ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


__END__
ScDeployStep::new()
.from(owner_address)
.contract_code("file:output/adder.wasm", &ic)
.call(adder_contract.init(5u32))
.gas_limit("5,000,000")
.expect(TxExpect::ok().no_result()),
|new_address, _| {

Check failure on line 34 in contracts/examples/adder/tests/adder_mandos_constructed_with_calls_test.rs

View workflow job for this annotation

GitHub Actions / Contracts / Rust tests

type annotations needed for `TypedResponse<RequestedResult>`

Check failure on line 34 in contracts/examples/adder/tests/adder_mandos_constructed_with_calls_test.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

type annotations needed for `TypedResponse<RequestedResult>`
assert_eq!(new_address, adder_contract.to_address());
},
)
.sc_query_step(
ScQueryStep::new()
.to(&adder_contract)
.call_expect(adder_contract.sum(), SingleValue::from(BigUint::from(5u32))),
.call(adder_contract.sum())
.expect_value(SingleValue::from(BigUint::from(5u32))),
)
.sc_call_step(
ScCallStep::new()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ fn crowdfunding_scenario_rust_test() {
.put_account(owner_addr, Account::new())
.new_address(owner_addr, 0, &cf_sc),
);
let (_, ()) = cf_sc
.init(
2_000u32,
deadline,
EgldOrEsdtTokenIdentifier::esdt(cf_token_id_value),
)
.into_blockchain_call()
.from(owner_addr)
.contract_code("file:output/crowdfunding-esdt.wasm", &ctx)
.gas_limit("5,000,000")
.expect(TxExpect::ok().no_result())
.execute(&mut world);

world.sc_deploy_step(
ScDeployStep::new()
.from(owner_addr)
.contract_code("file:output/crowdfunding-esdt.wasm", &ctx)
.call(cf_sc.init(
2_000u32,
deadline,
EgldOrEsdtTokenIdentifier::esdt(cf_token_id_value),
))
.gas_limit("5,000,000")
.expect(TxExpect::ok().no_result()),
);

// setup user accounts
world
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ impl MultisigInteract {

async fn quorum_reached(&mut self, action_id: usize) -> bool {
self.interactor
.vm_query(self.state.multisig().quorum_reached(action_id))
.quick_query(self.state.multisig().quorum_reached(action_id))
.await
}

async fn signed(&mut self, signer: &Address, action_id: usize) -> bool {
self.interactor
.vm_query(self.state.multisig().signed(signer, action_id))
.quick_query(self.state.multisig().signed(signer, action_id))
.await
}

Expand Down Expand Up @@ -395,7 +395,7 @@ impl MultisigInteract {
async fn print_quorum(&mut self) {
let quorum: SingleValue<usize> = self
.interactor
.vm_query(self.state.multisig().quorum())
.quick_query(self.state.multisig().quorum())
.await;

println!("quorum: {}", quorum.into());
Expand All @@ -404,7 +404,7 @@ impl MultisigInteract {
async fn print_board(&mut self) {
let board: SingleValue<usize> = self
.interactor
.vm_query(self.state.multisig().num_board_members())
.quick_query(self.state.multisig().num_board_members())
.await;

println!("board: {}", board.into());
Expand Down
Loading
Loading