Skip to content

Commit

Permalink
Merge pull request #267 from EmmanuelAR/feat/266
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianvrj authored Nov 25, 2024
2 parents 8762be6 + 5ea3f1b commit aca71ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
18 changes: 8 additions & 10 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 Expand Up @@ -180,8 +179,7 @@ pub mod Fund {
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
assert!(
valid_address_1 == caller || valid_address_2 == caller,
"Only Admins can change the fund state"
valid_address_1 == caller || valid_address_2 == caller, "Only Admins can set goal"
);
self.goal.write(goal);
}
Expand Down
41 changes: 23 additions & 18 deletions contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ fn test_set_goal() {
let dispatcher = IFundDispatcher { contract_address };
let goal = dispatcher.get_goal();
assert(goal == GOAL(), 'Invalid goal');

start_cheat_caller_address_global(VALID_ADDRESS_1());
dispatcher.set_goal(123);
let new_goal = dispatcher.get_goal();
assert(new_goal == 123, 'Set goal method not working')
assert(new_goal == 123, 'Set goal method not working');

start_cheat_caller_address_global(VALID_ADDRESS_2());
dispatcher.set_goal(140);
Expand Down Expand Up @@ -228,7 +228,7 @@ fn test_new_vote_received_event_emitted_successful() {
}

#[test]
#[should_panic(expected: ("Only Admins can change the fund state",))]
#[should_panic(expected: ("Only Admins can set goal",))]
fn test_set_goal_unauthorized() {
let contract_address = _setup_();
let dispatcher = IFundDispatcher { contract_address };
Expand All @@ -253,7 +253,7 @@ fn test_withdraw_with_non_closed_state() {
let contract_address = _setup_();
let fund_dispatcher = IFundDispatcher { contract_address };

start_cheat_caller_address_global(FUND_MANAGER());
start_cheat_caller_address_global(VALID_ADDRESS_1());
// set goal
fund_dispatcher.set_goal(500_u256);

Expand All @@ -278,7 +278,7 @@ fn test_withdraw() {
dispatcher.set_state(2);
stop_cheat_caller_address(contract_address);

start_cheat_caller_address(contract_address, FUND_MANAGER());
start_cheat_caller_address(contract_address, VALID_ADDRESS_1());
dispatcher.set_goal(goal);
stop_cheat_caller_address(contract_address);

Expand Down Expand Up @@ -410,7 +410,7 @@ fn test_update_received_donation() {
start_cheat_caller_address(contract_address, VALID_ADDRESS_1());
dispatcher.set_state(2);

start_cheat_caller_address(contract_address, FUND_MANAGER());
start_cheat_caller_address(contract_address, VALID_ADDRESS_1());
dispatcher.set_goal(strks);

start_cheat_caller_address(token_address, minter_address);
Expand Down Expand Up @@ -442,7 +442,7 @@ fn test_update_received_donation() {
Fund::DonationReceived {
current_balance,
donated_strks: strks,
donator_address: FUND_MANAGER(),
donator_address: VALID_ADDRESS_1(),
fund_contract_address: contract_address,
}
)
Expand All @@ -468,7 +468,7 @@ fn test_emit_event_donation_withdraw() {
start_cheat_caller_address(contract_address, VALID_ADDRESS_1());
dispatcher.set_state(2);

start_cheat_caller_address(contract_address, FUND_MANAGER());
start_cheat_caller_address(contract_address, VALID_ADDRESS_1());
dispatcher.set_goal(goal);

start_cheat_caller_address(token_address, minter_address);
Expand Down Expand Up @@ -497,14 +497,19 @@ 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
}
)
)
]
);
}

0 comments on commit aca71ae

Please sign in to comment.