Hello! I have seen a lot of examples of the usage of require_auth.
Let's use soroban-examples/token as an example. We have:
fn set_admin(e: Env, new_admin: Address) {
let admin = read_administrator(&e);
admin.require_auth();
write_administrator(&e, &new_admin);
event::set_admin(&e, admin, new_admin);
}
This function will only be sucsesfull if it was the admin itself that called the set_admin function.
The only way that I see that this is being tested, is checking at the recorded_top_authorizations like this:
token.set_admin(&admin2);
assert_eq!(
e.recorded_top_authorizations(),
std::vec![(
admin1.clone(),
token.contract_id.clone(),
Symbol::short("set_admin"),
(&admin2,).into_val(&e),
)]
);
However this does not tests the case where a fake_admin tries to call the set_admin function.
I expect to do something like this:
#[test]
#[should_panic(expected = "NOT ADMIN")]
fn set_admin_deauthorized() {
let e: Env = Default::default();
let fake_admin = Address::random(&e);
FROM(fake_admin).token.set_admin(&admin2);
}
In solidity this is like this:
await expect(token.connect(other).set_admin(other.address)).to.be.revertedWith('NOT_ADMIN')
How can we test this in rust and the soroban SDK?
Thanks!