Skip to content

Commit

Permalink
Merge branch 'master' into hc-bump-substrate-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
HCastano committed Jan 27, 2023
2 parents 376401c + 33b04bc commit 48d7fed
Show file tree
Hide file tree
Showing 25 changed files with 94 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = true # changed
fn_args_layout = "Tall"
fn_params_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = false # changed
Expand Down
4 changes: 2 additions & 2 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn build_contract(path_to_cargo_toml: &str) -> String {
};

let manifest_path = ManifestPath::new(path_to_cargo_toml).unwrap_or_else(|err| {
panic!("Invalid manifest path {}: {}", path_to_cargo_toml, err)
panic!("Invalid manifest path {path_to_cargo_toml}: {err}")
});
let args = ExecuteArgs {
manifest_path,
Expand Down Expand Up @@ -216,7 +216,7 @@ fn build_contract(path_to_cargo_toml: &str) -> String {
.into()
}
Err(err) => {
panic!("contract build for {} failed: {}", path_to_cargo_toml, err)
panic!("contract build for {path_to_cargo_toml} failed: {err}")
}
}
}
55 changes: 24 additions & 31 deletions crates/e2e/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ where
self.value
.unwrap_or_else(|env_err| {
panic!(
"Decoding dry run result to ink! message return type failed: {}",
env_err
"Decoding dry run result to ink! message return type failed: {env_err}"
)
})
.unwrap_or_else(|lang_err| {
panic!(
"Encountered a `LangError` while decoding dry run result to ink! message: {:?}",
lang_err
"Encountered a `LangError` while decoding dry run result to ink! message: {lang_err:?}"
)
})
}
Expand Down Expand Up @@ -216,7 +214,7 @@ where
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match &self {
Error::ContractNotFound(name) => {
f.write_str(&format!("ContractNotFound: {}", name))
f.write_str(&format!("ContractNotFound: {name}"))
}
Error::InstantiateDryRun(res) => {
f.write_str(&format!(
Expand All @@ -229,7 +227,7 @@ where
Error::UploadExtrinsic(_) => f.write_str("UploadExtrinsic"),
Error::CallDryRun(_) => f.write_str("CallDryRun"),
Error::CallExtrinsic(_) => f.write_str("CallExtrinsic"),
Error::Balance(msg) => write!(f, "Balance: {}", msg),
Error::Balance(msg) => write!(f, "Balance: {msg}"),
}
}
}
Expand Down Expand Up @@ -298,14 +296,14 @@ where
.await
.unwrap_or_else(|err| {
if let subxt::Error::Rpc(subxt::error::RpcError::ClientError(_)) = err {
let error_msg = format!("Error establishing connection to a node at {}. Make sure you run a node behind the given url!", url);
let error_msg = format!("Error establishing connection to a node at {url}. Make sure you run a node behind the given url!");
log_error(&error_msg);
panic!("{}", error_msg);
}
log_error(
"Unable to create client! Please check that your node is running.",
);
panic!("Unable to create client: {:?}", err);
panic!("Unable to create client: {err:?}");
});
let contracts = contracts
.into_iter()
Expand Down Expand Up @@ -421,7 +419,7 @@ where
let contract_metadata = self
.contracts
.get(contract_name)
.unwrap_or_else(|| panic!("Unknown contract {}", contract_name));
.unwrap_or_else(|| panic!("Unknown contract {contract_name}"));
let code = crate::utils::extract_wasm(contract_metadata);
let data = constructor_exec_input(constructor);

Expand Down Expand Up @@ -490,13 +488,13 @@ where
let mut account_id = None;
for evt in tx_events.iter() {
let evt = evt.unwrap_or_else(|err| {
panic!("unable to unwrap event: {:?}", err);
panic!("unable to unwrap event: {err:?}");
});

if let Some(instantiated) = evt
.as_event::<ContractInstantiatedEvent<E>>()
.unwrap_or_else(|err| {
panic!("event conversion to `Instantiated` failed: {:?}", err);
panic!("event conversion to `Instantiated` failed: {err:?}");
})
{
log_info(&format!(
Expand All @@ -515,8 +513,7 @@ where
&metadata,
);
log_error(&format!(
"extrinsic for instantiate failed: {:?}",
dispatch_error
"extrinsic for instantiate failed: {dispatch_error:?}"
));
return Err(Error::InstantiateExtrinsic(dispatch_error))
}
Expand All @@ -537,7 +534,7 @@ where

std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_else(|err| panic!("unable to get unix time: {}", err))
.unwrap_or_else(|err| panic!("unable to get unix time: {err}"))
.as_millis()
.as_u128()
.to_le_bytes()
Expand Down Expand Up @@ -581,7 +578,7 @@ where
.api
.upload_dry_run(signer, code.clone(), storage_deposit_limit)
.await;
log_info(&format!("upload dry run: {:?}", dry_run));
log_info(&format!("upload dry run: {dry_run:?}"));
if dry_run.is_err() {
return Err(Error::UploadDryRun(dry_run))
}
Expand All @@ -591,12 +588,12 @@ where
let mut hash = None;
for evt in tx_events.iter() {
let evt = evt.unwrap_or_else(|err| {
panic!("unable to unwrap event: {:?}", err);
panic!("unable to unwrap event: {err:?}");
});

if let Some(uploaded) =
evt.as_event::<CodeStoredEvent<E>>().unwrap_or_else(|err| {
panic!("event conversion to `Uploaded` failed: {:?}", err);
panic!("event conversion to `Uploaded` failed: {err:?}");
})
{
log_info(&format!(
Expand All @@ -611,10 +608,7 @@ where
evt.field_bytes(),
&metadata,
);
log_error(&format!(
"extrinsic for upload failed: {:?}",
dispatch_error
));
log_error(&format!("extrinsic for upload failed: {dispatch_error:?}"));
return Err(Error::UploadExtrinsic(dispatch_error))
}
}
Expand All @@ -628,7 +622,7 @@ where
None => {
dry_run
.as_ref()
.unwrap_or_else(|err| panic!("must have worked: {:?}", err))
.unwrap_or_else(|err| panic!("must have worked: {err:?}"))
.code_hash
}
};
Expand Down Expand Up @@ -688,7 +682,7 @@ where

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

if is_extrinsic_failed_event(&evt) {
Expand All @@ -697,7 +691,7 @@ where
evt.field_bytes(),
&metadata,
);
log_error(&format!("extrinsic for call failed: {:?}", dispatch_error));
log_error(&format!("extrinsic for call failed: {dispatch_error:?}"));
return Err(Error::CallExtrinsic(dispatch_error))
}
}
Expand Down Expand Up @@ -743,25 +737,24 @@ where
.fetch_or_default(&account_addr)
.await
.unwrap_or_else(|err| {
panic!("unable to fetch balance: {:?}", err);
panic!("unable to fetch balance: {err:?}");
})
.to_value()
.unwrap_or_else(|err| {
panic!("unable to decode account info: {:?}", err);
panic!("unable to decode account info: {err:?}");
});

let account_data = get_composite_field_value(&account, "data")?;
let balance = get_composite_field_value(account_data, "free")?;
let balance = balance.as_u128().ok_or_else(|| {
Error::Balance(format!("{:?} should convert to u128", balance))
Error::Balance(format!("{balance:?} should convert to u128"))
})?;
let balance = E::Balance::try_from(balance).map_err(|_| {
Error::Balance(format!("{:?} failed to convert from u128", balance))
Error::Balance(format!("{balance:?} failed to convert from u128"))
})?;

log_info(&format!(
"balance of contract {:?} is {:?}",
account_id, balance
"balance of contract {account_id:?} is {balance:?}"
));
Ok(balance)
}
Expand All @@ -786,7 +779,7 @@ where
.iter()
.find(|(name, _)| name == field_name)
.ok_or_else(|| {
Error::Balance(format!("No field named '{}' found", field_name))
Error::Balance(format!("No field named '{field_name}' found"))
})?;
Ok(field)
} else {
Expand Down
43 changes: 17 additions & 26 deletions crates/e2e/src/xts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ where
.build(&url)
.await
.unwrap_or_else(|err| {
panic!("error on ws request: {:?}", err);
panic!("error on ws request: {err:?}");
});

Self {
Expand Down Expand Up @@ -230,7 +230,7 @@ where
.await?;

tx_progress.wait_for_in_block().await.unwrap_or_else(|err| {
panic!("error on call `wait_for_in_block`: {:?}", err);
panic!("error on call `wait_for_in_block`: {err:?}");
});

Ok(())
Expand Down Expand Up @@ -263,10 +263,10 @@ where
.request("state_call", params)
.await
.unwrap_or_else(|err| {
panic!("error on ws request `contracts_instantiate`: {:?}", err);
panic!("error on ws request `contracts_instantiate`: {err:?}");
});
scale::Decode::decode(&mut bytes.as_ref()).unwrap_or_else(|err| {
panic!("decoding ContractInstantiateResult failed: {}", err)
panic!("decoding ContractInstantiateResult failed: {err}")
})
}

Expand Down Expand Up @@ -312,20 +312,17 @@ where
tx_progress
})
.unwrap_or_else(|err| {
panic!(
"error on call `sign_and_submit_then_watch_default`: {:?}",
err
);
panic!("error on call `sign_and_submit_then_watch_default`: {err:?}");
})
.wait_for_in_block()
.await
.unwrap_or_else(|err| {
panic!("error on call `wait_for_in_block`: {:?}", err);
panic!("error on call `wait_for_in_block`: {err:?}");
})
.fetch_events()
.await
.unwrap_or_else(|err| {
panic!("error on call `fetch_events`: {:?}", err);
panic!("error on call `fetch_events`: {err:?}");
})
}

Expand All @@ -349,10 +346,10 @@ where
.request("state_call", params)
.await
.unwrap_or_else(|err| {
panic!("error on ws request `upload_code`: {:?}", err);
panic!("error on ws request `upload_code`: {err:?}");
});
scale::Decode::decode(&mut bytes.as_ref())
.unwrap_or_else(|err| panic!("decoding CodeUploadResult failed: {}", err))
.unwrap_or_else(|err| panic!("decoding CodeUploadResult failed: {err}"))
}

/// Submits an extrinsic to upload a given code.
Expand Down Expand Up @@ -389,20 +386,17 @@ where
tx_progress
})
.unwrap_or_else(|err| {
panic!(
"error on call `sign_and_submit_then_watch_default`: {:?}",
err
);
panic!("error on call `sign_and_submit_then_watch_default`: {err:?}");
})
.wait_for_in_block()
.await
.unwrap_or_else(|err| {
panic!("error on call `wait_for_in_block`: {:?}", err);
panic!("error on call `wait_for_in_block`: {err:?}");
})
.fetch_events()
.await
.unwrap_or_else(|err| {
panic!("error on call `fetch_events`: {:?}", err);
panic!("error on call `fetch_events`: {err:?}");
})
}

Expand All @@ -429,10 +423,10 @@ where
.request("state_call", params)
.await
.unwrap_or_else(|err| {
panic!("error on ws request `contracts_call`: {:?}", err);
panic!("error on ws request `contracts_call`: {err:?}");
});
scale::Decode::decode(&mut bytes.as_ref())
.unwrap_or_else(|err| panic!("decoding ContractExecResult failed: {}", err))
.unwrap_or_else(|err| panic!("decoding ContractExecResult failed: {err}"))
}

/// Submits an extrinsic to call a contract with the given parameters.
Expand Down Expand Up @@ -474,20 +468,17 @@ where
tx_progress
})
.unwrap_or_else(|err| {
panic!(
"error on call `sign_and_submit_then_watch_default`: {:?}",
err
);
panic!("error on call `sign_and_submit_then_watch_default`: {err:?}");
})
.wait_for_in_block()
.await
.unwrap_or_else(|err| {
panic!("error on call `wait_for_in_block`: {:?}", err);
panic!("error on call `wait_for_in_block`: {err:?}");
})
.fetch_events()
.await
.unwrap_or_else(|err| {
panic!("error on call `fetch_events`: {:?}", err);
panic!("error on call `fetch_events`: {err:?}");
})
}
}
Loading

0 comments on commit 48d7fed

Please sign in to comment.