Skip to content

Commit

Permalink
Update subxt version (#1750)
Browse files Browse the repository at this point in the history
* Checkpoint

* Compiling

* blind guess

* blind guess

* blind guess

* blind guess

* blind guess

* std gating

* test deps

* import?

* Review

* Review
  • Loading branch information
pmikolajczyk41 authored Apr 17, 2023
1 parent b4fff41 commit 644c547
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 73 deletions.
12 changes: 6 additions & 6 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ tokio = { version = "1.18.2", features = ["rt-multi-thread"] }
log = { version = "0.4" }
env_logger = { version = "0.10" }
scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] }
subxt = "0.27.0"
subxt = "0.28.0"

# Substrate
pallet-contracts-primitives = "18.0.0"
sp-core = "16.0.0"
sp-keyring = "18.0.0"
sp-runtime = "18.0.0"
sp-weights = "14.0.0"
pallet-contracts-primitives = "23.0.0"
sp-core = "20.0.0"
sp-keyring = "23.0.0"
sp-runtime = "23.0.0"
sp-weights = "19.0.0"

[dev-dependencies]
# Required for the doctest of `MessageBuilder::call`
Expand Down
74 changes: 48 additions & 26 deletions crates/e2e/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use ink_env::Environment;
use ink_primitives::MessageResult;
use pallet_contracts_primitives::ExecReturnValue;
use sp_core::Pair;
#[cfg(feature = "std")]
use std::{
collections::BTreeMap,
fmt::Debug,
Expand All @@ -42,10 +43,14 @@ use subxt::{
blocks::ExtrinsicEvents,
config::ExtrinsicParams,
events::EventDetails,
ext::scale_value::{
Composite,
Value,
ValueDef,
ext::{
scale_decode,
scale_encode,
scale_value::{
Composite,
Value,
ValueDef,
},
},
tx::PairSigner,
};
Expand Down Expand Up @@ -279,6 +284,8 @@ where
CallExtrinsic(subxt::error::DispatchError),
/// Error fetching account balance.
Balance(String),
/// Decoding failed.
Decoding(subxt::Error),
}

// We implement a custom `Debug` here, as to avoid requiring the trait
Expand Down Expand Up @@ -307,12 +314,21 @@ where
Error::CallDryRun(_) => f.write_str("CallDryRun"),
Error::CallExtrinsic(_) => f.write_str("CallExtrinsic"),
Error::Balance(msg) => write!(f, "Balance: {msg}"),
Error::Decoding(err) => write!(f, "Decoding: {err}"),
}
}
}

/// A contract was successfully instantiated.
#[derive(Debug, scale::Decode, scale::Encode)]
#[derive(
Debug,
scale::Decode,
scale::Encode,
scale_decode::DecodeAsType,
scale_encode::EncodeAsType,
)]
#[decode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_decode")]
#[encode_as_type(crate_path = "subxt::ext::scale_encode")]
struct ContractInstantiatedEvent<E: Environment> {
/// Account id of the deployer.
pub deployer: E::AccountId,
Expand All @@ -329,7 +345,15 @@ where
}

/// Code with the specified hash has been stored.
#[derive(Debug, scale::Decode, scale::Encode)]
#[derive(
Debug,
scale::Decode,
scale::Encode,
scale_decode::DecodeAsType,
scale_encode::EncodeAsType,
)]
#[decode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_decode")]
#[encode_as_type(crate_path = "subxt::ext::scale_encode")]
struct CodeStoredEvent<E: Environment> {
/// Hash under which the contract code was stored.
pub code_hash: E::Hash,
Expand Down Expand Up @@ -548,7 +572,7 @@ where
.api
.instantiate_with_code(
value,
dry_run.gas_required,
dry_run.gas_required.into(),
storage_deposit_limit,
code,
data.clone(),
Expand Down Expand Up @@ -580,10 +604,9 @@ where
// multiple accounts as part of its constructor!
} else if is_extrinsic_failed_event(&evt) {
let metadata = self.api.client.metadata();
let dispatch_error = subxt::error::DispatchError::decode_from(
evt.field_bytes(),
&metadata,
);
let dispatch_error =
subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata)
.map_err(Error::Decoding)?;
log_error(&format!(
"extrinsic for instantiate failed: {dispatch_error:?}"
));
Expand Down Expand Up @@ -672,10 +695,10 @@ where
break
} else if is_extrinsic_failed_event(&evt) {
let metadata = self.api.client.metadata();
let dispatch_error = subxt::error::DispatchError::decode_from(
evt.field_bytes(),
&metadata,
);
let dispatch_error =
subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata)
.map_err(Error::Decoding)?;

log_error(&format!("extrinsic for upload failed: {dispatch_error:?}"));
return Err(Error::UploadExtrinsic(dispatch_error))
}
Expand Down Expand Up @@ -727,9 +750,9 @@ where
let tx_events = self
.api
.call(
sp_runtime::MultiAddress::Id(message.account_id().clone()),
subxt::utils::MultiAddress::Id(message.account_id().clone()),
value,
dry_run.exec_result.gas_required,
dry_run.exec_result.gas_required.into(),
storage_deposit_limit,
message.exec_input().to_vec(),
signer,
Expand All @@ -743,10 +766,9 @@ 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,
);
let dispatch_error =
subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata)
.map_err(Error::Decoding)?;
log_error(&format!("extrinsic for call failed: {dispatch_error:?}"));
return Err(Error::CallExtrinsic(dispatch_error))
}
Expand Down Expand Up @@ -788,10 +810,10 @@ 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,
);
let dispatch_error =
subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata)
.map_err(Error::Decoding)?;

log_error(&format!("extrinsic for call failed: {dispatch_error:?}"));
return Err(Error::CallExtrinsic(dispatch_error))
}
Expand Down Expand Up @@ -857,7 +879,7 @@ where
.api
.client
.storage()
.at(None)
.at_latest()
.await
.unwrap_or_else(|err| {
panic!("unable to fetch balance: {err:?}");
Expand Down
Loading

0 comments on commit 644c547

Please sign in to comment.