Skip to content

Commit

Permalink
Minor refactors in e2e crate (#1830)
Browse files Browse the repository at this point in the history
* Remove `whitelisted_attributes` from E2EConfig

* Simplify building control

* Remove unnecessary configs

* Fix initializing tracing

* Reexport config

* Codec version in ui tests

* Bump codec version

* Revert codegen changes
  • Loading branch information
pmikolajczyk41 committed Jul 3, 2023
1 parent 1909b8b commit 9fcfc46
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 64 deletions.
39 changes: 2 additions & 37 deletions crates/e2e/macro/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
use ink_ir::{
ast,
format_err_spanned,
utils::{
duplicate_config_err,
WhitelistedAttributes,
},
utils::duplicate_config_err,
};

/// The End-to-End test configuration.
#[derive(Debug, Default, PartialEq, Eq)]
pub struct E2EConfig {
/// The set of attributes that can be passed to call builder in the codegen.
whitelisted_attributes: WhitelistedAttributes,
/// Additional contracts that have to be built before executing the test.
additional_contracts: Vec<String>,
/// The [`Environment`](https://docs.rs/ink_env/4.1.0/ink_env/trait.Environment.html) to use
Expand All @@ -41,14 +36,11 @@ impl TryFrom<ast::AttributeArgs> for E2EConfig {
type Error = syn::Error;

fn try_from(args: ast::AttributeArgs) -> Result<Self, Self::Error> {
let mut whitelisted_attributes = WhitelistedAttributes::default();
let mut additional_contracts: Option<(syn::LitStr, ast::MetaNameValue)> = None;
let mut environment: Option<(syn::Path, ast::MetaNameValue)> = None;

for arg in args.into_iter() {
if arg.name.is_ident("keep_attr") {
whitelisted_attributes.parse_arg_value(&arg)?;
} else if arg.name.is_ident("additional_contracts") {
if arg.name.is_ident("additional_contracts") {
if let Some((_, ast)) = additional_contracts {
return Err(duplicate_config_err(
ast,
Expand Down Expand Up @@ -91,7 +83,6 @@ impl TryFrom<ast::AttributeArgs> for E2EConfig {

Ok(E2EConfig {
additional_contracts,
whitelisted_attributes,
environment,
})
}
Expand Down Expand Up @@ -197,7 +188,6 @@ mod tests {
environment = crate::CustomEnvironment,
},
Ok(E2EConfig {
whitelisted_attributes: Default::default(),
additional_contracts: vec![
"adder/Cargo.toml".into(),
"flipper/Cargo.toml".into(),
Expand All @@ -206,29 +196,4 @@ mod tests {
}),
);
}

#[test]
fn keep_attr_works() {
let mut attrs = WhitelistedAttributes::default();
attrs.0.insert("foo".to_string(), ());
attrs.0.insert("bar".to_string(), ());
assert_try_from(
syn::parse_quote! {
keep_attr = "foo, bar"
},
Ok(E2EConfig {
whitelisted_attributes: attrs,
additional_contracts: Vec::new(),
environment: None,
}),
)
}

#[test]
fn keep_attr_invalid_value_fails() {
assert_try_from(
syn::parse_quote! { keep_attr = 1u16 },
Err("expected a string with attributes separated by `,`"),
);
}
}
26 changes: 1 addition & 25 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,7 @@ use std::{
};
use xts::ContractsApi;

/// Default set of commonly used types by Substrate runtimes.
#[cfg(feature = "std")]
pub enum SubstrateConfig {}

#[cfg(feature = "std")]
impl subxt::Config for SubstrateConfig {
type Index = u32;
type Hash = sp_core::H256;
type Hasher = subxt::config::substrate::BlakeTwo256;
type AccountId = subxt::config::substrate::AccountId32;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = subxt::config::substrate::SubstrateHeader<
u32,
subxt::config::substrate::BlakeTwo256,
>;
type Signature = sp_runtime::MultiSignature;
type ExtrinsicParams = subxt::config::substrate::SubstrateExtrinsicParams<Self>;
}

/// Default set of commonly used types by Polkadot nodes.
#[cfg(feature = "std")]
pub type PolkadotConfig = subxt::config::WithExtrinsicParams<
SubstrateConfig,
subxt::config::polkadot::PolkadotExtrinsicParams<SubstrateConfig>,
>;
pub use subxt::PolkadotConfig;

/// Signer that is used throughout the E2E testing.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder<DefaultEnvi
= note: the following trait bounds were not satisfied:
`NonCodecType: parity_scale_codec::Decode`
note: the trait `parity_scale_codec::Decode` must be implemented
--> $CARGO/parity-scale-codec-3.6.1/src/codec.rs
--> $CARGO/parity-scale-codec-3.6.3/src/codec.rs
|
| pub trait Decode: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder<E, Set<Call
= note: the following trait bounds were not satisfied:
`NonCodec: parity_scale_codec::Decode`
note: the trait `parity_scale_codec::Decode` must be implemented
--> $CARGO/parity-scale-codec-3.6.1/src/codec.rs
--> $CARGO/parity-scale-codec-3.6.3/src/codec.rs
|
| pub trait Decode: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^

0 comments on commit 9fcfc46

Please sign in to comment.