From 3b6b6521bc9278e2604d79ec01ab405beb46db0b Mon Sep 17 00:00:00 2001 From: Sebastian Salazar Date: Fri, 1 Nov 2024 21:35:19 -0600 Subject: [PATCH 1/2] [fix] solution of a small bug and another method to install scarb and starknet-foundry --- contracts/README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index 3467a71..e512f77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -24,8 +24,29 @@ asdf install starknet-foundry 0.27.0 ``` ```bash - asdf install starknet-foundry 0.27.0 + asdf global starknet-foundry 0.27.0 ``` + **Setup your environment(Different option for macOS)** + + - Scarb v2.6.5 : [here](https://docs.swmansion.com/scarb/download.html#install-via-asdf). + ```bash + curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5 + ``` + Place it in the path: + ```bash + export PATH="$HOME/.local/bin:$PATH" + ``` + It is recommended to restart the terminal. + - Starknet Foundry v0.27.0: [here](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html). + ```bash + curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh -s -- -v 0.27.0 + ``` + Place it in the path: + ```bash + echo 'export PATH="$HOME/.asdf/shims:$HOME/.asdf/bin:$PATH"' >> ~/.zshrc + ``` + ```bash + echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> ~/.zshrc 3. **Compile Go Stark Me Backend 🛠️** To build the contracts, run the command: From 41dcfc4e843f2fbfaadbe23d3074e716811fb819 Mon Sep 17 00:00:00 2001 From: Sebastian Salazar Date: Fri, 1 Nov 2024 21:48:01 -0600 Subject: [PATCH 2/2] [feat] test issued when the fund contract receives a donation --- contracts/tests/test_fund.cairo | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/contracts/tests/test_fund.cairo b/contracts/tests/test_fund.cairo index 0936eed..d90716b 100644 --- a/contracts/tests/test_fund.cairo +++ b/contracts/tests/test_fund.cairo @@ -342,3 +342,55 @@ fn test_withdraw() { assert(owner_balance_after == (owner_balance_before + goal), 'wrong owner balance'); assert((fund_balance_before - goal) == fund_balance_after, 'wrong fund balance'); } + +#[test] +#[fork("Mainnet")] +fn test_emit_event_donation_received() { + //Initial configuration of contract addresses and donation targets + let contract_address = _setup_(); + let goal: u256 = 10; + let dispatcher = IFundDispatcher { contract_address }; + let minter_address = contract_address_const::(); + let token_address = contract_address_const::(); + let token_dispatcher = IERC20Dispatcher { contract_address: token_address }; + + //Donation target configuration in the dispatcher + dispatcher.setState(2); + start_cheat_caller_address(contract_address, FUND_MANAGER()); + dispatcher.setGoal(goal); + + //Provision of STRK token to the fund manager + 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); + let mut spy = spy_events(); + + //Receipt of the donation at the dispatcher + dispatcher.receiveDonation(goal); + start_cheat_caller_address_global(FUND_MANAGER()); + + //Verification of the current balance and issuance of the expected event + let current_balance = dispatcher.get_current_goal_state(); + spy + .assert_emitted( + @array![ + ( + contract_address, + Fund::Event::DonationReceived( + Fund::DonationReceived { + current_balance, + donated_strks: goal, + donator_address: FUND_MANAGER(), + fund_contract_address: contract_address, + } + ) + ) + ] + ); +}