Skip to content

Commit d0b3527

Browse files
committed
Merge branch 'master' into aj/e2e-call-dry-run
2 parents b674a88 + fc25569 commit d0b3527

File tree

34 files changed

+153
-203
lines changed

34 files changed

+153
-203
lines changed

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct_field_align_threshold = 0
3434
enum_discrim_align_threshold = 0
3535
match_arm_blocks = true
3636
force_multiline_blocks = true # changed
37-
fn_args_layout = "Tall"
37+
fn_params_layout = "Tall"
3838
brace_style = "SameLineWhere"
3939
control_brace_style = "AlwaysSameLine"
4040
trailing_semicolon = false # changed

ARCHITECTURE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ ink! is composed of a number of crates that are all found in the
2222
* [`env`](https://github.com/paritytech/ink/tree/master/crates/env):
2323
Serves two roles:
2424
* Exposes environmental functions, like information about the caller
25-
of a contract call, getting random entropy, or e.g. self-terminating the
26-
contract.
25+
of a contract call or e.g. self-terminating the contract.
2726
* Provides the connection to the [`pallet-contracts`](https://github.com/paritytech/substrate/tree/master/frame/contracts),
2827
so anything that calls into the underlying execution engine of the smart contract.
2928
This includes getting and setting a smart contracts storage, as well

crates/e2e/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ink_env = { version = "4.0.0-beta.1", path = "../env" }
2121
ink_primitives = { version = "4.0.0-beta.1", path = "../primitives" }
2222

2323
contract-metadata = { version = "2.0.0-rc" }
24+
funty = "2.0.0"
2425
impl-serde = { version = "0.3.1", default-features = false }
2526
jsonrpsee = { version = "0.16.0", features = ["ws-client"] }
2627
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
@@ -29,14 +30,14 @@ tokio = { version = "1.18.2", features = ["rt-multi-thread"] }
2930
log = { version = "0.4" }
3031
env_logger = { version = "0.10" }
3132
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] }
32-
subxt = "0.25.0"
33+
subxt = "0.26.0"
3334

3435
# Substrate
35-
pallet-contracts-primitives = "7.0.0"
36-
sp-core = "7.0.0"
37-
sp-keyring = "7.0.0"
38-
sp-runtime = "7.0.0"
39-
sp-weights = "4.0.0"
36+
pallet-contracts-primitives = "12.0.0"
37+
sp-core = "11.0.0"
38+
sp-keyring = "12.0.0"
39+
sp-runtime = "12.0.0"
40+
sp-weights = "8.0.0"
4041

4142
[dev-dependencies]
4243
# Required for the doctest of `MessageBuilder::call`

crates/e2e/macro/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn build_contract(path_to_cargo_toml: &str) -> String {
186186
};
187187

188188
let manifest_path = ManifestPath::new(path_to_cargo_toml).unwrap_or_else(|err| {
189-
panic!("Invalid manifest path {}: {}", path_to_cargo_toml, err)
189+
panic!("Invalid manifest path {path_to_cargo_toml}: {err}")
190190
});
191191
let args = ExecuteArgs {
192192
manifest_path,
@@ -216,7 +216,7 @@ fn build_contract(path_to_cargo_toml: &str) -> String {
216216
.into()
217217
}
218218
Err(err) => {
219-
panic!("contract build for {} failed: {}", path_to_cargo_toml, err)
219+
panic!("contract build for {path_to_cargo_toml} failed: {err}")
220220
}
221221
}
222222
}

crates/e2e/src/client.rs

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,23 @@ use ink_env::Environment;
3232
use ink_primitives::MessageResult;
3333

3434
use sp_core::Pair;
35-
use sp_runtime::traits::{
36-
IdentifyAccount,
37-
Verify,
38-
};
3935
use std::{
4036
collections::BTreeMap,
4137
fmt::Debug,
4238
marker::PhantomData,
4339
path::Path,
4440
};
41+
4542
use subxt::{
4643
blocks::ExtrinsicEvents,
44+
config::ExtrinsicParams,
4745
events::EventDetails,
48-
ext::{
49-
bitvec::macros::internal::funty::Fundamental,
50-
scale_value::{
51-
Composite,
52-
Value,
53-
ValueDef,
54-
},
55-
},
56-
tx::{
57-
ExtrinsicParams,
58-
PairSigner,
46+
ext::scale_value::{
47+
Composite,
48+
Value,
49+
ValueDef,
5950
},
51+
tx::PairSigner,
6052
};
6153

6254
/// Result of a contract instantiation.
@@ -104,6 +96,7 @@ where
10496
impl<C, E> core::fmt::Debug for InstantiationResult<C, E>
10597
where
10698
C: subxt::Config,
99+
C::AccountId: Debug,
107100
E: Environment,
108101
<E as Environment>::AccountId: Debug,
109102
<E as Environment>::Balance: Debug,
@@ -270,7 +263,7 @@ where
270263
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
271264
match &self {
272265
Error::ContractNotFound(name) => {
273-
f.write_str(&format!("ContractNotFound: {}", name))
266+
f.write_str(&format!("ContractNotFound: {name}"))
274267
}
275268
Error::InstantiateDryRun(res) => {
276269
f.write_str(&format!(
@@ -283,7 +276,7 @@ where
283276
Error::UploadExtrinsic(_) => f.write_str("UploadExtrinsic"),
284277
Error::CallDryRun(_) => f.write_str("CallDryRun"),
285278
Error::CallExtrinsic(_) => f.write_str("CallExtrinsic"),
286-
Error::Balance(msg) => write!(f, "Balance: {}", msg),
279+
Error::Balance(msg) => write!(f, "Balance: {msg}"),
287280
}
288281
}
289282
}
@@ -336,14 +329,10 @@ where
336329
impl<C, E> Client<C, E>
337330
where
338331
C: subxt::Config,
339-
C::AccountId: Into<C::Address> + serde::de::DeserializeOwned,
340-
C::Address: From<C::AccountId>,
332+
C::AccountId: serde::de::DeserializeOwned,
333+
C::AccountId: scale::Codec + Debug,
341334
C::Signature: From<sr25519::Signature>,
342-
<C::Signature as Verify>::Signer: From<sr25519::Public>,
343335
<C::ExtrinsicParams as ExtrinsicParams<C::Index, C::Hash>>::OtherParams: Default,
344-
<C::Signature as Verify>::Signer:
345-
From<sr25519::Public> + IdentifyAccount<AccountId = C::AccountId>,
346-
sr25519::Signature: Into<C::Signature>,
347336

348337
E: Environment,
349338
E::AccountId: Debug,
@@ -356,14 +345,14 @@ where
356345
.await
357346
.unwrap_or_else(|err| {
358347
if let subxt::Error::Rpc(subxt::error::RpcError::ClientError(_)) = err {
359-
let error_msg = format!("Error establishing connection to a node at {}. Make sure you run a node behind the given url!", url);
348+
let error_msg = format!("Error establishing connection to a node at {url}. Make sure you run a node behind the given url!");
360349
log_error(&error_msg);
361350
panic!("{}", error_msg);
362351
}
363352
log_error(
364353
"Unable to create client! Please check that your node is running.",
365354
);
366-
panic!("Unable to create client: {:?}", err);
355+
panic!("Unable to create client: {err:?}");
367356
});
368357
let contracts = contracts
369358
.into_iter()
@@ -397,11 +386,12 @@ where
397386
) -> Signer<C>
398387
where
399388
E::Balance: Clone,
400-
C::AccountId: Clone + core::fmt::Display,
389+
C::AccountId: Clone + core::fmt::Display + core::fmt::Debug,
390+
C::AccountId: From<sp_core::crypto::AccountId32>,
401391
{
402392
let (pair, _, _) = <sr25519::Pair as Pair>::generate_with_phrase(None);
403-
let account_id =
404-
<C::Signature as Verify>::Signer::from(pair.public()).into_account();
393+
let pair_signer = PairSigner::<C, _>::new(pair);
394+
let account_id = pair_signer.account_id().to_owned();
405395

406396
for _ in 0..6 {
407397
let transfer_result = self
@@ -429,7 +419,7 @@ where
429419
}
430420
}
431421

432-
PairSigner::new(pair)
422+
pair_signer
433423
}
434424

435425
/// This function extracts the metadata of the contract at the file path
@@ -478,7 +468,7 @@ where
478468
let contract_metadata = self
479469
.contracts
480470
.get(contract_name)
481-
.unwrap_or_else(|| panic!("Unknown contract {}", contract_name));
471+
.unwrap_or_else(|| panic!("Unknown contract {contract_name}"));
482472
let code = crate::utils::extract_wasm(contract_metadata);
483473
let data = constructor_exec_input(constructor);
484474

@@ -547,13 +537,13 @@ where
547537
let mut account_id = None;
548538
for evt in tx_events.iter() {
549539
let evt = evt.unwrap_or_else(|err| {
550-
panic!("unable to unwrap event: {:?}", err);
540+
panic!("unable to unwrap event: {err:?}");
551541
});
552542

553543
if let Some(instantiated) = evt
554544
.as_event::<ContractInstantiatedEvent<E>>()
555545
.unwrap_or_else(|err| {
556-
panic!("event conversion to `Instantiated` failed: {:?}", err);
546+
panic!("event conversion to `Instantiated` failed: {err:?}");
557547
})
558548
{
559549
log_info(&format!(
@@ -572,8 +562,7 @@ where
572562
&metadata,
573563
);
574564
log_error(&format!(
575-
"extrinsic for instantiate failed: {:?}",
576-
dispatch_error
565+
"extrinsic for instantiate failed: {dispatch_error:?}"
577566
));
578567
return Err(Error::InstantiateExtrinsic(dispatch_error))
579568
}
@@ -590,9 +579,11 @@ where
590579

591580
/// Generate a unique salt based on the system time.
592581
fn salt() -> Vec<u8> {
582+
use funty::Fundamental as _;
583+
593584
std::time::SystemTime::now()
594585
.duration_since(std::time::UNIX_EPOCH)
595-
.unwrap_or_else(|err| panic!("unable to get unix time: {}", err))
586+
.unwrap_or_else(|err| panic!("unable to get unix time: {err}"))
596587
.as_millis()
597588
.as_u128()
598589
.to_le_bytes()
@@ -636,7 +627,7 @@ where
636627
.api
637628
.upload_dry_run(signer, code.clone(), storage_deposit_limit)
638629
.await;
639-
log_info(&format!("upload dry run: {:?}", dry_run));
630+
log_info(&format!("upload dry run: {dry_run:?}"));
640631
if dry_run.is_err() {
641632
return Err(Error::UploadDryRun(dry_run))
642633
}
@@ -646,12 +637,12 @@ where
646637
let mut hash = None;
647638
for evt in tx_events.iter() {
648639
let evt = evt.unwrap_or_else(|err| {
649-
panic!("unable to unwrap event: {:?}", err);
640+
panic!("unable to unwrap event: {err:?}");
650641
});
651642

652643
if let Some(uploaded) =
653644
evt.as_event::<CodeStoredEvent<E>>().unwrap_or_else(|err| {
654-
panic!("event conversion to `Uploaded` failed: {:?}", err);
645+
panic!("event conversion to `Uploaded` failed: {err:?}");
655646
})
656647
{
657648
log_info(&format!(
@@ -666,10 +657,7 @@ where
666657
evt.field_bytes(),
667658
&metadata,
668659
);
669-
log_error(&format!(
670-
"extrinsic for upload failed: {:?}",
671-
dispatch_error
672-
));
660+
log_error(&format!("extrinsic for upload failed: {dispatch_error:?}"));
673661
return Err(Error::UploadExtrinsic(dispatch_error))
674662
}
675663
}
@@ -683,7 +671,7 @@ where
683671
None => {
684672
dry_run
685673
.as_ref()
686-
.unwrap_or_else(|err| panic!("must have worked: {:?}", err))
674+
.unwrap_or_else(|err| panic!("must have worked: {err:?}"))
687675
.code_hash
688676
}
689677
};
@@ -731,7 +719,7 @@ where
731719

732720
for evt in tx_events.iter() {
733721
let evt = evt.unwrap_or_else(|err| {
734-
panic!("unable to unwrap event: {:?}", err);
722+
panic!("unable to unwrap event: {err:?}");
735723
});
736724

737725
if is_extrinsic_failed_event(&evt) {
@@ -740,7 +728,7 @@ where
740728
evt.field_bytes(),
741729
&metadata,
742730
);
743-
log_error(&format!("extrinsic for call failed: {:?}", dispatch_error));
731+
log_error(&format!("extrinsic for call failed: {dispatch_error:?}"));
744732
return Err(Error::CallExtrinsic(dispatch_error))
745733
}
746734
}
@@ -807,28 +795,32 @@ where
807795
.api
808796
.client
809797
.storage()
810-
.fetch_or_default(&account_addr, None)
798+
.at(None)
799+
.await
800+
.unwrap_or_else(|err| {
801+
panic!("unable to fetch balance: {err:?}");
802+
})
803+
.fetch_or_default(&account_addr)
811804
.await
812805
.unwrap_or_else(|err| {
813-
panic!("unable to fetch balance: {:?}", err);
806+
panic!("unable to fetch balance: {err:?}");
814807
})
815808
.to_value()
816809
.unwrap_or_else(|err| {
817-
panic!("unable to decode account info: {:?}", err);
810+
panic!("unable to decode account info: {err:?}");
818811
});
819812

820813
let account_data = get_composite_field_value(&account, "data")?;
821814
let balance = get_composite_field_value(account_data, "free")?;
822815
let balance = balance.as_u128().ok_or_else(|| {
823-
Error::Balance(format!("{:?} should convert to u128", balance))
816+
Error::Balance(format!("{balance:?} should convert to u128"))
824817
})?;
825818
let balance = E::Balance::try_from(balance).map_err(|_| {
826-
Error::Balance(format!("{:?} failed to convert from u128", balance))
819+
Error::Balance(format!("{balance:?} failed to convert from u128"))
827820
})?;
828821

829822
log_info(&format!(
830-
"balance of contract {:?} is {:?}",
831-
account_id, balance
823+
"balance of contract {account_id:?} is {balance:?}"
832824
));
833825
Ok(balance)
834826
}
@@ -853,7 +845,7 @@ where
853845
.iter()
854846
.find(|(name, _)| name == field_name)
855847
.ok_or_else(|| {
856-
Error::Balance(format!("No field named '{}' found", field_name))
848+
Error::Balance(format!("No field named '{field_name}' found"))
857849
})?;
858850
Ok(field)
859851
} else {

crates/e2e/src/default_accounts.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
1717
use super::{
1818
AccountKeyring,
19-
IdentifyAccount,
2019
PairSigner,
21-
Verify,
2220
};
2321
use sp_core::sr25519;
2422

@@ -33,9 +31,8 @@ macro_rules! default_account {
3331
pub fn $fn_name<C>() -> PairSigner<C, sr25519::Pair>
3432
where
3533
C: subxt::Config,
36-
<C::Signature as Verify>::Signer: From<sr25519::Public>,
3734
C::Signature: From<sr25519::Signature>,
38-
<C::Signature as Verify>::Signer: IdentifyAccount<AccountId = C::AccountId>,
35+
C::AccountId: From<sp_core::crypto::AccountId32>
3936
{
4037
PairSigner::new(AccountKeyring::$keyring_fn_name.pair())
4138
}

0 commit comments

Comments
 (0)