Skip to content

Commit

Permalink
Merge pull request #240 from aguilar1x/feat/209
Browse files Browse the repository at this point in the history
Feat/209
  • Loading branch information
EmmanuelAR authored Nov 13, 2024
2 parents 098ddad + 418d4df commit a86e2d8
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
35 changes: 32 additions & 3 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
```bash
asdf global starknet-foundry 0.27.0
```
**Setup your environment(Different option for macOS)**
**Setup your environment (Different option for macOS)**

- Scarb v2.6.5 : [here](https://docs.swmansion.com/scarb/download.html#install-via-asdf).
```bash
Expand All @@ -37,16 +37,45 @@
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).

**Setup your environment (Ubuntu)**
- Scarb v2.6.5
```bash
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5
```
Run at terminal:
```bash
code ~ /.bashrc
```
Place it at the end of the path/code:
```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:
**Place it in the path (Option for macOS):**
```bash
echo 'export PATH="$HOME/.asdf/shims:$HOME/.asdf/bin:$PATH"' >> ~/.zshrc
```
```bash
echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> ~/.zshrc
```
**Place it in the path (Option for Ubuntu):**
```bash
In the terminal: code ~ /.bashrc
```
Place it at the end of the path/code:
```bash
export PATH="$HOME/.asdf/shims:$HOME/.asdf/bin:$PATH"
```
```bash
export PATH="$HOME/.foundry/bin:$PATH"
```

3. **Compile Go Stark Me Backend 🛠️**

To build the contracts, run the command:
Expand Down
58 changes: 58 additions & 0 deletions contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,61 @@ fn test_set_contact_handle_wrong_owner() {
start_cheat_caller_address_global(OTHER_USER());
IFundDispatcher { contract_address }.set_contact_handle(CONTACT_HANDLE_2());
}

#[test]
#[fork("Mainnet")]
fn test_update_received_donation() {
let contract_address = _setup_();

let mut spy = spy_events();

let strks: u256 = 500 * ONE_E18;

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 };

start_cheat_caller_address(contract_address, VALID_ADDRESS_1());
dispatcher.setState(2);

start_cheat_caller_address(contract_address, FUND_MANAGER());
dispatcher.setGoal(strks);

start_cheat_caller_address(token_address, minter_address);
let mut calldata = array![];
calldata.append_serde(FUND_MANAGER());
calldata.append_serde(strks);
call_contract_syscall(token_address, selector!("permissioned_mint"), calldata.span()).unwrap();
stop_cheat_caller_address(token_address);

assert(token_dispatcher.balance_of(FUND_MANAGER()) == strks, 'invalid balance');

start_cheat_caller_address(token_address, FUND_MANAGER());
token_dispatcher.transfer(contract_address, strks);
stop_cheat_caller_address(token_address);

dispatcher.update_receive_donation(strks);

let current_balance = dispatcher.get_current_goal_state();

assert(dispatcher.getState() == FundStates::CLOSED, 'state is not closed');
assert(current_balance == strks, 'strks not reached');

spy
.assert_emitted(
@array![
(
contract_address,
Fund::Event::DonationReceived(
Fund::DonationReceived {
current_balance,
donated_strks: strks,
donator_address: FUND_MANAGER(),
fund_contract_address: contract_address,
}
)
)
]
);
}

0 comments on commit a86e2d8

Please sign in to comment.