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

delegate_dependency api calls #2076

Merged
merged 33 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0675a45
*WIP* add `delegate_dependency` env api calls
ascjones Jan 26, 2024
6d491b4
Merge branch 'master' into aj/delegate-dependency
ascjones Feb 5, 2024
8a0d4b5
Merge branch 'master' into aj/delegate-dependency
ascjones Feb 7, 2024
37370be
Merge branch 'master' into aj/delegate-dependency
ascjones Feb 8, 2024
f441c6a
Merge branch 'master' into aj/delegate-dependency
ascjones Feb 8, 2024
a4bb790
Updated return types and moved docs
ascjones Feb 8, 2024
64afb16
Merge branch 'master' into aj/delegate-dependency
ascjones Feb 9, 2024
c0084dd
unused imports
ascjones Feb 9, 2024
9fc6820
Lazy delegate to
ascjones Feb 9, 2024
5086e0a
Allow deprecated
ascjones Feb 9, 2024
6e358da
Initialise delegate_to hash in constructor
ascjones Feb 9, 2024
b5bede6
Test example, adding `remove_code` extrinsic to e2e
ascjones Feb 9, 2024
d864abb
Docs
ascjones Feb 9, 2024
60b7662
CHANGELOG.md
ascjones Feb 9, 2024
e928284
drink unimplemented
ascjones Feb 9, 2024
82fcc91
Send it
ascjones Feb 9, 2024
e1f7a9f
Fix comment
ascjones Feb 9, 2024
be62c50
Fix comment
ascjones Feb 9, 2024
56a3bbf
Fix comment
ascjones Feb 9, 2024
8b21039
Fix comment
ascjones Feb 9, 2024
c72676d
Fix comment
ascjones Feb 9, 2024
864dcf4
Merge branch 'master' into aj/delegate-dependency
ascjones Feb 19, 2024
785db39
Update integration-tests/upgradeable-contracts/delegator/delegatee2/C…
ascjones Feb 21, 2024
82d720e
Update crates/e2e/src/backend.rs
ascjones Feb 21, 2024
22b01d0
update to `lock/unlock` host fns
ascjones Feb 22, 2024
f0c99e8
#[allow(deprecated)] for _v1 calls
ascjones Feb 22, 2024
4d975b8
Add link to lock up deposit
ascjones Feb 22, 2024
430a831
doc comment as per review
ascjones Feb 22, 2024
1442530
Merge branch 'master' into aj/delegate-dependency
ascjones Feb 23, 2024
eb36349
Update crates/e2e/src/backend.rs
ascjones Feb 23, 2024
c5581dc
Update crates/e2e/src/backend.rs
ascjones Feb 23, 2024
e9b39c9
Update crates/env/src/api.rs
ascjones Feb 23, 2024
d20cd52
Apply suggestions from code review
ascjones Feb 23, 2024
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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Linter] Publish the linting crates on crates.io - [#2060](https://github.com/paritytech/ink/pull/2060)
- [E2E] Added `create_call_builder` for testing existing contracts - [#2075](https://github.com/paritytech/ink/pull/2075)
- `call_v2` cross-contract calls with additional limit parameters - [#2077](https://github.com/paritytech/ink/pull/2077)
- `delegate_dependency` api calls - [#2076](https://github.com/paritytech/ink/pull/2076)

### Changed
- `Mapping`: Reflect all possible failure cases in comments ‒ [#2079](https://github.com/paritytech/ink/pull/2079)
Expand Down
55 changes: 47 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const_env = { version = "0.1"}

# Substrate dependencies
pallet-contracts = { version = "27.0.0", default-features = false }
pallet-contracts-uapi = { package = "ink-pallet-contracts-uapi", version = "=6.0.0", default-features = false }
pallet-contracts-uapi = { package = "pallet-contracts-uapi-next", version = "=6.0.1", default-features = false }
sp-core = { version = "28.0.0", default-features = false }
sp-keyring = { version = "31.0.0", default-features = false }
sp-runtime = { version = "31.0.1", default-features = false }
Expand Down
32 changes: 31 additions & 1 deletion crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use super::Keypair;
use crate::{
backend_calls::{
InstantiateBuilder,
RemoveCodeBuilder,
UploadBuilder,
},
builders::CreateBuilderPartial,
Expand Down Expand Up @@ -159,6 +160,28 @@ pub trait ContractsBackend<E: Environment> {
UploadBuilder::new(self, contract_name, caller)
}

/// Start building a remove code call.
ascjones marked this conversation as resolved.
Show resolved Hide resolved
/// # Example
///
/// ```ignore
/// let contract = client
/// .remove_code(&ink_e2e::alice(), code_hash)
/// // Submit the call for on-chain execution.
/// .submit()
/// .await
/// .expect("remove failed");
/// ```
fn remove_code<'a>(
&'a mut self,
caller: &'a Keypair,
code_hash: E::Hash,
) -> RemoveCodeBuilder<E, Self>
where
Self: Sized + BuilderClient<E>,
{
RemoveCodeBuilder::new(self, caller, code_hash)
}

/// Start building a call using a builder pattern.
///
/// # Example
Expand Down Expand Up @@ -193,7 +216,7 @@ 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
/// Executes a bare `call` for the contract at `account_id`. This function does not
/// perform a dry-run, and user is expected to provide the gas limit.
ascjones marked this conversation as resolved.
Show resolved Hide resolved
///
/// Use it when you want to have a more precise control over submitting extrinsic.
Expand Down Expand Up @@ -239,6 +262,13 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<E, Self::EventLog>, Self::Error>;

/// Removes the code of the contract at `code_hash`.
async fn bare_remove_code(
&mut self,
caller: &Keypair,
code_hash: E::Hash,
) -> Result<Self::EventLog, Self::Error>;

/// Bare instantiate call. This function does not perform a dry-run,
/// and user is expected to provide the gas limit.
///
Expand Down
31 changes: 31 additions & 0 deletions crates/e2e/src/backend_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,37 @@ where
}
}

/// Allows to build an end-to-end remove code call using a builder pattern.
pub struct RemoveCodeBuilder<'a, E, B>
where
E: Environment,
B: BuilderClient<E>,
{
client: &'a mut B,
caller: &'a Keypair,
code_hash: E::Hash,
}

impl<'a, E, B> RemoveCodeBuilder<'a, E, B>
where
E: Environment,
B: BuilderClient<E>,
{
/// Initialize a remove code builder with essential values.
pub fn new(client: &'a mut B, caller: &'a Keypair, code_hash: E::Hash) -> Self {
Self {
client,
caller,
code_hash,
}
}

/// Submit the remove code extrinsic.
pub async fn submit(&mut self) -> Result<B::EventLog, B::Error> {
B::bare_remove_code(self.client, self.caller, self.code_hash).await
}
}

fn calculate_weight(
mut proof_size: u64,
mut ref_time: u64,
Expand Down
12 changes: 10 additions & 2 deletions crates/e2e/src/drink_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ where
#[async_trait]
impl<
AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>,
Hash: Copy + From<[u8; 32]>,
Hash: Copy + Send + From<[u8; 32]>,
Config: SandboxConfig,
E: Environment<
AccountId = AccountId,
Expand Down Expand Up @@ -341,6 +341,14 @@ where
})
}

async fn bare_remove_code(
&mut self,
_caller: &Keypair,
_code_hash: E::Hash,
) -> Result<Self::EventLog, Self::Error> {
unimplemented!("drink! sandbox does not yet support remove_code")
}

async fn bare_call<Args: Sync + Encode + Clone, RetType: Send + Decode>(
&mut self,
caller: &Keypair,
Expand Down Expand Up @@ -420,7 +428,7 @@ where

impl<
AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>,
Hash: Copy + From<[u8; 32]>,
Hash: Copy + Send + From<[u8; 32]>,
Config: SandboxConfig,
E: Environment<
AccountId = AccountId,
Expand Down
3 changes: 3 additions & 0 deletions crates/e2e/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub enum Error<DispatchError: fmt::Debug + fmt::Display> {
/// The `call` extrinsic failed.
#[error("Call extrinsic error: {0}")]
CallExtrinsic(DispatchError),
/// The `remove_code` extrinsic failed.
#[error("Remove code extrinsic error: {0}")]
RemoveCodeExtrinsic(DispatchError),
/// Error fetching account balance.
#[error("Fetching account Balance error: {0}")]
Balance(String),
Expand Down
33 changes: 29 additions & 4 deletions crates/e2e/src/subxt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ where
E::AccountId: Debug + Send + Sync,
E::Balance:
Clone + Debug + Send + Sync + From<u128> + scale::HasCompact + serde::Serialize,
E::Hash: Debug + Send + scale::Encode,
E::Hash: Debug + Send + Sync + scale::Encode,
{
async fn bare_instantiate<Contract: Clone, Args: Send + Sync + Encode + Clone, R>(
&mut self,
Expand Down Expand Up @@ -536,6 +536,30 @@ where
Ok(ret)
}

async fn bare_remove_code(
&mut self,
caller: &Keypair,
code_hash: E::Hash,
) -> Result<Self::EventLog, Self::Error> {
let tx_events = self.api.remove_code(caller, code_hash).await;

for evt in tx_events.iter() {
let evt = evt.unwrap_or_else(|err| {
panic!("unable to unwrap event: {err:?}");
});

if is_extrinsic_failed_event(&evt) {
let metadata = self.api.client.metadata();
let dispatch_error =
DispatchError::decode_from(evt.field_bytes(), metadata)
.map_err(|e| Error::Decoding(e.to_string()))?;
return Err(Error::RemoveCodeExtrinsic(dispatch_error))
}
}

Ok(tx_events)
}

async fn bare_call<Args: Sync + Encode + Clone, RetType: Send + Decode>(
&mut self,
caller: &Keypair,
Expand Down Expand Up @@ -571,7 +595,7 @@ where
if is_extrinsic_failed_event(&evt) {
let metadata = self.api.client.metadata();
let dispatch_error =
subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata)
DispatchError::decode_from(evt.field_bytes(), metadata)
.map_err(|e| Error::Decoding(e.to_string()))?;
log_error(&format!("extrinsic for call failed: {dispatch_error}"));
return Err(Error::CallExtrinsic(dispatch_error))
Expand Down Expand Up @@ -660,13 +684,14 @@ where
C::Address: From<sr25519::PublicKey>,
C::Signature: From<sr25519::Signature>,
C::Address: Send + Sync,
<<C as subxt::Config>::ExtrinsicParams as subxt::config::ExtrinsicParams<C>>::OtherParams: Default + Send + Sync,
<<C as subxt::Config>::ExtrinsicParams as ExtrinsicParams<C>>::OtherParams:
Default + Send + Sync,

E: Environment,
E::AccountId: Debug + Send + Sync,
E::Balance:
Clone + Debug + Send + Sync + From<u128> + scale::HasCompact + serde::Serialize,
E::Hash: Debug + Send + scale::Encode,
E::Hash: Debug + Send + Sync + scale::Encode,
{
}

Expand Down
Loading
Loading