Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Marks the `pallet-revive` host function `account_id` stable - [#2578](https://github.com/use-ink/ink/pull/2578)
- Stabilize `is_contract` - [#2654](https://github.com/use-ink/ink/pull/2654)
- Extract `sandbox` from `ink_e2e` into a new `ink_sandbox` crate - [#2659](https://github.com/use-ink/ink/pull/2659)
- Synchronize with `polkadot-sdk/1b1cef306d9ceebf963fd15a04b5c79ee2618bce` ‒ [2675](https://github.com/use-ink/ink/pull/2675)

### Fixed
- Fix decoding of `HostFn::minimum_balance` return value - [#2656](https://github.com/use-ink/ink/pull/2656)
Expand Down
611 changes: 486 additions & 125 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ scale-info = { version = "2.11", default-features = false }
schemars = { version = "0.8" }
secp256k1 = { version = "0.30.0" }
serde = { version = "1.0.215", default-features = false }
serde_json = { version = "1.0.137" }
serde_json = { version = "1.0.145" }
sha2 = { version = "0.10" }
sha3 = { version = "0.10" }
static_assertions = { version = "1.1" }
Expand Down
21 changes: 10 additions & 11 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use ink_env::{
call::utils::DecodeMessageResult,
};
use ink_primitives::{
DepositLimit,
H160,
abi::AbiEncodeWith,
};
Expand Down Expand Up @@ -242,8 +241,8 @@ pub trait ContractsBackend<E: Environment> {

#[async_trait]
pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
/// Executes a bare `call` for the contract at `account_id`. This function does not
/// perform a dry-run, and the user is expected to provide the gas limit.
/// Executes a bare `call` for the contract at `account_id`. This function does
/// _not_ perform a dry-run, and the user is expected to provide the gas limit.
///
/// Use it when you want to have a more precise control over submitting extrinsic.
///
Expand All @@ -259,7 +258,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
message: &CallBuilderFinal<E, Args, RetType, Abi>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
) -> Result<(Self::EventLog, Option<CallTrace>), Self::Error>
where
CallBuilderFinal<E, Args, RetType, Abi>: Clone;
Expand All @@ -282,7 +281,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType, Abi>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<CallDryRunResult<E, RetType, Abi>, Self::Error>
where
CallBuilderFinal<E, Args, RetType, Abi>: Clone;
Expand All @@ -304,7 +303,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
dest: H160,
input_data: Vec<u8>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
signer: &Keypair,
) -> Result<CallDryRunResult<E, RetType, Abi>, Self::Error>;

Expand All @@ -318,7 +317,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
input_data: Vec<u8>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
signer: &Keypair,
) -> Result<(Self::EventLog, Option<CallTrace>), Self::Error>;

Expand Down Expand Up @@ -368,7 +367,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error>;

async fn raw_instantiate(
Expand All @@ -378,7 +377,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
constructor: Vec<u8>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error>;

async fn raw_instantiate_dry_run<Abi: Sync + Clone>(
Expand All @@ -387,7 +386,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
caller: &Keypair,
constructor: Vec<u8>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiateDryRunResult<E, Abi>, Self::Error>;

async fn exec_instantiate(
Expand Down Expand Up @@ -417,7 +416,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiateDryRunResult<E, Abi>, Self::Error>;

/// Checks if `caller` was already mapped in `pallet-revive`. If not, it will do so
Expand Down
26 changes: 10 additions & 16 deletions crates/e2e/src/backend_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ use ink_env::{
Environment,
call::utils::DecodeMessageResult,
};
use ink_primitives::{
DepositLimit,
abi::AbiEncodeWith,
};
use ink_primitives::abi::AbiEncodeWith;
use sp_weights::Weight;

use super::{
InstantiateDryRunResult,
Keypair,
balance_to_deposit_limit,
balance_to_deposit_limit_dry_run,
};
use crate::{
CallBuilderFinal,
Expand Down Expand Up @@ -152,7 +147,7 @@ where
self.caller,
self.message,
self.value,
balance_to_deposit_limit_dry_run::<E>(self.storage_deposit_limit),
self.storage_deposit_limit,
)
.await?;

Expand All @@ -171,8 +166,7 @@ where
self.message,
self.value,
gas_limit,
// todo: the `bare_call` converts this value back, this is unnecessary work
DepositLimit::Balance(dry_run.exec_result.storage_deposit.charge_or_zero()),
dry_run.exec_result.storage_deposit.charge_or_zero(),
)
.await?;

Expand All @@ -193,7 +187,7 @@ where
self.caller,
self.message,
self.value,
balance_to_deposit_limit_dry_run::<E>(self.storage_deposit_limit),
self.storage_deposit_limit,
)
.await
}
Expand All @@ -214,7 +208,7 @@ where
value: E::Balance,
extra_gas_portion: Option<u64>,
gas_limit: Option<Weight>,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
}

impl<'a, E, Contract, Args, R, B, Abi>
Expand Down Expand Up @@ -244,7 +238,7 @@ where
value: 0u32.into(),
extra_gas_portion: None,
gas_limit: None,
storage_deposit_limit: DepositLimit::UnsafeOnlyForDryRun,
storage_deposit_limit: None,
}
}

Expand Down Expand Up @@ -287,9 +281,11 @@ where
}

/// Specify the max amount of funds that can be charged for storage.
///
/// *Important*: `None` means charging the maximum!
pub fn storage_deposit_limit(
&mut self,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
) -> &mut Self {
self.storage_deposit_limit = storage_deposit_limit;
self
Expand Down Expand Up @@ -331,9 +327,7 @@ where
self.constructor,
self.value,
gas_limit,
balance_to_deposit_limit::<E>(Some(
dry_run.contract_result.storage_deposit.charge_or_zero(),
)),
dry_run.contract_result.storage_deposit.charge_or_zero(),
)
.await?;

Expand Down
43 changes: 0 additions & 43 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ use ink_env::{
};
use ink_primitives::{
Address,
DepositLimit,
H256,
types::AccountIdMapper,
};
Expand Down Expand Up @@ -207,45 +206,3 @@ where
{
<<Contract as ContractCallBuilder>::Type<Abi> as FromAddr>::from_addr(acc_id)
}

/// Transforms `Option<<E as Environment>::Balance>>` into `DepositLimit`.
///
/// This function must only be used for dry-runs, a `None` will
/// become an unrestricted deposit limit (`DepositLimit::UnsafeOnlyForDryRun`).
fn balance_to_deposit_limit_dry_run<E: Environment>(
b: Option<<E as Environment>::Balance>,
) -> DepositLimit<<E as Environment>::Balance> {
match b {
Some(v) => DepositLimit::Balance(v),
None => DepositLimit::UnsafeOnlyForDryRun,
}
}

/// Transforms `Option<<E as Environment>::Balance>>` into `DepositLimit`.
/// This function must be used for submitting extrinsics on-chain.
///
/// Panics if `limit` is `None`. Make sure to execute a dry-run
/// beforehand and use the `storage_deposit_limit` result of it here.
fn balance_to_deposit_limit<E: Environment>(
limit: Option<<E as Environment>::Balance>,
) -> DepositLimit<<E as Environment>::Balance> {
match limit {
Some(val) => DepositLimit::Balance(val),
None => panic!("Deposit limit must be specified for on-chain submissions."),
}
}

/// Transforms `DepositLimit<<E as Environment>::Balance>` into `<E as
/// Environment>::Balance>`.
///
/// Panics if `limit` is unrestricted (`DepositLimit::UnsafeOnlyForDryRun`).
fn deposit_limit_to_balance<E: Environment>(
limit: DepositLimit<<E as Environment>::Balance>,
) -> <E as Environment>::Balance {
match limit {
DepositLimit::Balance(val) => val,
DepositLimit::UnsafeOnlyForDryRun => {
panic!("Unrestricted deposit limit not allowed for balance conversion!")
}
}
}
38 changes: 13 additions & 25 deletions crates/e2e/src/subxt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use super::{
CreateBuilderPartial,
constructor_exec_input,
},
deposit_limit_to_balance,
events::{
CodeStoredEvent,
EventWithTopics,
Expand Down Expand Up @@ -69,10 +68,7 @@ use ink_env::{
},
},
};
use ink_primitives::{
DepositLimit,
abi::AbiEncodeWith,
};
use ink_primitives::abi::AbiEncodeWith;
use ink_revive_types::evm::CallTrace;
use jsonrpsee::core::async_trait;
use scale::{
Expand Down Expand Up @@ -530,7 +526,7 @@ where
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error> {
let data = constructor_exec_input(constructor.clone());
let ret = self
Expand All @@ -546,9 +542,8 @@ where
constructor: Vec<u8>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error> {
let storage_deposit_limit = deposit_limit_to_balance::<E>(storage_deposit_limit);
let (events, trace) = self
.api
.instantiate_with_code(
Expand Down Expand Up @@ -618,15 +613,8 @@ where
storage_deposit_limit: E::Balance,
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error> {
let code = self.contracts.load_code(contract_name);
self.raw_instantiate(
code,
signer,
data,
value,
gas_limit,
DepositLimit::Balance(storage_deposit_limit),
)
.await
self.raw_instantiate(code, signer, data, value, gas_limit, storage_deposit_limit)
.await
}

/// Important: For an uncomplicated UX of the E2E testing environment we
Expand All @@ -644,7 +632,7 @@ where
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiateDryRunResult<E, Abi>, Self::Error> {
let code = self.contracts.load_code(contract_name);
let data = constructor_exec_input(constructor.clone());
Expand All @@ -662,7 +650,7 @@ where
caller: &Keypair,
data: Vec<u8>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiateDryRunResult<E, Abi>, Self::Error> {
// There's a side effect here!
let _ = self.map_account(caller).await;
Expand Down Expand Up @@ -749,7 +737,7 @@ where
message: &CallBuilderFinal<E, Args, RetType, Abi>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
) -> Result<(Self::EventLog, Option<CallTrace>), Self::Error>
where
CallBuilderFinal<E, Args, RetType, Abi>: Clone,
Expand All @@ -774,7 +762,7 @@ where
input_data: Vec<u8>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: E::Balance,
signer: &Keypair,
) -> Result<(Self::EventLog, Option<CallTrace>), Self::Error> {
let (tx_events, trace) = self
Expand All @@ -783,7 +771,7 @@ where
dest,
value,
gas_limit.into(),
deposit_limit_to_balance::<E>(storage_deposit_limit),
storage_deposit_limit,
input_data,
signer,
)
Expand All @@ -801,7 +789,7 @@ where
.map_err(|e| Error::Decoding(e.to_string()))?;
log_error(&format!(
"Attempt to stringify returned data: {:?}",
String::from_utf8_lossy(&trace.clone().unwrap().output[..])
String::from_utf8_lossy(&trace.clone().unwrap().output.0[..])
));
log_error(&format!(
"extrinsic for `raw_call` failed: {dispatch_error} {trace:?}"
Expand All @@ -828,7 +816,7 @@ where
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType, Abi>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<CallDryRunResult<E, RetType, Abi>, Self::Error>
where
CallBuilderFinal<E, Args, RetType, Abi>: Clone,
Expand Down Expand Up @@ -872,7 +860,7 @@ where
dest: H160,
input_data: Vec<u8>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
storage_deposit_limit: Option<E::Balance>,
signer: &Keypair,
) -> Result<CallDryRunResult<E, RetType, Abi>, Self::Error> {
let (exec_result, trace) = self
Expand Down
Loading
Loading