Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

apptreeso
Copy link

No description provided.

Copy link

vercel bot commented Aug 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
create-soroban-dapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2024 7:30am
create-soroban-dapp-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2024 7:30am

@chopan123
Copy link
Member

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.

Copy link
Member

@esteblock esteblock left a 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")
Copy link
Member

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);
Copy link
Member

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();
Copy link
Member

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();
Copy link
Member

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());
Copy link
Member

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(),
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants