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

Test: Set Contact Handle #259 #270

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ pub mod Fund {
}
fn set_name(ref self: ContractState, name: ByteArray) {
let caller = get_caller_address();
let valid_address_1 = contract_address_const::<
FundManagerConstants::VALID_ADDRESS_1
>();
let valid_address_2 = contract_address_const::<
FundManagerConstants::VALID_ADDRESS_2
>();
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
assert!(
self.owner.read() == caller || valid_address_1 == caller || valid_address_2 == caller,
"You must be an owner or admin to perform this action");
self.owner.read() == caller
|| valid_address_1 == caller
|| valid_address_2 == caller,
"You must be an owner or admin to perform this action"
);
self.name.write(name);
}
fn get_name(self: @ContractState) -> ByteArray {
Expand Down
72 changes: 62 additions & 10 deletions contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,66 @@ fn test_emit_event_donation_withdraw() {

dispatcher.withdraw();

spy.assert_emitted(@array![
(
contract_address,
Fund::Event::DonationWithdraw(Fund::DonationWithdraw {
owner_address: OWNER(),
fund_contract_address: contract_address,
withdrawn_amount
})
)
]);
spy
.assert_emitted(
@array![
(
contract_address,
Fund::Event::DonationWithdraw(
Fund::DonationWithdraw {
owner_address: OWNER(),
fund_contract_address: contract_address,
withdrawn_amount
}
)
)
]
);
}


#[test]
#[should_panic(expected: ("You must be an owner or admin to perform this action",))]
fn test_set_contact_handle_error() {
let contract_address = _setup_();
let dispatcher = IFundDispatcher { contract_address };
let contact_handle = dispatcher.get_contact_handle();
assert(contact_handle == CONTACT_HANDLE_1(), 'Invalid contact handle');

start_cheat_caller_address_global(OTHER_USER());
dispatcher.set_contact_handle(CONTACT_HANDLE_2())
}

#[test]
fn test_set_contact_handle_success() {
let contract_address = _setup_();
let dispatcher = IFundDispatcher { contract_address };
let contact_handle = dispatcher.get_contact_handle();
assert(contact_handle == CONTACT_HANDLE_1(), 'Invalid contact handle');

start_cheat_caller_address_global(OWNER());
dispatcher.set_contact_handle(CONTACT_HANDLE_2());
let new_contact_handle = dispatcher.get_contact_handle();
assert(new_contact_handle == CONTACT_HANDLE_2(), 'Set contact method not working');
dispatcher.set_contact_handle(CONTACT_HANDLE_1());
let reverted_contact_handle = dispatcher.get_contact_handle();
assert(reverted_contact_handle == CONTACT_HANDLE_1(), 'revert');

start_cheat_caller_address_global(VALID_ADDRESS_1());
dispatcher.set_contact_handle(CONTACT_HANDLE_2());
let new_contact_handle = dispatcher.get_contact_handle();
assert(new_contact_handle == CONTACT_HANDLE_2(), 'Set contact method not working');
dispatcher.set_contact_handle(CONTACT_HANDLE_1());
let reverted_contact_handle = dispatcher.get_contact_handle();
assert(reverted_contact_handle == CONTACT_HANDLE_1(), 'revert');

start_cheat_caller_address_global(VALID_ADDRESS_2());
dispatcher.set_contact_handle(CONTACT_HANDLE_2());
let new_contact_handle = dispatcher.get_contact_handle();
assert(new_contact_handle == CONTACT_HANDLE_2(), 'Set contact method not working');
dispatcher.set_contact_handle(CONTACT_HANDLE_1());
let reverted_contact_handle = dispatcher.get_contact_handle();
assert(reverted_contact_handle == CONTACT_HANDLE_1(), ' revert ')
}


Loading