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

[E2E alternative backend]: Backend traits #1857

Merged
merged 24 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7ae8ac5
Introduce new module for the trait. Rename `client` module
pmikolajczyk41 Jul 25, 2023
02c32d9
`exec_upload` should be a private method
pmikolajczyk41 Jul 25, 2023
7902e6d
Divide interface into general-chain and contracts-specific
pmikolajczyk41 Jul 25, 2023
420afe6
Actor type
pmikolajczyk41 Jul 26, 2023
f37f752
Merge remote-tracking branch 'origin/master' into pmikolajczyk41/back…
pmikolajczyk41 Jul 26, 2023
37828b6
Problems with Send/Sync
pmikolajczyk41 Jul 26, 2023
e605a0e
Seems that adding everywhere Send/Sync requirement solves :shrug:
pmikolajczyk41 Jul 26, 2023
b13556e
Adjust tests
pmikolajczyk41 Jul 26, 2023
0361c45
Fmt
pmikolajczyk41 Jul 26, 2023
1af5856
Fmt
pmikolajczyk41 Jul 26, 2023
3a5d827
Fmt
pmikolajczyk41 Jul 26, 2023
6e9e043
Merge remote-tracking branch 'origin/master' into pmikolajczyk41/back…
pmikolajczyk41 Jul 27, 2023
08c496c
Yanked contract-build version
pmikolajczyk41 Jul 27, 2023
7b831e8
Leftovers from merge
pmikolajczyk41 Jul 27, 2023
9e40e91
Move instantiate*
pmikolajczyk41 Jul 27, 2023
3749d18
Upload
pmikolajczyk41 Jul 27, 2023
4d96eb4
Trait completed
pmikolajczyk41 Jul 27, 2023
e56a4a5
Implement E2EBackend, but it requires the whole litany of trait bound…
pmikolajczyk41 Jul 27, 2023
80d9d6b
Add import to tests
pmikolajczyk41 Jul 27, 2023
87e4e7d
Fmt
pmikolajczyk41 Jul 27, 2023
448b78a
New contract-build
pmikolajczyk41 Jul 27, 2023
071f5b1
Merge remote-tracking branch 'origin/master' into pmikolajczyk41/back…
pmikolajczyk41 Jul 28, 2023
4ac1488
Add license to recently added files
pmikolajczyk41 Jul 28, 2023
cff7fa4
Don't import ChainBackend if not needed
pmikolajczyk41 Jul 29, 2023
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ array-init = { version = "2.0", default-features = false }
blake2 = { version = "0.10" }
cargo_metadata = { version = "0.17.0" }
cfg-if = { version = "1.0" }
contract-build = { version = "3.1.0" }
contract-build = { version = "4.0.0-alpha" }
derive_more = { version = "0.99.17", default-features = false }
either = { version = "1.5", default-features = false }
funty = { version = "2.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn build_contract(path_to_cargo_toml: &str) -> String {
output_type: OutputType::HumanReadable,
skip_wasm_validation: false,
target: Target::Wasm,
..ExecuteArgs::default()
..Default::default()
};

match contract_build::execute(args) {
Expand Down
141 changes: 141 additions & 0 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
use crate::{
builders::CreateBuilderPartial,
CallBuilderFinal,
CallDryRunResult,
CallResult,
InstantiationResult,
UploadResult,
};
use ink_env::Environment;
use jsonrpsee::core::async_trait;
use pallet_contracts_primitives::ContractInstantiateResult;
use subxt::dynamic::Value;

/// Full E2E testing backend: combines general chain API and contract-specific operations.
#[async_trait]
pub trait E2EBackend<E: Environment>: ChainBackend + ContractsBackend<E> {}

/// General chain operations useful in contract testing.
#[async_trait]
pub trait ChainBackend {
/// Abstract type representing the entity that interacts with the chain.
type Actor: Send;
/// Identifier type for an actor.
type ActorId;
/// Balance type.
type Balance: Send;
/// Error type.
type Error;
/// Event log type.
type EventLog;

/// Generate a new actor's credentials and fund it with the given amount from the
/// `sender` actor.
async fn create_and_fund_account(
&mut self,
origin: &Self::Actor,
amount: Self::Balance,
) -> Self::Actor;

/// Returns the balance of `actor`.
async fn balance(&self, actor: Self::ActorId) -> Result<Self::Balance, Self::Error>;

/// Executes a runtime call `call_name` for the `pallet_name`.
/// The `call_data` is a `Vec<Value>`.
///
/// Note:
/// - `pallet_name` must be in camel case, for example `Balances`.
/// - `call_name` must be snake case, for example `force_transfer`.
/// - `call_data` is a `Vec<subxt::dynamic::Value>` that holds a representation of
/// some value.
///
/// Returns when the transaction is included in a block. The return value contains all
/// events that are associated with this transaction.
async fn runtime_call<'a>(
&mut self,
actor: &Self::Actor,
pallet_name: &'a str,
call_name: &'a str,
call_data: Vec<Value>,
) -> Result<Self::EventLog, Self::Error>;
}

/// Contract-specific operations.
#[async_trait]
pub trait ContractsBackend<E: Environment> {
/// Abstract type representing the entity that interacts with the chain.
type Actor;
/// Error type.
type Error;
/// Event log type.
type EventLog;

/// The function subsequently uploads and instantiates an instance of the contract.
///
/// This function extracts the metadata of the contract at the file path
/// `target/ink/$contract_name.contract`.
///
/// Calling this function multiple times should be idempotent, the contract is
/// newly instantiated each time using a unique salt. No existing contract
/// instance is reused!
async fn instantiate<Contract, Args: Send + scale::Encode, R>(
&mut self,
contract_name: &str,
caller: &Self::Actor,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiationResult<E, Self::EventLog>, Self::Error>;

/// Dry run contract instantiation.
async fn instantiate_dry_run<Contract, Args: Send + scale::Encode, R>(
&mut self,
contract_name: &str,
caller: &Self::Actor,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> ContractInstantiateResult<E::AccountId, E::Balance, ()>;

/// The function subsequently uploads and instantiates an instance of the contract.
///
/// This function extracts the Wasm of the contract for the specified contract.
///
/// Calling this function multiple times should be idempotent, the contract is
/// newly instantiated each time using a unique salt. No existing contract
/// instance is reused!
async fn upload(
&mut self,
contract_name: &str,
caller: &Self::Actor,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<E, Self::EventLog>, Self::Error>;

/// Executes a `call` for the contract at `account_id`.
///
/// Returns when the transaction is included in a block. The return value
/// contains all events that are associated with this transaction.
async fn call<Args: Sync + scale::Encode, RetType: Send + scale::Decode>(
&mut self,
caller: &Self::Actor,
message: &CallBuilderFinal<E, Args, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> Result<CallResult<E, RetType, Self::EventLog>, Self::Error>
where
CallBuilderFinal<E, Args, RetType>: Clone;

/// Executes a dry-run `call`.
///
/// Returns the result of the dry run, together with the decoded return value of the
/// invoked message.
async fn call_dry_run<Args: Sync + scale::Encode, RetType: Send + scale::Decode>(
&mut self,
caller: &Self::Actor,
message: &CallBuilderFinal<E, Args, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> CallDryRunResult<E, RetType>
where
CallBuilderFinal<E, Args, RetType>: Clone;
}
16 changes: 11 additions & 5 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
html_favicon_url = "https://use.ink/crate-docs/favicon.png"
)]

mod backend;
mod builders;
mod client;
mod contract_results;
mod error;
pub mod events;
mod node_proc;
mod subxt_client;
mod xts;

pub use client::{
CallBuilderFinal,
Client,
Error,
pub use backend::{
ChainBackend,
ContractsBackend,
E2EBackend,
};
pub use contract_results::{
CallDryRunResult,
Expand All @@ -46,6 +47,11 @@ pub use node_proc::{
pub use sp_core::H256;
pub use sp_keyring::AccountKeyring;
pub use subxt;
pub use subxt_client::{
CallBuilderFinal,
Client,
Error,
};
pub use subxt_signer::sr25519::{
self,
dev::*,
Expand Down
Loading