Skip to content

Commit

Permalink
Merge pull request #270 from ChrisFernandezVivas/test/a-set_contact_h…
Browse files Browse the repository at this point in the history
…andle
  • Loading branch information
adrianvrj authored Nov 26, 2024
2 parents f5900da + 6373a02 commit 21aea84
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,50 @@ fn test_emit_event_donation_withdraw() {
]
);
}


#[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 ')
}


0 comments on commit 21aea84

Please sign in to comment.