Skip to content

Commit

Permalink
deleting setup_donation function
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoB1911 committed Oct 31, 2024
2 parents 263540a + 72ff78f commit 4c623b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
7 changes: 5 additions & 2 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,16 @@ pub mod Fund {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
assert(self.state.read() == FundStates::CLOSED, 'Fund not close goal yet.');
assert(self.get_current_goal_state() > 0, 'Fund hasnt reached its goal yet');
assert(
self.get_current_goal_state() >= self.getGoal(), 'Fund hasnt reached its goal yet'
);
// Withdraw
let withdrawn_amount = self.get_current_goal_state();
// TODO: Calculate balance to deposit in owner address and in fund manager address (95%
// and 5%), also transfer the amount to fund manager address.
self.token_dispatcher().approve(self.getOwner(), withdrawn_amount);
self.token_dispatcher().transfer(self.getOwner(), withdrawn_amount);
assert(self.get_current_goal_state() >= 0, 'Fund hasnt reached its goal yet');
assert(self.get_current_goal_state() == 0, 'Pending stks to withdraw');
self.setState(4);
self
.emit(
Expand Down
61 changes: 27 additions & 34 deletions contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,6 @@ fn _setup_() -> ContractAddress {
let (contract_address, _) = contract.deploy(@calldata).unwrap();
contract_address
}
fn setup_donation(
dispatcher: IFundDispatcher,
token_dispatcher: IERC20Dispatcher,
contract_address: ContractAddress,
token_address: ContractAddress,
minter_address: ContractAddress,
goal: u256
) {
// Put state as recollecting dons
dispatcher.setState(2);
// Put 10 strks as goal, only fund manager
start_cheat_caller_address(contract_address, FUND_MANAGER());
dispatcher.setGoal(goal);
// fund the manager with STRK token
cheat_caller_address(token_address, minter_address, CheatSpan::TargetCalls(1));
let mut calldata = array![];
calldata.append_serde(FUND_MANAGER());
calldata.append_serde(goal);
call_contract_syscall(token_address, selector!("permissioned_mint"), calldata.span()).unwrap();
// approve
cheat_caller_address(token_address, FUND_MANAGER(), CheatSpan::TargetCalls(1));
token_dispatcher.approve(contract_address, goal);
}
// ***************************************************************************************
// TEST
// ***************************************************************************************
Expand Down Expand Up @@ -171,12 +148,20 @@ fn test_receive_donation_successful() {
let minter_address = contract_address_const::<StarknetConstants::STRK_TOKEN_MINTER_ADDRESS>();
let token_address = contract_address_const::<StarknetConstants::STRK_TOKEN_ADDRESS>();
let token_dispatcher = IERC20Dispatcher { contract_address: token_address };

//Set up donation call
setup_donation(
dispatcher, token_dispatcher, contract_address, token_address, minter_address, goal
);

// Put state as recollecting dons
dispatcher.setState(2);
// Put 10 strks as goal, only fund manager
start_cheat_caller_address(contract_address, FUND_MANAGER());
dispatcher.setGoal(goal);
// fund the manager with STRK token
cheat_caller_address(token_address, minter_address, CheatSpan::TargetCalls(1));
let mut calldata = array![];
calldata.append_serde(FUND_MANAGER());
calldata.append_serde(goal);
call_contract_syscall(token_address, selector!("permissioned_mint"), calldata.span()).unwrap();
// approve
cheat_caller_address(token_address, FUND_MANAGER(), CheatSpan::TargetCalls(1));
token_dispatcher.approve(contract_address, goal);
// Donate 5 strks
dispatcher.receiveDonation(goal / 2);
let current_goal_state = dispatcher.get_current_goal_state();
Expand Down Expand Up @@ -233,24 +218,32 @@ fn test_new_vote_received_event_emitted_successful() {
);
}


#[test]
#[fork("Mainnet")]
fn test_emit_event_donation_withdraw() {
//Set up contract addresses
let contract_address = _setup_();
let goal: u256 = 10;
let strks: u256 = 11;

let dispatcher = IFundDispatcher { contract_address };
let minter_address = contract_address_const::<StarknetConstants::STRK_TOKEN_MINTER_ADDRESS>();
let token_address = contract_address_const::<StarknetConstants::STRK_TOKEN_ADDRESS>();
let token_dispatcher = IERC20Dispatcher { contract_address: token_address };

//Set up donation call
setup_donation(
dispatcher, token_dispatcher, contract_address, token_address, minter_address, goal
);
dispatcher.setState(2);
// Put 10 strks as goal, only fund manager
start_cheat_caller_address(contract_address, FUND_MANAGER());
dispatcher.setGoal(goal);
// fund the manager with STRK token
cheat_caller_address(token_address, minter_address, CheatSpan::TargetCalls(1));
let mut calldata = array![];
calldata.append_serde(FUND_MANAGER());
calldata.append_serde(goal);
call_contract_syscall(token_address, selector!("permissioned_mint"), calldata.span()).unwrap();
// approve
cheat_caller_address(token_address, FUND_MANAGER(), CheatSpan::TargetCalls(1));
token_dispatcher.approve(contract_address, goal);

dispatcher.receiveDonation(goal);

Expand Down

0 comments on commit 4c623b1

Please sign in to comment.