Hi Team, I have some code looks like:
#[test]
#[should_panic(expected = "HostError: Error(Auth, InvalidAction)")] // Unauthorized
fn transfer_ownership() {
client
.mock_auths(&[MockAuth {
address: &user,
invoke: &MockAuthInvoke {
contract: &contract_id,
fn_name: "transfer_ownership",
args: (&new_owner,).into_val(&env),
sub_invokes: &[],
},
}])
.transfer_ownership(&new_owner);
}
Q1. Can I define the error string "HostError: Error(Auth, InvalidAction)" as a const, so that I can use it for all auth failure test? I tried something like the example below, but it doesn't allow me to use the variable name in the expected section.
const ERROR_STRING: &str = "HostError: Error(Auth, InvalidAction)";
#[should_panic(expected = ERROR_STRING)]
Q2. Can I return a custom-defined error when require_auth() fails, such as Error::Unauthorized, to handle the auth failure more efficiently. If not, is there any future plans to do this?