Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Oct 11, 2022
1 parent 177b161 commit 3acea90
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 44 deletions.
100 changes: 61 additions & 39 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl InkE2ETest {
let ws_url = &self.test.config.ws_url();
let node_log = &self.test.config.node_log();
let skip_build = &self.test.config.skip_build();
//let deps = &self.test.config.deps();

// This path will only be used in case `skip_build` is activated
// and no path was specified for it.
Expand All @@ -77,56 +78,69 @@ impl InkE2ETest {
path = metadata_path;
}

let mut metadata_paths: Vec<String> = Vec::new();

if !skip_build.value && contract_path().is_none() {
BUILD_ONCE.call_once(|| {
env_logger::init();
use std::process::{
Command,
Stdio,
};
let output = Command::new("cargo")
// TODO(#xxx) Add possibility of configuring `skip_linting` in attributes.
.args(["+stable", "contract", "build", "--skip-linting", "--output-json"])
.env("RUST_LOG", "")
.stderr(Stdio::inherit())
.output()
.expect("failed to execute `cargo-contract` build process");

log::info!("`cargo-contract` returned status: {}", output.status);
eprintln!("`cargo-contract` returned status: {}", output.status);
log::info!(
"`cargo-contract` stdout: {}",
String::from_utf8_lossy(&output.stdout)
);
eprintln!(
"`cargo-contract` stdout: {}",
String::from_utf8_lossy(&output.stdout)
);
if !output.status.success() {
let arr = ["Cargo.toml", "accumulator/Cargo.toml", "adder/Cargo.toml", "subber/Cargo.toml"];
let mut first = true;
for manifest_path in arr {
log::info!("-------path: {}", manifest_path);
let output = Command::new("cargo")
// TODO(#xxx) Add possibility of configuring `skip_linting` in attributes.
.args(["+stable", "contract", "build", "--skip-linting", "--output-json", &format!("--manifest-path={}", manifest_path)])
.env("RUST_LOG", "")
.stderr(Stdio::inherit())
.output()
.expect("failed to execute `cargo-contract` build process");

log::info!("`cargo-contract` returned status: {}", output.status);
eprintln!("`cargo-contract` returned status: {}", output.status);
log::info!(
"`cargo-contract` stderr: {}",
String::from_utf8_lossy(&output.stderr)
"`cargo-contract` stdout: {}",
String::from_utf8_lossy(&output.stdout)
);
eprintln!(
"`cargo-contract` stdout: {}",
String::from_utf8_lossy(&output.stdout)
);
if !output.status.success() {
log::info!(
"`cargo-contract` stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
eprintln!(
"`cargo-contract` stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
}

assert!(output.status.success());

let json = String::from_utf8_lossy(&output.stdout);
let metadata: serde_json::Value =
serde_json::from_str(&json).expect("cannot convert json to utf8");
let mut dest_metadata =
metadata["metadata_result"]["dest_bundle"].to_string();
dest_metadata = dest_metadata.trim_matches('"').to_string();
path = PathBuf::from(dest_metadata);
log::info!("extracted metadata path: {}", path.display());

metadata_paths.push(path.display().to_string());

if first {
// TODO is this still needed?
CONTRACT_PATH.with(|metadata_path| {
*metadata_path.borrow_mut() = Some(path.clone());
});
first = false;
}
}

assert!(output.status.success());

let json = String::from_utf8_lossy(&output.stdout);
let metadata: serde_json::Value =
serde_json::from_str(&json).expect("cannot convert json to utf8");
let mut dest_metadata =
metadata["metadata_result"]["dest_bundle"].to_string();
dest_metadata = dest_metadata.trim_matches('"').to_string();
path = PathBuf::from(dest_metadata);
log::info!("extracted metadata path: {}", path.display());

CONTRACT_PATH.with(|metadata_path| {
*metadata_path.borrow_mut() = Some(path.clone());
});
});
} else {
BUILD_ONCE.call_once(|| {
Expand All @@ -145,6 +159,16 @@ impl InkE2ETest {
.expect("converting path to str failed");
let path = syn::LitStr::new(os_path, proc_macro2::Span::call_site());

//let arr = ["Cargo.toml", "accumulator/Cargo.toml", "adder/Cargo.toml", "subber/Cargo.toml"];
let meta: Vec<TokenStream2> = metadata_paths.iter().map(|path| {
log::info!("--metadata: {:?}", path);
quote! {
log_info(&format!("=============extracting metadata for {}", #path));
// TODO(#1421) `smart-bench_macro` needs to be forked.
::ink_e2e::smart_bench_macro::contract!(#path);
}
}).collect();

quote! {
#( #attrs )*
#[test]
Expand All @@ -160,9 +184,7 @@ impl InkE2ETest {
::ink_e2e::env_logger::init();
});

log_info("extracting metadata");
// TODO(#1421) `smart-bench_macro` needs to be forked.
::ink_e2e::smart_bench_macro::contract!(#path);
#( #meta )*

log_info("creating new client");

Expand Down
17 changes: 12 additions & 5 deletions examples/delegator/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,31 +127,38 @@ mod delegator {
mod e2e_tests {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::e2e_test(skip_build = true)]
/*
, deps = [
"accumulator/Cargo.toml",
"adder/Cargo.toml",
"subber/Cargo.toml",
]
*/
#[ink_e2e::e2e_test]
async fn e2e_delegator(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
// given
ink_e2e::build!("target/ink/accumulator/accumulator.contract");
//ink_e2e::build!("target/ink/accumulator/accumulator.contract");
let accumulator_hash: ink_e2e::H256 = client
.upload(&mut ink_e2e::alice(), accumulator::PATH, None)
.await
.expect("uploading `accumulator` failed")
.code_hash;

ink_e2e::build!("target/ink/adder/adder.contract");
//ink_e2e::build!("target/ink/adder/adder.contract");
let adder_hash: ink_e2e::H256 = client
.upload(&mut ink_e2e::alice(), adder::PATH, None)
.await
.expect("uploading `adder` failed")
.code_hash;

ink_e2e::build!("target/ink/subber/subber.contract");
//ink_e2e::build!("target/ink/subber/subber.contract");
let subber_hash: ink_e2e::H256 = client
.upload(&mut ink_e2e::alice(), subber::PATH, None)
.await
.expect("uploading `subber` failed")
.code_hash;

ink_e2e::build!("target/ink/delegator.contract");
//ink_e2e::build!("target/ink/delegator.contract");
let constructor = delegator::constructors::new(
1234, // initial value
1337, // salt
Expand Down

0 comments on commit 3acea90

Please sign in to comment.