1

Hi guys I'm new to Rust and new to ink!, so please bear with me if I asked some silly questions.

My code is here. It comprises of an ERC20 contract and a main contract which contains some function that will change the state of the ERC20. Different from the delegator example which initialized add/subber/accumulator from codehash, my one will initialize the ERC20 by its accountID. I'm wondering whether ink-e2e allows me to test ERC20 approve/transfer from the main contract and methods in main contract that will trigger some methods in ERC20? I did following attempts in my code but failed.

image1 image2

When I run cargo test --features e2e-tests I got the following errors:

error[E0599]: the function or associated item `new` exists for struct `Client<WithExtrinsicParams<ink_e2e::SubstrateConfig, BaseExtrinsicParams<ink_e2e::SubstrateConfig, PlainTip>>, DefaultEnvironment>`, but its trait bounds were not satisfied
   --> lib.rs:99:9
    |
99  | /         #[ink_e2e::test(
100 | |             additional_contracts = "erc20/Cargo.toml"
101 | |         )]
    | |__________^ function or associated item cannot be called on `Client<WithExtrinsicParams<ink_e2e::SubstrateConfig, BaseExtrinsicParams<ink_e2e::SubstrateConfig, PlainTip>>, DefaultEnvironment>` due to unsatisfied trait bounds
    |
   ::: /Users/angie/.cargo/registry/src/github.com-1ecc6299db9ec823/ink_env-4.0.0-beta/src/types.rs:172:1
    |
172 |   pub enum DefaultEnvironment {}
    |   --------------------------- doesn't satisfy `DefaultEnvironment: ink_env::types::Environment`
    |
   ::: /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/xts.rs:69:1
    |
69  |   pub struct Call<E: Environment, B> {
    |   ---------------------------------- doesn't satisfy `ink_e2e::xts::Call<DefaultEnvironment, _>: Encode`
    |
    = note: the following trait bounds were not satisfied:
            `DefaultEnvironment: ink_env::types::Environment`
            `ink_e2e::xts::Call<DefaultEnvironment, _>: Encode`
    = note: this error originates in the attribute macro `ink_e2e::test` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `DefaultEnvironment: ink_env::types::Environment` is not satisfied
   --> lib.rs:99:9
    |
99  | /         #[ink_e2e::test(
100 | |             additional_contracts = "erc20/Cargo.toml"
101 | |         )]
    | |__________^ the trait `ink_env::types::Environment` is not implemented for `DefaultEnvironment`
    |
    = help: the trait `ink_env::types::Environment` is implemented for `ink_env::types::DefaultEnvironment`
note: required by a bound in `Client`
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/client.rs:249:8
    |
249 |     E: Environment,
    |        ^^^^^^^^^^^ required by this bound in `Client`
    = note: this error originates in the attribute macro `ink_e2e::test` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
   --> lib.rs:120:17
    |
118 |             let test_constructor = TestErcRef::new(
    |                                    --------------- arguments to this function are incorrect
119 |                 erc20_acc_id,
120 |                 ink_e2e::alice()
    |                 ^^^^^^^^^^^^^^^^ expected struct `ink::ink_primitives::AccountId`, found struct `PairSigner`
    |
    = note: expected struct `ink::ink_primitives::AccountId`
               found struct `PairSigner<_, ink_e2e::subxt::ext::sp_core::sr25519::Pair>`
note: associated function defined here
   --> lib.rs:45:16
    |
4   | #[ink::contract]
    | ----------------
...
45  |         pub fn new(
    |                ^^^

error[E0277]: the trait bound `Erc20Ref: ink::codegen::trait_def::call_builder::TraitCallBuilder` is not satisfied
   --> lib.rs:133:43
    |
133 |             let approve = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                                           ^^^^^^^^ the trait `ink::codegen::trait_def::call_builder::TraitCallBuilder` is not implemented for `Erc20Ref`
    |
note: required by a bound in `build_message`
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:93:10
    |
93  |     Ref: TraitCallBuilder + FromAccountId<ink_env::DefaultEnvironment>,
    |          ^^^^^^^^^^^^^^^^ required by this bound in `build_message`

error[E0277]: the trait bound `Erc20Ref: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>` is not satisfied
   --> lib.rs:133:43
    |
133 |             let approve = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                                           ^^^^^^^^ the trait `ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>` is not implemented for `Erc20Ref`
    |
note: required by a bound in `build_message`
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:93:29
    |
93  |     Ref: TraitCallBuilder + FromAccountId<ink_env::DefaultEnvironment>,
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `build_message`

error[E0308]: mismatched types
   --> lib.rs:133:53
    |
133 |             let approve = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                           ------------------------- ^^^^^^^^^^^^^^^^^^^^ expected struct `ink_primitives::types::AccountId`, found struct `ink::ink_primitives::AccountId`
    |                           |
    |                           arguments to this function are incorrect
    |
    = note: perhaps two different versions of crate `ink_primitives` are being used?
note: function defined here
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:89:8
    |
89  | pub fn build_message<Ref>(
    |        ^^^^^^^^^^^^^

error[E0599]: the method `call` exists for struct `MessageBuilder<ink_env::types::DefaultEnvironment, Erc20Ref>`, but its trait bounds were not satisfied
   --> lib.rs:134:18
    |
134 |                 .call(|contract| contract.approve(test_acc_id,  10_000));
    |                  ^^^^ method cannot be called on `MessageBuilder<ink_env::types::DefaultEnvironment, Erc20Ref>` due to unsatisfied trait bounds
    |
   ::: /Users/angie/Documents/CherryBooooooom/InteractWithErc20/erc20/lib.rs:13:5
    |
13  |     /// A simple ERC-20 contract.
    |     -----------------------------
    |     |
    |     doesn't satisfy `_: ink::codegen::trait_def::call_builder::TraitCallBuilder`
    |     doesn't satisfy `_: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>`
    |
    = note: the following trait bounds were not satisfied:
            `Erc20Ref: ink::codegen::trait_def::call_builder::TraitCallBuilder`
            `Erc20Ref: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>`

error[E0277]: the trait bound `Erc20Ref: ink::codegen::trait_def::call_builder::TraitCallBuilder` is not satisfied
   --> lib.rs:142:44
    |
142 |             let transfer = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                                            ^^^^^^^^ the trait `ink::codegen::trait_def::call_builder::TraitCallBuilder` is not implemented for `Erc20Ref`
    |
note: required by a bound in `build_message`
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:93:10
    |
93  |     Ref: TraitCallBuilder + FromAccountId<ink_env::DefaultEnvironment>,
    |          ^^^^^^^^^^^^^^^^ required by this bound in `build_message`

error[E0277]: the trait bound `Erc20Ref: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>` is not satisfied
   --> lib.rs:142:44
    |
142 |             let transfer = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                                            ^^^^^^^^ the trait `ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>` is not implemented for `Erc20Ref`
    |
note: required by a bound in `build_message`
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:93:29
    |
93  |     Ref: TraitCallBuilder + FromAccountId<ink_env::DefaultEnvironment>,
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `build_message`

error[E0308]: mismatched types
   --> lib.rs:142:54
    |
142 |             let transfer = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                            ------------------------- ^^^^^^^^^^^^^^^^^^^^ expected struct `ink_primitives::types::AccountId`, found struct `ink::ink_primitives::AccountId`
    |                            |
    |                            arguments to this function are incorrect
    |
    = note: perhaps two different versions of crate `ink_primitives` are being used?
note: function defined here
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:89:8
    |
89  | pub fn build_message<Ref>(
    |        ^^^^^^^^^^^^^

error[E0599]: the method `call` exists for struct `MessageBuilder<ink_env::types::DefaultEnvironment, Erc20Ref>`, but its trait bounds were not satisfied
   --> lib.rs:143:18
    |
143 |                 .call(|contract| contract.transfer(ink_e2e::bob(),  2_000));
    |                  ^^^^ method cannot be called on `MessageBuilder<ink_env::types::DefaultEnvironment, Erc20Ref>` due to unsatisfied trait bounds
    |
   ::: /Users/angie/Documents/CherryBooooooom/InteractWithErc20/erc20/lib.rs:13:5
    |
13  |     /// A simple ERC-20 contract.
    |     -----------------------------
    |     |
    |     doesn't satisfy `_: ink::codegen::trait_def::call_builder::TraitCallBuilder`
    |     doesn't satisfy `_: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>`
    |
    = note: the following trait bounds were not satisfied:
            `Erc20Ref: ink::codegen::trait_def::call_builder::TraitCallBuilder`
            `Erc20Ref: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>`

error[E0277]: the trait bound `Erc20Ref: ink::codegen::trait_def::call_builder::TraitCallBuilder` is not satisfied
   --> lib.rs:150:46
    |
150 |             let balance_of = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                                              ^^^^^^^^ the trait `ink::codegen::trait_def::call_builder::TraitCallBuilder` is not implemented for `Erc20Ref`
    |
note: required by a bound in `build_message`
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:93:10
    |
93  |     Ref: TraitCallBuilder + FromAccountId<ink_env::DefaultEnvironment>,
    |          ^^^^^^^^^^^^^^^^ required by this bound in `build_message`

error[E0277]: the trait bound `Erc20Ref: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>` is not satisfied
   --> lib.rs:150:46
    |
150 |             let balance_of = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                                              ^^^^^^^^ the trait `ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>` is not implemented for `Erc20Ref`
    |
note: required by a bound in `build_message`
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:93:29
    |
93  |     Ref: TraitCallBuilder + FromAccountId<ink_env::DefaultEnvironment>,
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `build_message`

error[E0308]: mismatched types
   --> lib.rs:150:56
    |
150 |             let balance_of = build_message::<Erc20Ref>(erc20_acc_id.clone())
    |                              ------------------------- ^^^^^^^^^^^^^^^^^^^^ expected struct `ink_primitives::types::AccountId`, found struct `ink::ink_primitives::AccountId`
    |                              |
    |                              arguments to this function are incorrect
    |
    = note: perhaps two different versions of crate `ink_primitives` are being used?
note: function defined here
   --> /Users/angie/.cargo/git/checkouts/ink-1add513eda8f5a89/fc543da/crates/e2e/src/builders.rs:89:8
    |
89  | pub fn build_message<Ref>(
    |        ^^^^^^^^^^^^^

error[E0599]: the method `call` exists for struct `MessageBuilder<ink_env::types::DefaultEnvironment, Erc20Ref>`, but its trait bounds were not satisfied
   --> lib.rs:151:14
    |
151 |             .call(|contract| contract.balance_of(ink_e2e::bob()));
    |              ^^^^ method cannot be called on `MessageBuilder<ink_env::types::DefaultEnvironment, Erc20Ref>` due to unsatisfied trait bounds
    |
   ::: /Users/angie/Documents/CherryBooooooom/InteractWithErc20/erc20/lib.rs:13:5
    |
13  |     /// A simple ERC-20 contract.
    |     -----------------------------
    |     |
    |     doesn't satisfy `_: ink::codegen::trait_def::call_builder::TraitCallBuilder`
    |     doesn't satisfy `_: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>`
    |
    = note: the following trait bounds were not satisfied:
            `Erc20Ref: ink::codegen::trait_def::call_builder::TraitCallBuilder`
            `Erc20Ref: ink_env::call::create_builder::FromAccountId<ink_env::types::DefaultEnvironment>`

Some errors have detailed explanations: E0277, E0308, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `testerc` due to 15 previous errors

Could anyone help? Thanks!

6
  • while testing your code, did you get any error?
    – go11li
    Commented Dec 30, 2022 at 2:43
  • Hello @Ganesh11 yes, my tests were failed
    – Hikari
    Commented Dec 30, 2022 at 4:06
  • can you please show you error?
    – go11li
    Commented Dec 30, 2022 at 5:01
  • Hi @Ganesh11 I've updated with errors, cheers
    – Hikari
    Commented Dec 30, 2022 at 6:39
  • From just an overview it seems the main issue is you didnt specify which ink enviroment are u using. Just use the DefaultEnviroment Commented Jan 2, 2023 at 13:40

1 Answer 1

2

Here's the diff for how to get your tests compiling. It's not pretty and I'll create a GitHub issue to make the API easier to use.

diff --git a/Cargo.toml b/Cargo.toml
index 09c8226..4127137 100755
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Angie Sheng"]
 edition = "2021"
 
 [dependencies]
-ink = { version = "4.0.0-beta", default-features = false }
+ink = { version = "4.0", default-features = false }
 
 scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
 scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }
@@ -28,7 +28,7 @@ overflow-checks = false
 overflow-checks = false
 
 [dev-dependencies]
-ink_e2e = { git = "https://github.com/paritytech/ink", version = "4.0.0-beta" }
+ink_e2e = { version = "4.0" }
 
 [features]
 default = ["std"]
diff --git a/lib.rs b/lib.rs
index e168a9a..d0d4c87 100755
--- a/lib.rs
+++ b/lib.rs
@@ -90,6 +90,7 @@ mod test_erc {
     
     #[cfg(all(test, feature = "e2e-tests"))]
     mod e2e_tests {
+        use ink::primitives::AccountId;
         use super::TestErcRef;
         use erc20::Erc20Ref;
         use ink_e2e::build_message;
@@ -115,12 +116,14 @@ mod test_erc {
 
             // let official being alice, 
             // erc20 was instantiated by its accountid
+            let alice = ink_e2e::alice::<ink_e2e::PolkadotConfig>();
+            let alice_account_id_32 = alice.account_id();
             let test_constructor = TestErcRef::new(
                 erc20_acc_id,
-                ink_e2e::alice()
+                AccountId::try_from(alice_account_id_32.as_ref()).unwrap()
             );
 
-            // initiate testerc20 by alice 
+            // initiate testerc20 by alice
             let test_acc_id = client
                 .instantiate("testerc20", &mut ink_e2e::alice(), test_constructor, 0, None)
                 .await
@@ -139,8 +142,11 @@ mod test_erc {
 
             // test erc20 transfer
             // transfer 2,000 to Bob
+            let bob = ink_e2e::alice::<ink_e2e::PolkadotConfig>();
+            let bob_account_id_32 = bob.account_id();
+            let bob_account_id = AccountId::try_from(bob_account_id_32.as_ref()).unwrap();
             let transfer = build_message::<Erc20Ref>(erc20_acc_id.clone())
-                .call(|contract| contract.transfer(ink_e2e::bob(),  2_000));
+                .call(|contract| contract.transfer(bob_account_id,  2_000));
 
             // Alice transfers 2,000 to Bob
             let transfer_res = client.call(&mut ink_e2e::alice(), transfer, 0, None).await;
@@ -148,14 +154,12 @@ mod test_erc {
  
             //check Bob's balance after the transfer
             let balance_of = build_message::<Erc20Ref>(erc20_acc_id.clone())
-            .call(|contract| contract.balance_of(ink_e2e::bob()));
+            .call(|contract| contract.balance_of(bob_account_id));
 
-            let balance_of_result = client
-            .call(&mut ink_e2e::charlie(), balance_of, 0, None)
+            let balance_of_bob = client
+            .call_dry_run(&mut ink_e2e::charlie(), &balance_of, 0, None)
             .await
-            .expect("Calling `balance_of` failed");
-
-            let balance_of_bob = balance_of.value.expect("Input is valid, call must not fail.");
+            .return_value();
 
             // check whether the balance of bob is equal to 2000 or not
             assert_eq!(balance_of_bob, 2000);
1
  • Hi @cmichi! Thank you for the answer! Could you elaborate a bit more on the underlying reason for it? Is it that ink_e2e accounts (::alice()) are somehow different? Why the PolkadotConfig?
    – stano
    Commented Apr 5, 2023 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.