ink: error: already initialized off-chain environment when using run_test

When trying to run a test with ink_core::env::test::run_test I get the following error:

thread 'multisig_plain::tests::construction_works' panicked at 'encountered already initialized off-chain environment: OffChain(TypedEncoded(AlreadyInitialized { initialized_id: TypeId { t: 596591791173715099 }, new_id: TypeId { t: 596591791173715099 } }))', lib.rs:46:1

This example is taken from this PR.

mod tests {
        use super::*;
        use ink_core::env::test;
        type Accounts = test::DefaultAccounts<MyEnv>;

        #[test]
        fn construction_works() {
            test::run_test(|accounts: Accounts| {
                MultisigPlain::new(
                    ink_prelude::vec![accounts.alice, accounts.bob, accounts.eve],
                    2,
                );
                Ok(())
            })
            .unwrap();
        }
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 29 (4 by maintainers)

Most upvoted comments

I agree. It seems to be a very surprising thing if even you are surprised.