Skip to content

Commit 34dc67c

Browse files
Merge pull request #1833 from multiversx/upgrade-step-refactor
unified syntax - upgrade refactor (multi-upgrade now possible)
2 parents f88c38e + 00e0871 commit 34dc67c

File tree

4 files changed

+70
-121
lines changed

4 files changed

+70
-121
lines changed

framework/scenario/src/scenario/tx_to_step.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod tx_to_step_deploy;
55
mod tx_to_step_query;
66
mod tx_to_step_trait;
77
mod tx_to_step_transfer;
8+
mod tx_to_step_upgrade;
89

910
pub use step_annotation::*;
1011
pub use step_wrapper::{StepWithResponse, StepWrapper};

framework/scenario/src/scenario/tx_to_step/tx_to_step_call.rs

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
use multiversx_sc::types::{
2-
Code, FunctionCall, NotPayable, RHListExec, Tx, TxEnv, TxEnvWithTxHash, TxFromSpecified, TxGas,
3-
TxPayment, TxToSpecified, UpgradeCall,
2+
FunctionCall, RHListExec, Tx, TxEnv, TxEnvWithTxHash, TxFromSpecified, TxGas, TxPayment,
3+
TxToSpecified,
44
};
55

6-
use crate::{
7-
imports::MxscPath,
8-
scenario_model::{ScCallStep, TxESDT, TxExpect, TxResponse},
9-
ScenarioEnvExec,
10-
};
6+
use crate::scenario_model::{ScCallStep, TxESDT, TxExpect, TxResponse};
117

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

@@ -81,53 +77,3 @@ where
8177

8278
step
8379
}
84-
85-
impl<'w, From, To, RH> TxToStep<ScenarioEnvExec<'w>, RH>
86-
for Tx<
87-
ScenarioEnvExec<'w>,
88-
From,
89-
To,
90-
NotPayable,
91-
(),
92-
UpgradeCall<ScenarioEnvExec<'w>, Code<MxscPath<'w>>>,
93-
RH,
94-
>
95-
where
96-
From: TxFromSpecified<ScenarioEnvExec<'w>>,
97-
To: TxToSpecified<ScenarioEnvExec<'w>>,
98-
RH: RHListExec<TxResponse, ScenarioEnvExec<'w>>,
99-
{
100-
type Step = ScCallStep;
101-
102-
fn tx_to_step(self) -> StepWrapper<ScenarioEnvExec<'w>, Self::Step, RH> {
103-
let mut step = tx_to_sc_call_upgrade_step(&self.env, self.from, self.to, self.data);
104-
step.expect = Some(self.result_handler.list_tx_expect());
105-
106-
StepWrapper {
107-
env: self.env,
108-
step,
109-
result_handler: self.result_handler,
110-
}
111-
}
112-
}
113-
114-
pub fn tx_to_sc_call_upgrade_step<'a, 'w: 'a, From, To>(
115-
env: &'a ScenarioEnvExec<'w>,
116-
from: From,
117-
to: To,
118-
data: UpgradeCall<ScenarioEnvExec<'w>, Code<MxscPath>>,
119-
) -> ScCallStep
120-
where
121-
From: TxFromSpecified<ScenarioEnvExec<'w>>,
122-
To: TxToSpecified<ScenarioEnvExec<'w>>,
123-
{
124-
let mut step = ScCallStep::new()
125-
.from(address_annotated(env, &from))
126-
.to(address_annotated(env, &to))
127-
.function("upgrade");
128-
for arg in data.arg_buffer.iter_buffers() {
129-
step.tx.arguments.push(arg.to_vec().into());
130-
}
131-
132-
step
133-
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use multiversx_sc::types::{
2+
Code, NotPayable, RHListExec, Tx, TxCodeValue, TxEnv, TxFromSpecified, TxGas, TxToSpecified,
3+
UpgradeCall,
4+
};
5+
6+
use crate::{
7+
imports::ScCallStep,
8+
scenario_model::{TxExpect, TxResponse},
9+
};
10+
11+
use super::{address_annotated, code_annotated, gas_annotated, StepWrapper, TxToStep};
12+
13+
impl<Env, From, To, Gas, RH, CodeValue> TxToStep<Env, RH>
14+
for Tx<Env, From, To, NotPayable, Gas, UpgradeCall<Env, Code<CodeValue>>, RH>
15+
where
16+
Env: TxEnv<RHExpect = TxExpect>,
17+
From: TxFromSpecified<Env>,
18+
To: TxToSpecified<Env>,
19+
Gas: TxGas<Env>,
20+
CodeValue: TxCodeValue<Env>,
21+
RH: RHListExec<TxResponse, Env>,
22+
{
23+
type Step = ScCallStep;
24+
25+
fn tx_to_step(self) -> StepWrapper<Env, Self::Step, RH> {
26+
let mut step =
27+
tx_to_sc_call_upgrade_step(&self.env, self.from, self.to, self.gas, self.data);
28+
step.expect = Some(self.result_handler.list_tx_expect());
29+
30+
StepWrapper {
31+
env: self.env,
32+
step,
33+
result_handler: self.result_handler,
34+
}
35+
}
36+
}
37+
38+
pub fn tx_to_sc_call_upgrade_step<'a, 'w: 'a, Env, From, To, Gas, CodeValue>(
39+
env: &Env,
40+
from: From,
41+
to: To,
42+
gas: Gas,
43+
data: UpgradeCall<Env, Code<CodeValue>>,
44+
) -> ScCallStep
45+
where
46+
Env: TxEnv,
47+
From: TxFromSpecified<Env>,
48+
To: TxToSpecified<Env>,
49+
Gas: TxGas<Env>,
50+
CodeValue: TxCodeValue<Env>,
51+
{
52+
let mut step = ScCallStep::new()
53+
.from(address_annotated(env, &from))
54+
.to(address_annotated(env, &to))
55+
.function("upgradeContract")
56+
.argument(code_annotated(env, data.code_source))
57+
.argument(data.code_metadata.to_byte_array().to_vec());
58+
59+
step.tx.gas_limit = gas_annotated(env, gas);
60+
61+
for arg in data.arg_buffer.iter_buffers() {
62+
step.tx.arguments.push(arg.to_vec().into());
63+
}
64+
65+
step
66+
}

framework/snippets-base/src/interactor_tx/interactor_exec_upgrade.rs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -96,67 +96,3 @@ where
9696
}
9797
}
9898
}
99-
100-
impl<'w, GatewayProxy, From, To, Gas, RH, CodeValue>
101-
TxToStep<InteractorEnvExec<'w, GatewayProxy>, RH>
102-
for Tx<
103-
InteractorEnvExec<'w, GatewayProxy>,
104-
From,
105-
To,
106-
NotPayable,
107-
Gas,
108-
UpgradeCall<InteractorEnvExec<'w, GatewayProxy>, Code<CodeValue>>,
109-
RH,
110-
>
111-
where
112-
GatewayProxy: GatewayAsyncService,
113-
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
114-
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
115-
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
116-
CodeValue: TxCodeValue<InteractorEnvExec<'w, GatewayProxy>>,
117-
RH: RHListExec<TxResponse, InteractorEnvExec<'w, GatewayProxy>>,
118-
RH::ListReturns: NestedTupleFlatten,
119-
{
120-
type Step = ScCallStep;
121-
122-
fn tx_to_step(self) -> StepWrapper<InteractorEnvExec<'w, GatewayProxy>, Self::Step, RH> {
123-
let mut step =
124-
tx_to_sc_call_upgrade_step(&self.env, self.from, self.to, self.gas, self.data);
125-
step.expect = Some(self.result_handler.list_tx_expect());
126-
127-
StepWrapper {
128-
env: self.env,
129-
step,
130-
result_handler: self.result_handler,
131-
}
132-
}
133-
}
134-
135-
pub fn tx_to_sc_call_upgrade_step<'a, 'w: 'a, GatewayProxy, From, To, Gas, CodeValue>(
136-
env: &'a InteractorEnvExec<'w, GatewayProxy>,
137-
from: From,
138-
to: To,
139-
gas: Gas,
140-
data: UpgradeCall<InteractorEnvExec<'w, GatewayProxy>, Code<CodeValue>>,
141-
) -> ScCallStep
142-
where
143-
GatewayProxy: GatewayAsyncService,
144-
From: TxFromSpecified<InteractorEnvExec<'w, GatewayProxy>>,
145-
To: TxToSpecified<InteractorEnvExec<'w, GatewayProxy>>,
146-
Gas: TxGas<InteractorEnvExec<'w, GatewayProxy>>,
147-
CodeValue: TxCodeValue<InteractorEnvExec<'w, GatewayProxy>>,
148-
{
149-
let mut step = ScCallStep::new()
150-
.from(address_annotated(env, &from))
151-
.to(address_annotated(env, &to))
152-
.gas_limit(gas.gas_value(env))
153-
.function("upgradeContract")
154-
.argument(code_annotated(env, data.code_source))
155-
.argument(data.code_metadata.to_byte_array().to_vec());
156-
157-
for arg in data.arg_buffer.iter_buffers() {
158-
step.tx.arguments.push(arg.to_vec().into());
159-
}
160-
161-
step
162-
}

0 commit comments

Comments
 (0)