Skip to content
Draft
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
40 changes: 24 additions & 16 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use ink_env::{
EncodeArgsWith,
},
};
use ink_primitives::H160;
use ink_primitives::{
H160,
U256,
};
use ink_revive_types::evm::CallTrace;
use jsonrpsee::core::async_trait;
use sp_weights::Weight;
Expand Down Expand Up @@ -65,14 +68,14 @@ pub trait ChainBackend {
async fn create_and_fund_account(
&mut self,
origin: &Keypair,
amount: Self::Balance,
amount: U256,
) -> Keypair;

/// Returns the free balance of `account`.
async fn free_balance(
&mut self,
account: Self::AccountId,
) -> Result<Self::Balance, Self::Error>;
) -> Result<U256, Self::Error>;

/// Executes a runtime call `call_name` for the `pallet_name`.
/// The `call_data` is a `Vec<Value>`.
Expand Down Expand Up @@ -104,8 +107,13 @@ pub trait ChainBackend {
&mut self,
origin: &Keypair,
dest: Self::AccountId,
value: Self::Balance,
value: U256,
) -> Result<(), Self::Error>;

/// Get the balance with EVM decimals of the given `address`.
///
/// Returns the spendable balance excluding the existential deposit.
async fn evm_balance(&mut self, address: H160) -> U256;
}

/// Contract-specific operations.
Expand Down Expand Up @@ -256,9 +264,9 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
&mut self,
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType, Abi>,
value: E::Balance,
value: U256,
gas_limit: Weight,
storage_deposit_limit: E::Balance,
storage_deposit_limit: U256,
) -> Result<(Self::EventLog, Option<CallTrace>), Self::Error>
where
CallBuilderFinal<E, Args, RetType, Abi>: Clone;
Expand All @@ -280,8 +288,8 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
&mut self,
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType, Abi>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
value: U256,
storage_deposit_limit: Option<U256>,
) -> Result<CallDryRunResult<E, RetType, Abi>, Self::Error>
where
CallBuilderFinal<E, Args, RetType, Abi>: Clone;
Expand Down Expand Up @@ -332,8 +340,8 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
&mut self,
contract_name: &str,
caller: &Keypair,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<E, Self::EventLog>, Self::Error>;
storage_deposit_limit: Option<U256>,
) -> Result<UploadResult<Self::EventLog>, Self::Error>;

/// Removes the code of the contract at `code_hash`.
async fn bare_remove_code(
Expand Down Expand Up @@ -365,9 +373,9 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
code: Vec<u8>,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
value: U256,
gas_limit: Weight,
storage_deposit_limit: E::Balance,
storage_deposit_limit: U256,
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error>;

async fn raw_instantiate(
Expand All @@ -394,9 +402,9 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
signer: &Keypair,
contract_name: &str,
data: Vec<u8>,
value: E::Balance,
value: U256,
gas_limit: Weight,
storage_deposit_limit: E::Balance,
storage_deposit_limit: U256,
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error>;

/// Dry run contract instantiation.
Expand All @@ -415,8 +423,8 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
contract_name: &str,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
value: U256,
storage_deposit_limit: Option<U256>,
) -> Result<InstantiateDryRunResult<E, Abi>, Self::Error>;

/// Checks if `caller` was already mapped in `pallet-revive`. If not, it will do so
Expand Down
46 changes: 20 additions & 26 deletions crates/e2e/src/backend_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ink_env::{
EncodeArgsWith,
},
};
use ink_primitives::U256;
use sp_weights::Weight;

use super::{
Expand Down Expand Up @@ -51,10 +52,10 @@ where
client: &'a mut B,
caller: &'a Keypair,
message: &'a CallBuilderFinal<E, Args, RetType, Abi>,
value: E::Balance,
value: U256,
extra_gas_portion: Option<u64>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<E::Balance>,
storage_deposit_limit: Option<U256>,
}

impl<'a, E, Args, RetType, B, Abi> CallBuilder<'a, E, Args, RetType, B, Abi>
Expand All @@ -70,23 +71,20 @@ where
client: &'a mut B,
caller: &'a Keypair,
message: &'a CallBuilderFinal<E, Args, RetType, Abi>,
) -> CallBuilder<'a, E, Args, RetType, B, Abi>
where
E::Balance: From<u32>,
{
) -> CallBuilder<'a, E, Args, RetType, B, Abi> {
Self {
client,
caller,
message,
value: 0u32.into(),
value: U256::zero(),
extra_gas_portion: None,
gas_limit: None,
storage_deposit_limit: None,
}
}

/// Provide value with a call
pub fn value(&mut self, value: E::Balance) -> &mut Self {
pub fn value(&mut self, value: U256) -> &mut Self {
self.value = value;
self
}
Expand Down Expand Up @@ -124,10 +122,7 @@ where
}

/// Specify the max amount of funds that can be charged for storage.
pub fn storage_deposit_limit(
&mut self,
storage_deposit_limit: E::Balance,
) -> &mut Self {
pub fn storage_deposit_limit(&mut self, storage_deposit_limit: U256) -> &mut Self {
self.storage_deposit_limit = Some(storage_deposit_limit);
self
}
Expand Down Expand Up @@ -168,7 +163,7 @@ where
self.message,
self.value,
gas_limit,
dry_run.exec_result.storage_deposit.charge_or_zero(),
E::native_to_eth(dry_run.exec_result.storage_deposit.charge_or_zero()),
)
.await?;

Expand Down Expand Up @@ -207,10 +202,10 @@ where
caller: &'a Keypair,
contract_name: &'a str,
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
value: U256,
extra_gas_portion: Option<u64>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<E::Balance>,
storage_deposit_limit: Option<U256>,
}

impl<'a, E, Contract, Args, R, B, Abi>
Expand All @@ -228,24 +223,21 @@ where
caller: &'a Keypair,
contract_name: &'a str,
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
) -> InstantiateBuilder<'a, E, Contract, Args, R, B, Abi>
where
E::Balance: From<u32>,
{
) -> InstantiateBuilder<'a, E, Contract, Args, R, B, Abi> {
Self {
client,
caller,
contract_name,
constructor,
value: 0u32.into(),
value: U256::zero(),
extra_gas_portion: None,
gas_limit: None,
storage_deposit_limit: None,
}
}

/// Provide value with a call
pub fn value(&mut self, value: E::Balance) -> &mut Self {
pub fn value(&mut self, value: U256) -> &mut Self {
self.value = value;
self
}
Expand Down Expand Up @@ -287,7 +279,7 @@ where
/// *Important*: `None` means charging the maximum!
pub fn storage_deposit_limit(
&mut self,
storage_deposit_limit: Option<E::Balance>,
storage_deposit_limit: Option<U256>,
) -> &mut Self {
self.storage_deposit_limit = storage_deposit_limit;
self
Expand Down Expand Up @@ -329,7 +321,7 @@ where
self.constructor,
self.value,
gas_limit,
dry_run.contract_result.storage_deposit.charge_or_zero(),
E::native_to_eth(dry_run.contract_result.storage_deposit.charge_or_zero()),
)
.await?;

Expand Down Expand Up @@ -366,7 +358,8 @@ where
client: &'a mut B,
contract_name: &'a str,
caller: &'a Keypair,
storage_deposit_limit: Option<E::Balance>,
storage_deposit_limit: Option<U256>,
_phantom: PhantomData<E>,
}

impl<'a, E, B> UploadBuilder<'a, E, B>
Expand All @@ -381,20 +374,21 @@ where
contract_name,
caller,
storage_deposit_limit: None,
_phantom: Default::default(),
}
}

/// Specify the max amount of funds that can be charged for storage.
pub fn storage_deposit_limit(
&mut self,
storage_deposit_limit: Option<E::Balance>,
storage_deposit_limit: Option<U256>,
) -> &mut Self {
self.storage_deposit_limit = storage_deposit_limit;
self
}

/// Execute the upload.
pub async fn submit(&mut self) -> Result<UploadResult<E, B::EventLog>, B::Error> {
pub async fn submit(&mut self) -> Result<UploadResult<B::EventLog>, B::Error> {
B::bare_upload(
self.client,
self.contract_name,
Expand Down
21 changes: 2 additions & 19 deletions crates/e2e/src/contract_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,32 +194,15 @@ where
}

/// Result of a contract upload.
pub struct UploadResult<E: Environment, EventLog> {
pub struct UploadResult<EventLog> {
/// The hash with which the contract can be instantiated.
pub code_hash: H256,
/// The result of the dry run, contains debug messages if there were any.
pub dry_run: CodeUploadResult<E::Balance>,
pub dry_run: CodeUploadResult,
/// Events that happened with the contract instantiation.
pub events: EventLog,
}

/// We implement a custom `Debug` here, to avoid requiring the trait bound `Debug` for
/// `E`.
impl<E: Environment, EventLog> Debug for UploadResult<E, EventLog>
where
E::Balance: Debug,
H256: Debug,
EventLog: Debug,
{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("UploadResult")
.field("code_hash", &self.code_hash)
.field("dry_run", &self.dry_run)
.field("events", &self.events)
.finish()
}
}

/// Result of a contract call.
pub struct CallResult<E: Environment, V, EventLog, Abi> {
/// The result of the dry run, contains debug messages if there were any.
Expand Down
Loading
Loading