-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the access control feature for Paltalabs #63
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
When I connect to the front with the admin wallet, it works as expected. when I connect with another wallet, frontend does not change. I am able to send the transaction, and it says success but the title is not changed. That means, contract is good, but the frontend could be improved to make the user understand why title is not changed, or to not let the user change the title if it connects with another wallet that's not the one set at initialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally code is correct.
I will check frontend now.
However, there is no way to add authorized users as requested in the challenge. Please add that
// This function should be called once when the contract is deployed | ||
pub fn init(env: Env, admin: Address, title: String) { | ||
if env.storage().instance().has(&AdminInfo::Initialized) { | ||
panic!("contract already initilized") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good contracts do not panic but return Errors
// Set the admin title | ||
env.storage().instance().set(&AdminInfo::Title, &title); | ||
env.events() | ||
.publish(("AccessControl", symbol_short!("set")), title); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to have events :)
|
||
// Set the admin title | ||
pub fn set_title(env: Env, title: String) { | ||
let admin: Address = env.storage().instance().get(&AdminInfo::Admin).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this unwrap would panic, better to return error
#[test] | ||
fn test_set_title_by_owner() { | ||
let env = Env::default(); | ||
env.mock_all_auths(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is working because you are mocking all auths
// Check the authorization, should failed | ||
let new_admin_title = String::from_str(&env, "new_admin_title"); | ||
let result = client.try_set_title(&new_admin_title); | ||
assert!(result.is_err()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is returning erros because auths where not mocked.
You need to choose, or do all tests mocking all auths or not
let user_title = String::from_str(&env, "user_title"); | ||
client.set_title(&user_title); | ||
assert_eq!( | ||
env.auths(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this is the way
No description provided.