diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fdf2d01cb..5e0f3f6cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -203,4 +203,6 @@ jobs: # Build with linting cargo run --profile debug-ci -- contract build --lint --manifest-path=${{ runner.temp }}/foobar/Cargo.toml && cargo run --profile debug-ci -- contract check --manifest-path=${{ runner.temp }}/foobar/Cargo.toml && - cargo run --profile debug-ci -- contract build --manifest-path=${{ runner.temp }}/foobar/Cargo.toml --release + cargo run --profile debug-ci -- contract build --manifest-path=${{ runner.temp }}/foobar/Cargo.toml --release && + # Run tests + cargo test --profile debug-ci --all-features -- --test-threads=1 diff --git a/CHANGELOG.md b/CHANGELOG.md index d3677ee14..333501c36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +Fix e2e tests in the contract template - [#1537](https://github.com/paritytech/cargo-contract/pull/1537) + ## [4.0.0] This `cargo-contract` release is compatible with Rust versions `>=1.70`and ink! versions `>=5.0.0` diff --git a/crates/build/templates/new/_Cargo.toml b/crates/build/templates/new/_Cargo.toml index 202e87c10..295c46171 100644 --- a/crates/build/templates/new/_Cargo.toml +++ b/crates/build/templates/new/_Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" [dependencies] ink = { version = "5.0.0", default-features = false } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } -scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } +[dev-dependencies] +ink_e2e = { version = "5.0.0" } [lib] path = "lib.rs" @@ -17,8 +17,6 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", - "scale/std", - "scale-info/std", ] ink-as-dependency = [] e2e-tests = [] diff --git a/crates/build/templates/new/lib.rs b/crates/build/templates/new/lib.rs index 3d4e6e60b..525f2a612 100644 --- a/crates/build/templates/new/lib.rs +++ b/crates/build/templates/new/lib.rs @@ -79,7 +79,7 @@ mod {{name}} { use super::*; /// A helper function used for calling contract messages. - use ink_e2e::build_message; + use ink_e2e::ContractsBackend; /// The End-to-End test `Result` type. type E2EResult = std::result::Result>; @@ -88,19 +88,19 @@ mod {{name}} { #[ink_e2e::test] async fn default_works(mut client: ink_e2e::Client) -> E2EResult<()> { // Given - let constructor = {{camel_name}}Ref::default(); + let mut constructor = {{camel_name}}Ref::default(); // When - let contract_account_id = client - .instantiate("{{name}}", &ink_e2e::alice(), constructor, 0, None) + let contract = client + .instantiate("{{name}}", &ink_e2e::alice(), &mut constructor) + .submit() .await - .expect("instantiate failed") - .account_id; + .expect("instantiate failed"); + let call_builder = contract.call_builder::<{{camel_name}}>(); // Then - let get = build_message::<{{camel_name}}Ref>(contract_account_id.clone()) - .call(|{{name}}| {{name}}.get()); - let get_result = client.call_dry_run(&ink_e2e::alice(), &get, 0, None).await; + let get = call_builder.get(); + let get_result = client.call(&ink_e2e::alice(), &get).dry_run().await?; assert!(matches!(get_result.return_value(), false)); Ok(()) @@ -110,30 +110,29 @@ mod {{name}} { #[ink_e2e::test] async fn it_works(mut client: ink_e2e::Client) -> E2EResult<()> { // Given - let constructor = {{camel_name}}Ref::new(false); - let contract_account_id = client - .instantiate("{{name}}", &ink_e2e::bob(), constructor, 0, None) + let mut constructor = {{camel_name}}Ref::new(false); + let contract = client + .instantiate("{{name}}", &ink_e2e::bob(), &mut constructor) + .submit() .await - .expect("instantiate failed") - .account_id; + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::<{{camel_name}}>(); - let get = build_message::<{{camel_name}}Ref>(contract_account_id.clone()) - .call(|{{name}}| {{name}}.get()); - let get_result = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; + let get = call_builder.get(); + let get_result = client.call(&ink_e2e::bob(), &get).dry_run().await?; assert!(matches!(get_result.return_value(), false)); // When - let flip = build_message::<{{camel_name}}Ref>(contract_account_id.clone()) - .call(|{{name}}| {{name}}.flip()); + let flip = call_builder.flip(); let _flip_result = client - .call(&ink_e2e::bob(), flip, 0, None) + .call(&ink_e2e::bob(), &flip) + .submit() .await .expect("flip failed"); // Then - let get = build_message::<{{camel_name}}Ref>(contract_account_id.clone()) - .call(|{{name}}| {{name}}.get()); - let get_result = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; + let get = call_builder.get(); + let get_result = client.call(&ink_e2e::bob(), &get).dry_run().await?; assert!(matches!(get_result.return_value(), true)); Ok(())