Skip to content

Commit

Permalink
Merge pull request #274 from LazarusAA/test/assert-admins-in-set-name
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianvrj authored Nov 28, 2024
2 parents 6c6fbb0 + dcc4374 commit 0768f34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ pub mod Fund {
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();

assert!(
self.owner.read() == caller || valid_address_1 == caller || valid_address_2 == caller,
self.owner.read() == caller
|| valid_address_1 == caller
|| valid_address_2 == caller,
"You must be an owner or admin to perform this action"
);

Expand Down Expand Up @@ -292,4 +294,4 @@ pub mod Fund {
}
}
}
}
}
13 changes: 12 additions & 1 deletion contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ fn test_set_name_owner() {
assert(new_name == "NEW_NAME", 'Set name method not working');
}

#[test]
#[should_panic(expected: ("You must be an owner or admin to perform this action",))]
fn test_set_name_unauthorized_access() {
let contract_address = _setup_();
let dispatcher = IFundDispatcher { contract_address };
let name = dispatcher.get_name();
assert(name == NAME(), 'Invalid name');

start_cheat_caller_address_global(OTHER_USER());
dispatcher.set_name("UNAUTHORIZED_NAME");
}

#[test]
#[should_panic(expected: ("You must be an owner or admin to perform this action",))]
fn test_set_name_not_admin_or_owner() {
Expand Down Expand Up @@ -589,4 +601,3 @@ fn test_set_contact_handle_success() {
assert(reverted_contact_handle == CONTACT_HANDLE_1(), ' revert ')
}


0 comments on commit 0768f34

Please sign in to comment.