Skip to content

Commit

Permalink
[ink_e2e] utilize contract-build crate (#1523)
Browse files Browse the repository at this point in the history
* E2E: utilize `contract-build` crate

* Build as debug so we can see the debug messages

* Switch to using `contract-build` master branch

* Add missing flag

* Use released `contract-build` crate

* Manifest path error detail

* Be explicit with ExecuteArgs instead of using defaults

* Fix warning

* Use latest cargo-contract crates

* Pass features
  • Loading branch information
ascjones authored Dec 7, 2022
1 parent fc543da commit bf2de8f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ink = { version = "4.0.0-beta", path = "../ink" }
ink_env = { version = "4.0.0-beta", path = "../env" }
ink_primitives = { version = "4.0.0-beta", path = "../primitives" }

contract-metadata = { version = "2.0.0-beta" }
contract-metadata = { version = "2.0.0-beta.1" }
impl-serde = { version = "0.3.1", default-features = false }
jsonrpsee = { version = "0.16.0", features = ["ws-client"] }
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
Expand Down
3 changes: 2 additions & 1 deletion crates/e2e/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ proc-macro = true

[dependencies]
ink_ir = { version = "4.0.0-beta", path = "../../ink/ir" }
contract-build = "2.0.0-beta.1"
derive_more = "0.99.17"
env_logger = "0.10.0"
log = "0.4.17"
serde_json = "1.0.85"
serde_json = "1.0.89"
syn = "1"
proc-macro2 = "1"
quote = "1"
87 changes: 46 additions & 41 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,47 +174,52 @@ impl InkE2ETest {

/// Builds the contract at `manifest_path`, returns the path to the contract
/// bundle build artifact.
fn build_contract(manifest_path: &str) -> String {
use std::process::{
Command,
Stdio,
fn build_contract(path_to_cargo_toml: &str) -> String {
use contract_build::{
BuildArtifacts,
BuildMode,
ExecuteArgs,
Features,
ManifestPath,
Network,
OptimizationPasses,
OutputType,
UnstableFlags,
Verbosity,
};

let manifest_path = ManifestPath::new(path_to_cargo_toml).unwrap_or_else(|err| {
panic!("Invalid manifest path {}: {}", path_to_cargo_toml, err)
});
let args = ExecuteArgs {
manifest_path,
verbosity: Verbosity::Default,
build_mode: BuildMode::Debug,
features: Features::default(),
network: Network::Online,
build_artifact: BuildArtifacts::All,
unstable_flags: UnstableFlags::default(),
optimization_passes: Some(OptimizationPasses::default()),
keep_debug_symbols: false,
lint: false,
output_type: OutputType::HumanReadable,
skip_wasm_validation: false,
};
let output = Command::new("cargo")
.args([
"+stable",
"contract",
"build",
"--output-json",
&format!("--manifest-path={}", manifest_path),
])
.env("RUST_LOG", "")
.stderr(Stdio::inherit())
.output()
.unwrap_or_else(|err| {
panic!("failed to execute `cargo-contract` build process: {}", err)
});

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

assert!(
output.status.success(),
"contract build for {} failed",
manifest_path
);

let json = String::from_utf8_lossy(&output.stdout);
let metadata: serde_json::Value = serde_json::from_str(&json)
.unwrap_or_else(|err| panic!("cannot convert json to utf8: {}", err));
let dest_metadata = metadata["metadata_result"]["dest_bundle"].to_string();
dest_metadata.trim_matches('"').to_string()
match contract_build::execute(args) {
Ok(build_result) => {
let metadata_result = build_result
.metadata_result
.expect("Metadata artifacts not generated");
metadata_result
.dest_bundle
.canonicalize()
.expect("Invalid dest bundle path")
.to_string_lossy()
.into()
}
Err(err) => {
panic!("contract build for {} failed: {}", path_to_cargo_toml, err)
}
}
}

0 comments on commit bf2de8f

Please sign in to comment.