5

I have two ink! contracts and one of those contracts is making calls to the other one using a CallBuilder.

I want to test that with e2e ink! tests and I am running into a problem.

For reference, one of the contracts is called Identity while the other one is called AddressBook.

The AddressBook contract is calling the Identity contract. The e2e test is in the AddressBook contract code.

The following e2e successfully compiles as far as there are no events in the AddressBook contract:

#[cfg(all(test, feature = "e2e-tests"))]
mod e2e_tests {
    use super::AddressBookRef;
    use ink_e2e::build_message;
    use identity::IdentityRef;

    type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

    #[ink_e2e::test]
    async fn add_identity_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
        let identity_constructor = IdentityRef::new();

        let identity_acc_id = client
            .instantiate("identity", &ink_e2e::alice(), identity_constructor, 0, None)
            .await
            .expect("instantiate failed")
            .account_id;

        Ok(())
    }
}

When events are defined in the address book contract I get the following error:

error[E0284]: type annotations needed
   --> contracts/address-book/lib.rs:116:15
    |
116 |             self.env().emit_event(AddressBookCreated { owner: caller });
    |                        ^^^^^^^^^^
    |
    = note: cannot satisfy `<_ as ContractEventBase>::Type == _`
help: try using a fully qualified path to specify the expected types
    |
116 |             <EnvAccess<'_, DefaultEnvironment> as EmitEvent<C>>::emit_event::<address_book::AddressBookCreated>(self.env(), AddressBookCreated { owner: caller });
    |             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++          ~

error[E0283]: type annotations needed
   --> contracts/address-book/lib.rs:116:15
    |
116 |             self.env().emit_event(AddressBookCreated { owner: caller });
    |                        ^^^^^^^^^^
    |
note: multiple `impl`s satisfying `EnvAccess<'_, DefaultEnvironment>: EmitEvent<_>` found
   --> contracts/address-book/lib.rs:33:1
    |
33  | #[ink::contract]
    | ^^^^^^^^^^^^^^^^
    = note: and another `impl` found in the `identity` crate: `impl<'a> EmitEvent<identity::Identity> for EnvAccess<'a, <identity::Identity as ContractEnv>::Env>;`
    = note: this error originates in the attribute macro `ink::contract` (in Nightly builds, run with -Z macro-backtrace for more info)
help: try using a fully qualified path to specify the expected types
    |
116 |             <EnvAccess<'_, DefaultEnvironment> as EmitEvent<C>>::emit_event::<address_book::AddressBookCreated>(self.env(), AddressBookCreated { owner: caller });
    |             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++          ~

How can I fix this?

0

1 Answer 1

1

See answer in this post. It should help.

Use

<EnvAccess<'_, DefaultEnvironment> as EmitEvent<C>>::emit_event::<address_book::AddressBookCreated>(self.env(), AddressBookCreated { owner: caller });

instead of

self.env().emit_event(AddressBookCreated { owner: caller });

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.