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

impl upgrade in scenario env #1642

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions contracts/examples/adder/tests/adder_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,18 @@ fn adder_blackbox() {
.check_account(ADDER_ADDRESS)
.check_storage("str:sum", "6");

world
.tx()
.from(OWNER_ADDRESS)
.to(ADDER_ADDRESS)
.typed(adder_proxy::AdderProxy)
.upgrade(100u64)
.code(CODE_PATH)
.run();

world
.check_account(ADDER_ADDRESS)
.check_storage("str:sum", "100");

world.write_scenario_trace("trace1.scen.json");
}
33 changes: 30 additions & 3 deletions framework/scenario/src/facade/world_tx/scenario_exec_call.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use multiversx_sc::{
tuple_util::NestedTupleFlatten,
types::{
heap::H256, FunctionCall, ManagedAddress, ManagedBuffer, RHListExec, Tx, TxBaseWithEnv,
TxEnv, TxEnvMockDeployAddress, TxEnvWithTxHash, TxFromSpecified, TxGas, TxPayment,
TxToSpecified,
heap::H256, Code, FunctionCall, ManagedAddress, ManagedBuffer, NotPayable, RHListExec, Tx,
TxBaseWithEnv, TxEnv, TxEnvMockDeployAddress, TxEnvWithTxHash, TxFromSpecified, TxGas,
TxPayment, TxToSpecified, UpgradeCall,
},
};

use crate::{
api::StaticApi,
imports::MxscPath,
scenario::tx_to_step::{address_annotated, TxToStep},
scenario_model::{SetStateStep, TxExpect, TxResponse},
ScenarioTxEnv, ScenarioTxRun, ScenarioWorld,
Expand Down Expand Up @@ -90,6 +91,32 @@ where
}
}

impl<'w, From, To, RH> ScenarioTxRun
for Tx<
ScenarioEnvExec<'w>,
From,
To,
NotPayable,
(),
UpgradeCall<ScenarioEnvExec<'w>, Code<MxscPath<'w>>>,
RH,
>
where
From: TxFromSpecified<ScenarioEnvExec<'w>>,
To: TxToSpecified<ScenarioEnvExec<'w>>,
RH: RHListExec<TxResponse, ScenarioEnvExec<'w>>,
RH::ListReturns: NestedTupleFlatten,
{
type Returns = <RH::ListReturns as NestedTupleFlatten>::Unpacked;

fn run(self) -> Self::Returns {
let mut step_wrapper = self.tx_to_step();
step_wrapper.step.explicit_tx_hash = core::mem::take(&mut step_wrapper.env.data.tx_hash);
step_wrapper.env.world.sc_call(&mut step_wrapper.step);
step_wrapper.process_result()
}
}

impl<'w> TxEnvWithTxHash for ScenarioEnvExec<'w> {
fn set_tx_hash(&mut self, tx_hash: H256) {
assert!(self.data.tx_hash.is_none(), "tx hash set twice");
Expand Down
59 changes: 57 additions & 2 deletions framework/scenario/src/scenario/tx_to_step/tx_to_step_call.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use multiversx_sc::types::{
FunctionCall, RHListExec, Tx, TxEnv, TxFromSpecified, TxGas, TxPayment, TxToSpecified,
Code, FunctionCall, NotPayable, RHListExec, Tx, TxEnv, TxFromSpecified, TxGas, TxPayment,
TxToSpecified, UpgradeCall,
};

use crate::scenario_model::{ScCallStep, TxESDT, TxExpect, TxResponse};
use crate::{
imports::MxscPath,
scenario_model::{ScCallStep, TxESDT, TxExpect, TxResponse},
ScenarioEnvExec,
};

use super::{address_annotated, gas_annotated, StepWrapper, TxToStep};

Expand Down Expand Up @@ -75,3 +80,53 @@ where

step
}

impl<'w, From, To, RH> TxToStep<ScenarioEnvExec<'w>, RH>
for Tx<
ScenarioEnvExec<'w>,
From,
To,
NotPayable,
(),
UpgradeCall<ScenarioEnvExec<'w>, Code<MxscPath<'w>>>,
RH,
>
where
From: TxFromSpecified<ScenarioEnvExec<'w>>,
To: TxToSpecified<ScenarioEnvExec<'w>>,
RH: RHListExec<TxResponse, ScenarioEnvExec<'w>>,
{
type Step = ScCallStep;

fn tx_to_step(self) -> StepWrapper<ScenarioEnvExec<'w>, Self::Step, RH> {
let mut step = tx_to_sc_call_upgrade_step(&self.env, self.from, self.to, self.data);
step.expect = Some(self.result_handler.list_tx_expect());

StepWrapper {
env: self.env,
step,
result_handler: self.result_handler,
}
}
}

pub fn tx_to_sc_call_upgrade_step<'a, 'w: 'a, From, To>(
env: &'a ScenarioEnvExec<'w>,
from: From,
to: To,
data: UpgradeCall<ScenarioEnvExec<'w>, Code<MxscPath>>,
) -> ScCallStep
where
From: TxFromSpecified<ScenarioEnvExec<'w>>,
To: TxToSpecified<ScenarioEnvExec<'w>>,
{
let mut step = ScCallStep::new()
.from(address_annotated(env, &from))
.to(address_annotated(env, &to))
.function("upgrade");
for arg in data.arg_buffer.iter_buffers() {
step.tx.arguments.push(arg.to_vec().into());
}

step
}
Loading