Skip to content

Commit

Permalink
Merge pull request #1693 from multiversx/interactor-missing-code
Browse files Browse the repository at this point in the history
Interactor - proper error when code is missing
  • Loading branch information
andrei-marinica authored Jul 2, 2024
2 parents ea7c8e4 + 967e501 commit ead1f3f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
12 changes: 4 additions & 8 deletions contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use multiversx_sc_snippets::imports::*;

const INTERACTOR_SCENARIO_TRACE_PATH: &str = "interactor_trace.scen.json";

const ADDER_CODE_PATH: MxscPath = MxscPath::new("../output/adder.mxsc.json");

#[tokio::main]
async fn main() {
env_logger::init();
Expand Down Expand Up @@ -42,7 +44,6 @@ async fn main() {
struct AdderInteract {
interactor: Interactor,
wallet_address: Bech32Address,
adder_code: BytesValue,
state: State,
}

Expand All @@ -54,15 +55,10 @@ impl AdderInteract {
.with_tracer(INTERACTOR_SCENARIO_TRACE_PATH)
.await;
let wallet_address = interactor.register_wallet(test_wallets::mike());
let adder_code = BytesValue::interpret_from(
"mxsc:../output/adder.mxsc.json",
&InterpreterContext::default(),
);

Self {
interactor,
wallet_address: wallet_address.into(),
adder_code,
state: State::load_state(),
}
}
Expand All @@ -84,7 +80,7 @@ impl AdderInteract {
.from(&self.wallet_address)
.typed(adder_proxy::AdderProxy)
.init(0u32)
.code(&self.adder_code)
.code(ADDER_CODE_PATH)
.returns(ReturnsNewBech32Address)
.prepare_async()
.run()
Expand All @@ -109,7 +105,7 @@ impl AdderInteract {
tx.from(&self.wallet_address)
.typed(adder_proxy::AdderProxy)
.init(0u32)
.code(&self.adder_code)
.code(ADDER_CODE_PATH)
.gas(NumExpr("70,000,000"))
.returns(ReturnsNewBech32Address)
});
Expand Down
12 changes: 5 additions & 7 deletions framework/scenario/src/facade/world_tx/scenario_tx_env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use multiversx_chain_scenario_format::interpret_trait::InterpreterContext;
use multiversx_sc::types::{ManagedAddress, ManagedBuffer, TxEnv, H256};

Expand All @@ -13,7 +11,7 @@ pub trait ScenarioTxEnv: TxEnv {
/// The actual data required to run a scenario locally. This is the minimal environment needed to run txs.
#[derive(Default, Debug, Clone)]
pub struct ScenarioTxEnvData {
pub context_path: PathBuf,
pub interpreter_context: InterpreterContext,
pub tx_hash: Option<H256>,
}

Expand All @@ -37,9 +35,7 @@ impl TxEnv for ScenarioTxEnvData {

impl ScenarioTxEnvData {
pub fn interpreter_context(&self) -> InterpreterContext {
InterpreterContext::default()
.with_dir(self.context_path.clone())
.with_allowed_missing_files()
self.interpreter_context.clone()
}
}

Expand All @@ -52,7 +48,9 @@ impl ScenarioTxEnv for ScenarioTxEnvData {
impl ScenarioWorld {
pub(crate) fn new_env_data(&self) -> ScenarioTxEnvData {
ScenarioTxEnvData {
context_path: self.current_dir.clone(),
interpreter_context: InterpreterContext::new()
.with_dir(self.current_dir.clone())
.with_allowed_missing_files(),
tx_hash: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use multiversx_sc_scenario::ScenarioTxEnvData;
use multiversx_sc_scenario::{imports::InterpreterContext, ScenarioTxEnvData};

use crate::Interactor;

impl Interactor {
pub(crate) fn new_env_data(&self) -> ScenarioTxEnvData {
ScenarioTxEnvData {
context_path: self.current_dir.clone(),
interpreter_context: InterpreterContext::new().with_dir(self.current_dir.clone()),
tx_hash: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/scenario-format/src/interpret_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use crate::value_interpreter::VMIdentifier;

#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
pub struct InterpreterContext {
pub context_path: PathBuf,
pub vm_type: VMIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion sdk/scenario-format/src/value_interpreter/vm_identifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub const VM_TYPE_LENGTH: usize = 2;

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct VMIdentifier {
pub vm_type: [u8; VM_TYPE_LENGTH],
}
Expand Down

0 comments on commit ead1f3f

Please sign in to comment.