3

I write tests for my smart contract and got this error:

no caller has been set

The error comes from: ink_engine-4.2.0/src/ext.rs:325:14. In function that I want to write tests I have following line:

let caller = self.env().caller();

Any suggestion what I do wrongly?

I look at the place the error comes from, and I see following code:

/// Returns the address of the caller.
pub fn caller(&self, output: &mut &mut [u8]) {
    let caller = self
        .exec_context
        .caller
        .as_ref()
        .expect("no caller has been set")
        .as_bytes();
    set_output(output, caller);
}
1
  • here are the function needed while writing test in ink! smart contract. You need to set_caller like this
    – go11li
    Commented Jun 8, 2023 at 1:13

1 Answer 1

0

I think that this is not ideal solution, but working.

let _accounts = ink_env::test::default_accounts::<ink_env::DefaultEnvironment>();
let contract_addr: AccountId = AccountId::from([0xFF as u8; 32]);
ink_env::test::set_caller::<ink_env::DefaultEnvironment>(_accounts.alice);

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.