Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Apr 9, 2024
1 parent 11db738 commit bd70cef
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub trait FirstContract {
self.tx()
.to(&second_contract_address)
.gas(gas_left)
.raw_call(ManagedBuffer::from(SECOND_CONTRACT_REJECT_ESDT_PAYMENT))
.raw_call(SECOND_CONTRACT_REJECT_ESDT_PAYMENT)
.single_esdt(&expected_token_identifier, 0u64, &esdt_value)
.transfer_execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@
}
}
]
}
}
12 changes: 3 additions & 9 deletions contracts/feature-tests/rust-testing-framework-tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,10 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule {

#[endpoint]
fn call_other_contract_add_async_call(&self, other_sc_address: ManagedAddress, value: BigUint) {
let mut args = ManagedArgBuffer::new();
args.push_arg(&value);

self.tx()
.to(&other_sc_address)
.raw_call("call")
.arguments_raw(args)
.raw_call("add")
.argument(&value)
.async_call_and_exit();
}

Expand All @@ -215,15 +212,12 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule {

#[endpoint]
fn execute_on_dest_add_value(&self, other_sc_address: ManagedAddress, value: BigUint) {
let mut args = ManagedArgBuffer::new();
args.push_arg(value);

let gas_left = self.blockchain().get_gas_left();
self.tx()
.to(&other_sc_address)
.gas(gas_left)
.raw_call("addValue")
.arguments_raw(args)
.argument(&value)
.sync_call();
}

Expand Down
132 changes: 24 additions & 108 deletions framework/base/src/types/interaction/tx_exec/tx_exec_upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
api::CallTypeApi,
contract_base::SendRawWrapper,
proxy_imports::TxToSpecified,
tuple_util::NestedTupleFlatten,
types::{
Code, CodeMetadata, DeployRawResult, FromSource, ManagedAddress, ManagedBuffer, ManagedVec,
Expand Down Expand Up @@ -79,100 +80,11 @@ where
}
}

impl<Api, Payment, Gas, FromSourceValue, RH>
Tx<
TxScEnv<Api>,
(),
&ManagedAddress<Api>,
Payment,
Gas,
UpgradeCall<TxScEnv<Api>, FromSource<FromSourceValue>>,
RH,
>
where
Api: CallTypeApi,
Payment: TxPaymentEgldOnly<TxScEnv<Api>>,
Gas: TxGas<TxScEnv<Api>>,
FromSourceValue: TxFromSourceValue<TxScEnv<Api>>,
RH: TxEmptyResultHandler<TxScEnv<Api>>,
{
/// Launches the upgrade from source async call.
///
/// TODO: change return type to `!`.
pub fn upgrade_async_call_and_exit(self) {
let gas = self.gas.explicit_or_gas_left(&self.env);
self.payment.with_egld_value(&self.env, |egld_value| {
SendRawWrapper::<Api>::new().upgrade_from_source_contract(
self.to,
gas,
egld_value,
&self.data.code_source.0.into_value(&self.env),
self.data.code_metadata,
&self.data.arg_buffer,
);
});
}
}

impl<Api, Payment, Gas, RH>
Tx<TxScEnv<Api>, (), ManagedAddress<Api>, Payment, Gas, UpgradeCall<TxScEnv<Api>, ()>, RH>
where
Api: CallTypeApi,
Payment: TxPaymentEgldOnly<TxScEnv<Api>>,
Gas: TxGas<TxScEnv<Api>>,
RH: TxEmptyResultHandler<TxScEnv<Api>>,
{
/// Backwards compatibility, immitates the old API.
///
/// Note that the data type (the `UpgradeCall`) doesn't have the code set.
/// This is because the old API was passing it as paramter, so we use it from the `code` argument.
///
/// Also note that the code metadata is taken from the `code_metadata` argument.
/// If another one was previously set in the `Tx` object, that one will be ignored.
pub fn upgrade_contract(self, code: &ManagedBuffer<Api>, code_metadata: CodeMetadata) {
let gas = self.gas.explicit_or_gas_left(&self.env);
self.payment.with_egld_value(&self.env, |egld_value| {
SendRawWrapper::<Api>::new().upgrade_contract(
&self.to,
gas,
egld_value,
code,
code_metadata,
&self.data.arg_buffer,
);
});
}

/// Backwards compatibility, immitates the old API.
///
/// Note that the data type (the `UpgradeCall`) doesn't have the code set.
/// This is because the old API was passing it as paramter, so we use it from the `code` argument.
///
/// Also note that the code metadata is taken from the `code_metadata` argument.
/// If another one was previously set in the `Tx` object, that one will be ignored.
pub fn upgrade_from_source(
self,
source_address: &ManagedAddress<Api>,
code_metadata: CodeMetadata,
) {
let gas = self.gas.explicit_or_gas_left(&self.env);
self.payment.with_egld_value(&self.env, |egld_value| {
SendRawWrapper::<Api>::new().upgrade_from_source_contract(
&self.to,
gas,
egld_value,
source_address,
code_metadata,
&self.data.arg_buffer,
);
});
}
}

impl<Api, Payment, Gas, RH>
Tx<TxScEnv<Api>, (), &ManagedAddress<Api>, Payment, Gas, UpgradeCall<TxScEnv<Api>, ()>, RH>
impl<Api, To, Payment, Gas, RH>
Tx<TxScEnv<Api>, (), To, Payment, Gas, UpgradeCall<TxScEnv<Api>, ()>, RH>
where
Api: CallTypeApi,
To: TxToSpecified<TxScEnv<Api>>,
Payment: TxPaymentEgldOnly<TxScEnv<Api>>,
Gas: TxGas<TxScEnv<Api>>,
RH: TxEmptyResultHandler<TxScEnv<Api>>,
Expand All @@ -187,14 +99,16 @@ where
pub fn upgrade_contract(self, code: &ManagedBuffer<Api>, code_metadata: CodeMetadata) {
let gas = self.gas.explicit_or_gas_left(&self.env);
self.payment.with_egld_value(&self.env, |egld_value| {
SendRawWrapper::<Api>::new().upgrade_contract(
self.to,
gas,
egld_value,
code,
code_metadata,
&self.data.arg_buffer,
);
self.to.with_value_ref(&self.env, |to| {
SendRawWrapper::<Api>::new().upgrade_contract(
to,
gas,
egld_value,
code,
code_metadata,
&self.data.arg_buffer,
);
});
});
}

Expand All @@ -212,14 +126,16 @@ where
) {
let gas = self.gas.explicit_or_gas_left(&self.env);
self.payment.with_egld_value(&self.env, |egld_value| {
SendRawWrapper::<Api>::new().upgrade_from_source_contract(
self.to,
gas,
egld_value,
source_address,
code_metadata,
&self.data.arg_buffer,
);
self.to.with_value_ref(&self.env, |to| {
SendRawWrapper::<Api>::new().upgrade_from_source_contract(
to,
gas,
egld_value,
source_address,
code_metadata,
&self.data.arg_buffer,
);
});
});
}
}

0 comments on commit bd70cef

Please sign in to comment.