Skip to main content

assert_auth

Macro assert_auth 

Source
macro_rules! assert_auth {
    ($caller:expr, $client:ident . $method:ident ( $($arg:expr),* $(,)? )) => { ... };
}
Expand description

Assert that a contract call with authentication succeeds

This macro is used to test contract calls that require authentication. It mocks the authentication for the specified caller and executes the contract call. If the call fails or doesn’t require the authentication, the macro will panic with an error message.

§Example


#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
   pub fn set_value(env: &Env, caller: Address, value: u32) {
       caller.require_auth();
   }
}


assert_auth!(caller, client.set_value(&caller, &42));