I am trying to detach end-to-end tests from my main contract lib.rs. I created a new module in tests_e2e.rs.

I import the module in main contract like so:

#[cfg(all(test, feature = "e2e-tests"))]
mod tests_e2e;

In the tests_e2e.rs file, I have the usual module defined for ink_e2e tests, but with the obvious addition of the crate import (named ilockmvp):

    pub mod e2e_tests {

        use crate::ilockmvp::*;

        use ink_e2e::{
        use openbrush::contracts::psp22::psp22_external::PSP22;
        use ink::primitives::{

When I build test with cargo +nightly test --features e2e-tests -- --show-output I get this error: error results

When I remove the crate import, no such error occurs, but the obvious error that I need to import things ensues.


How do I work around this? --thoughts/suggestions/insights?

***** I got this working fine for my #[ink::test] unit tests in a different module file (tests_unit.rs).

4 Answers 4


In short:

  1. Create a separate file (e.g. e2e_tests.rs) and move all the code from e2e_tests module there (without mod e2e_tests).
  2. Add these lines on top of e2e_tests.rs file:
use crate::<your_crate_name>::*;

#[cfg(all(test, feature = "e2e-tests"))]
pub use ink_e2e::build_message;
  1. In lib.rs add:
#[cfg(all(test, feature = "e2e-tests"))]
pub mod e2e_tests;


Issue already submitted.

The only solution I have found for now is to save both the file containing the e2e_tests and the one containing the contract with each modification (without performed cargo clean) and this works for me.

  • Ok yeah, the double-save method works for me. Thanks! Apparently the issue has been fixed though? I do not understand how to make their fix apply to my usecase. Commented Mar 2, 2023 at 21:57
  • yes can confirm, now is fixed .
    – balda
    Commented Mar 3, 2023 at 22:18
  • to apply the fix just use the new ink release :)
    – balda
    Commented Mar 3, 2023 at 22:49
  • cargo clean works for me
    – go11li
    Commented Mar 4, 2023 at 5:03

What I have done in this contract is separate ink_e2e test to different folder. You can view in this gh repo. I compiled and it works fine.

  • If you run the e2e tests with your example it gives the same error Commented Feb 28, 2023 at 15:17
  • but I am not getting error look in this image github.com/ganesh1233456/decode-ink-events/blob/main/…
    – go11li
    Commented Feb 28, 2023 at 16:07
  • @Ganesh11 you're running test with stable contract channel. I have to use +nightly because they use this #![feature(min_specialization)]. Your example will pass the same error running with +nightly unfortunately. Also, @DaanvanderPlas, I followed your example to the letter and no luck, same error. I also stripped out everything in the test to that it was just a naked #[ink_e2e::test] instance. I wonder if it is something to do the the +nightly toolchain? My version is 1.69.0-nightly. What are yours'? Commented Feb 28, 2023 at 20:48
  • @blairmunroakusa rustc 1.69.0-nightly (c5c7d2b37 2023-02-24)
    – go11li
    Commented Mar 1, 2023 at 5:35
Steps to recreate problem:
  • Set up tests_e2e.rs module as specified by @DaanvanderPlas answer above. This configuration is correct, but will not necessarily solve the problem once the damage is done.
  • Remove #[cfg(all(test, feature = "e2e-tests"))] from the module file.
  • Attempt to build and run tests with +nightly will fail with OP error message, consisting of the first e2e test failed to generate metadata artifacts, then one 'Once instance has previously been poisoned' message per remaining e2e test.
  • Attempt to replace #[cfg(all(test, feature = "e2e-tests"))] in tests_e2e.rs module file should continue to fail and produce the same set of error messages.
Additional steps (beyond @DaanvanderPlas setup) to solve problem:
  • Delete target directory or cargo clean and build and run test from scratch.

And that's it, should work again.


In @Ganesh11's example repo, building and running test with stable cargo contract v2.0.0 will still succeed if the macro is left out in the tests module file. However, running with +nightly v0.69.0 will fail without the second instance of the ink_e2e macro. And, once it has failed, target will need to be deleted or run cargo clean.

The reason for needing +nightly in this scenario is because Openbrush contracts rely on the #![feature(min_specialization)] macro, which is not supported by the stable toolchain.

  • This issue not only comes up if removing the ink_e2e cfg macro. Any change to the tests_e2e.rs file in general causes this problem, and a cargo clean must be performed.
  • This is a big problem because the build time is so long.

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.