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] Call builders and extra gas margin option #1917

Merged
merged 52 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bc27b10
add extra arg to specify extra gas portion
Sep 16, 2023
313d351
changelog
Sep 16, 2023
2578e5a
fmt
Sep 16, 2023
116caf6
fix the test
Sep 18, 2023
024405b
add call builders
Sep 25, 2023
e7b9c0e
Update changelog
Sep 25, 2023
da053c6
fix spelling
Sep 25, 2023
e872567
introduce bare calls alongside builder api
Sep 27, 2023
9df632f
add docs
Sep 27, 2023
86fab73
add upload builder
Sep 27, 2023
9e7814e
remove async in upload
Sep 27, 2023
2b3260f
ignore doctest
Sep 27, 2023
3bef64c
update integration tests
Sep 27, 2023
ad43cce
`submit_dry_run()` -> `dry_run()`
Sep 27, 2023
5109e64
format tests
Sep 27, 2023
9e5b311
fixes
Sep 27, 2023
7e7a02e
fmt
Sep 27, 2023
8e8713f
another fmt
Sep 27, 2023
8cdf350
Make env cloneable and take constructor as mut ref
Sep 28, 2023
505e582
one more fix
Sep 28, 2023
48e9543
remove unnecessary trait bound
Sep 28, 2023
93221db
remove more trait bounds
Sep 28, 2023
a8ccedf
fix tests and fmt
Sep 28, 2023
3c600b4
fix tests and tweak drink backend
Sep 28, 2023
0c076f4
move margin call to separate trait
Sep 28, 2023
3d3e04d
update docs
Sep 28, 2023
f1a3228
add BuilderClient as supertrait of E2EBackend and fix docs
Sep 28, 2023
bb332ad
fix more tests and docs
Sep 28, 2023
975762a
one last doc fix
Sep 28, 2023
714d7d8
Merge branch 'master' into gn/extra_gas_config
Sep 28, 2023
2855db2
UI tests
Sep 28, 2023
c091243
Remove unecessary trait bounds
Sep 29, 2023
5f11cbc
remove move unecessary trait bounds
Sep 29, 2023
62b1608
one more missing trait
Sep 29, 2023
d96fed4
Revert "UI tests"
Sep 29, 2023
61a0fa0
keep Clone with custom env in UI tests
Sep 29, 2023
6af9c46
remove duplicate derive
Sep 29, 2023
02bb3ec
add proper dry-run in drink
Oct 3, 2023
2d62be8
reformat the trait and add gas limit option
Oct 3, 2023
6be1cdc
fmt example
Oct 3, 2023
8036919
update docs
Oct 3, 2023
1bebfc9
Merge branch 'master' into gn/extra_gas_config
Oct 3, 2023
d7c6be4
fix CI by adding necessary trait bounds
Oct 4, 2023
7d6aafa
fix CI
Oct 4, 2023
3d8f9ba
Update integration-tests/call-builder-return-value/lib.rs
Oct 7, 2023
d3560c3
Merge branch 'master' into gn/extra_gas_config
Oct 7, 2023
7542d5a
Suggestions for removing code duplication in #1917 (#1938)
ascjones Oct 17, 2023
aef2dcd
add dummy error struct to drink
Oct 17, 2023
c5b78de
Merge branch 'master' into gn/extra_gas_config
Oct 17, 2023
c649b58
remove default
Oct 17, 2023
c5c1de5
pass args to instantiate dry run correctly
Oct 18, 2023
ccac9ff
add license files
Oct 18, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

## Changed
- [E2E] E2E call builders and extra gas margin option - [#1917](https://github.com/paritytech/ink/pull/1917)
- Make `set_code_hash` generic - [#1906](https://github.com/paritytech/ink/pull/1906)

## Version 5.0.0-alpha
Expand Down
150 changes: 140 additions & 10 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@

use super::Keypair;
use crate::{
backend_calls::{
InstantiateBuilder,
UploadBuilder,
},
builders::CreateBuilderPartial,
contract_results::BareInstantiationResult,
CallBuilder,
CallBuilderFinal,
CallDryRunResult,
CallResult,
InstantiationResult,
UploadResult,
};
Expand All @@ -27,6 +32,7 @@ use ink_env::{
};
use jsonrpsee::core::async_trait;
use pallet_contracts_primitives::ContractInstantiateResult;
use sp_weights::Weight;
use subxt::dynamic::Value;

/// Full E2E testing backend: combines general chain API and contract-specific operations.
Expand All @@ -42,7 +48,7 @@ pub trait ChainBackend {
/// Account type.
type AccountId;
/// Balance type.
type Balance: Send;
type Balance: Send + From<u32>;
pmikolajczyk41 marked this conversation as resolved.
Show resolved Hide resolved
/// Error type.
type Error;
/// Event log type.
Expand Down Expand Up @@ -93,6 +99,60 @@ pub trait ContractsBackend<E: Environment> {
/// Event log type.
type EventLog;

/// Start building an instantiate call using a builder pattern.
///
/// # Example
///
/// ```ignore
/// // Constructor method
/// let constructor = FlipperRef::new(false);
/// let contract = client
/// .instantiate("flipper", &ink_e2e::alice(), constructor)
/// // Optional arguments
/// // Send 100 units with the call.
/// .value(100)
/// // Add 10% margin to the gas limit
/// .extra_gas_portion(10)
/// .storage_deposit_limit(100)
/// // Submit the call for on-chain execution.
/// .submit()
/// .await
/// .expect("instantiate failed");
/// ```
fn instantiate<'a, Contract, Args: Send + Clone + scale::Encode + Sync, R>(
&'a mut self,
contract_name: &'a str,
caller: &'a Keypair,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering... maybe alice() should be moved to default as well (similarly to value, storage deposit and margin)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, the caller should be specified explicitly. I don't want to hide this information from the developer per se

constructor: CreateBuilderPartial<E, Contract, Args, R>,
) -> InstantiateBuilder<'a, E, Contract, Args, R, Self>
where
Self: std::marker::Sized,
{
InstantiateBuilder::new(self, caller, contract_name, constructor)
}

/// Submits an instantiate call with a gas margin.
///
/// Intended to be used as part of builder API.
async fn instantiate_with_gas_margin<
Contract,
Args: Send + scale::Encode + Clone,
R,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
margin: Option<u64>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiationResult<E, Self::EventLog>, Self::Error>;

/// Bare instantiate call. This function does perform a dry-run,
/// and user is expected to provide the gas limit.
///
/// Use it when you want to have a more precise control over submitting extrinsic.
///
/// The function subsequently uploads and instantiates an instance of the contract.
///
/// This function extracts the metadata of the contract at the file path
Expand All @@ -101,17 +161,22 @@ pub trait ContractsBackend<E: Environment> {
/// 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>(
async fn bare_instantiate<Contract, Args: Send + scale::Encode + Clone, R>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiationResult<E, Self::EventLog>, Self::Error>;
) -> Result<BareInstantiationResult<E, Self::EventLog>, Self::Error>;

/// Dry run contract instantiation.
async fn instantiate_dry_run<Contract, Args: Send + scale::Encode, R>(
async fn bare_instantiate_dry_run<
Contract,
Args: Send + Sync + scale::Encode + Clone,
R,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
Expand All @@ -120,39 +185,104 @@ pub trait ContractsBackend<E: Environment> {
storage_deposit_limit: Option<E::Balance>,
) -> ContractInstantiateResult<E::AccountId, E::Balance, ()>;

/// Start building an upload call.
/// # Example
///
/// ```ignore
/// let contract = client
/// .upload("flipper", &ink_e2e::alice())
/// // Optional arguments
/// .storage_deposit_limit(100)
/// // Submit the call for on-chain execution.
/// .submit()
/// .await
/// .expect("upload failed");
/// ```
fn upload<'a>(
&'a mut self,
contract_name: &'a str,
caller: &'a Keypair,
) -> UploadBuilder<E, Self>
where
Self: Sized,
{
UploadBuilder::new(self, contract_name, caller)
}

/// The function subsequently uploads and instantiates an instance of the contract.
pmikolajczyk41 marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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(
async fn bare_upload(
&mut self,
contract_name: &str,
caller: &Keypair,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<E, Self::EventLog>, Self::Error>;

/// Executes a `call` for the contract at `account_id`.
/// Start building a call using a builder pattern.
///
/// # Example
///
/// ```ignore
/// // Message method
/// let get = call.get();
/// let get_res = client
/// .call(&ink_e2e::bob(), &get)
/// // Optional arguments
/// // Send 100 units with the call.
/// .value(100)
/// // Add 10% margin to the gas limit
/// .extra_gas_portion(10)
/// .storage_deposit_limit(100)
/// // Submit the call for on-chain execution.
/// .submit()
/// .await
/// .expect("instantiate failed");
/// ```
fn call<'a, Args: Sync + scale::Encode + Clone, RetType: Send + scale::Decode>(
&'a mut self,
caller: &'a Keypair,
message: &'a CallBuilderFinal<E, Args, RetType>,
) -> CallBuilder<'a, E, Args, RetType, Self>
where
Self: std::marker::Sized,
{
CallBuilder::new(self, caller, message)
}

/// Executes a bare `call` for the contract at `account_id`. This function does
/// perform a dry-run, and user is expected to provide the gas limit.
///
/// Use it when you want to have a more precise control over submitting extrinsic.
///
/// 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>(
async fn bare_call<
Args: Sync + scale::Encode + Clone,
RetType: Send + scale::Decode,
>(
&mut self,
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: Option<E::Balance>,
) -> Result<CallResult<E, RetType, Self::EventLog>, Self::Error>
) -> Result<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>(
async fn bare_call_dry_run<
Args: Sync + scale::Encode + Clone,
RetType: Send + scale::Decode,
>(
&mut self,
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType>,
Expand Down
Loading