Skip to content

Commit

Permalink
Merge branch 'dev' into contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
raizo07 authored Oct 9, 2024
2 parents b574b6f + 6556f6e commit 263b8e3
Show file tree
Hide file tree
Showing 45 changed files with 3,533 additions and 208 deletions.
96 changes: 55 additions & 41 deletions .github/workflows/contract_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ name: CI

on:
pull_request:
branches:
- dev

push:
branches:
- dev
- main

jobs:
check-lint:
determine-changes:
runs-on: ubuntu-latest
outputs:
contracts_dir: ${{ steps.changes.outputs.contracts_dir }}
steps:
- uses: actions/checkout@v2

Expand All @@ -14,71 +23,76 @@ jobs:
id: changes
with:
filters: |
contracts_dir:
contracts_dir:
- 'contracts/src/**'
- name: Install scarb
if: steps.changes.outputs.contracts_dir == 'true'
run: |
cd contracts
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5
check-lint:
runs-on: ubuntu-latest
needs: determine-changes
steps:
- uses: actions/checkout@v2

- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
if: needs.determine-changes.outputs.contracts_dir == 'true'
with:
scarb-version: "2.6.5"

- name: Run scarb fmt
if: steps.changes.outputs.contracts_dir == 'true'
run: |
cd contracts
scarb fmt
- name: Run Scarb formatting
if: needs.determine-changes.outputs.contracts_dir == 'true'
working-directory: contracts
run: scarb fmt

- name: No changes detected in contracts directory
if: needs.determine-changes.outputs.contracts_dir == 'false'
run: echo "No linting perfomed since no changes have been detected in the contracts directory."

check-contracts-changes:
runs-on: ubuntu-latest
needs: determine-changes
steps:
- uses: actions/checkout@v2

- name: Check for changes
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
contracts_dir:
- 'contracts/src/**'

- name: Install scarb
if: steps.changes.outputs.contracts_dir == 'true'
run: |
cd contracts
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5
uses: software-mansion/setup-scarb@v1
if: needs.determine-changes.outputs.contracts_dir == 'true'
with:
scarb-version: "2.6.5"

- name: Run Scarb check
if: needs.determine-changes.outputs.contracts_dir == 'true'
working-directory: contracts
run: scarb check

- name: Run scarb check
if: steps.changes.outputs.contracts_dir == 'true'
run: |
cd contracts
scarb check
- name: No changes detected in contracts directory
if: needs.determine-changes.outputs.contracts_dir == 'false'
run: echo "No contracts checks done since no changes have been detected in the contracts directory."

run-tests:
runs-on: ubuntu-latest
needs: determine-changes
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Check for changes
uses: dorny/paths-filter@v3
id: changes
- name: Install Scarb
uses: software-mansion/setup-scarb@v1
if: needs.determine-changes.outputs.contracts_dir == 'true'
with:
filters: |
contracts_dir:
- 'contracts/src/**'
scarb-version: "2.6.5"

- name: Install scarb
if: steps.changes.outputs.contracts_dir == 'true'
run: |
cd contracts
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5

- name: Install snfoundry
uses: foundry-rs/setup-snfoundry@v3
if: needs.determine-changes.outputs.contracts_dir == 'true'
with:
starknet-foundry-version: "0.20.1"
starknet-foundry-version: "0.27.0"

- name: Run Cairo tests
if: needs.determine-changes.outputs.contracts_dir == 'true'
id: cairo_tests
run: bash scripts/run_tests.sh

- name: No changes detected in contracts directory
if: needs.determine-changes.outputs.contracts_dir == 'false'
run: echo "No tests were run since no changes have been detected in the contracts directory."
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ You can check the prototype we have in mind and suggest any improvement, if you

- [Figma prototype](https://www.figma.com/design/SCiGViaoPT9UTrT7CsLbAt/Go-Stark-Me?node-id=0-1&t=FUhnIhNcXRIGkQ16-1)

## Contributors

- [EmmanuelAR](https://github.com/EmmanuelAR)
- [adrianvrj](https://github.com/adrianvrj)
- [bitfalt](https://github.com/bitfalt)

## Want to Contribute?

If you are interested in contributing to Go Stark Me, please follow these steps:
Expand Down Expand Up @@ -52,3 +58,5 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
Contributions of any kind welcome!

- [@bitfalt](https://t.me/bitfalt)
63 changes: 53 additions & 10 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
# Go Stark Me - Backend Setup 💻

### Steps to Run the Backend 🥳
## Steps to Run the Backend 🥳

1. **Navigate to the Contracts Directory 🔍**

Ensure you are in the correct directory where the Cairo contracts are stored.

```bash
cd gostarkme/contracts
2. **Compile gostarkme backend 🛠️**
```bash
scarb build
3. **Run gostarkme unit test**
```bash
snforge test
4. **Run code formatter 📝**
```bash
scarb fmt
```

2. **Setup your environment**

- Scarb v2.6.5 : [here](https://docs.swmansion.com/scarb/download.html#install-via-asdf).
```bash
asdf install scarb 2.6.5
```
```bash
asdf global scarb 2.6.5
```
- Starknet Foundry v0.27.0: [here](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html).
```bash
asdf install starknet-foundry 0.27.0
```
```bash
asdf install starknet-foundry 0.27.0
```
3. **Compile Go Stark Me Backend 🛠️**

To build the contracts, run the command:

```bash
scarb build
```

4. **Run Go Stark Me Unit Tests ✅**

To run the unit tests for the contracts, run the following command:

```bash
scarb run test
```
or
```bash
snforge test
```

5. **Run Code Formatter 📝**

To format your contracts, simply run the command:

```bash
scarb fmt
```

## UML Diagram

![UML Class Diagram](https://github.com/user-attachments/assets/479c9296-e3ac-4ad3-bf79-5f458c456a45)
4 changes: 2 additions & 2 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d7

[[package]]
name = "snforge_std"
version = "0.20.1"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.20.1#fea2db8f2b20148cc15ee34b08de12028eb42942"
version = "0.27.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de"
2 changes: 1 addition & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ starknet = "2.6.4"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.20.1" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.27.0" }

[scripts]
test = "snforge test"
Expand Down
1 change: 0 additions & 1 deletion contracts/src/donator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ mod Donator {
fn getLevel(self: @ContractState) -> u32 {
return self.level.read();
}

fn getTotalStarkDonations(self: @ContractState) -> u64 {
return self.total_stark_donations.read();
}
Expand Down
9 changes: 8 additions & 1 deletion contracts/src/donatorManager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use starknet::class_hash::ClassHash;
#[starknet::interface]
pub trait IDonatorManager<TContractState> {
fn newDonator(ref self: TContractState);
fn getOwner(self: @TContractState) -> ContractAddress;
fn getDonatorClassHash(self: @TContractState) -> ClassHash;
fn getDonatorByAddress(self: @TContractState, owner: ContractAddress) -> ContractAddress;
}

Expand Down Expand Up @@ -45,7 +47,6 @@ mod DonatorManager {
impl DonatorManagerImpl of super::IDonatorManager<ContractState> {
fn newDonator(ref self: ContractState) {
let mut calldata = ArrayTrait::<felt252>::new();

calldata.append(get_caller_address().try_into().unwrap());

let (address_0, _) = deploy_syscall(
Expand All @@ -54,6 +55,12 @@ mod DonatorManager {
.unwrap();
self.donators.write(get_caller_address().try_into().unwrap(), address_0);
}
fn getOwner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn getDonatorClassHash(self: @ContractState) -> ClassHash {
return self.donator_class_hash.read();
}
fn getDonatorByAddress(self: @ContractState, owner: ContractAddress) -> ContractAddress {
return self.donators.read(owner);
}
Expand Down
28 changes: 18 additions & 10 deletions contracts/src/fundManager.cairo
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ pub trait IFundManager<TContractState> {
fn newFund(ref self: TContractState, name: felt252, goal: u64);
fn getCurrentId(self: @TContractState) -> u128;
fn getFund(self: @TContractState, id: u128) -> ContractAddress;
fn getOwner(self: @TContractState) -> ContractAddress;
fn getFundClassHash(self: @TContractState) -> ClassHash;
}

#[starknet::contract]
mod FundManager {
// *************************************************************************
// ***************************************************************************************
// IMPORT
// *************************************************************************
// ***************************************************************************************
use core::array::ArrayTrait;
use core::traits::TryInto;
use starknet::ContractAddress;
use starknet::syscalls::deploy_syscall;
use starknet::class_hash::ClassHash;
use starknet::get_caller_address;

// *************************************************************************
// ***************************************************************************************
// STORAGE
// *************************************************************************
// ***************************************************************************************
#[storage]
struct Storage {
owner: ContractAddress,
Expand All @@ -31,19 +33,19 @@ mod FundManager {
fund_class_hash: ClassHash,
}

// *************************************************************************
// ***************************************************************************************
// CONSTRUCTOR
// *************************************************************************
// ***************************************************************************************
#[constructor]
fn constructor(ref self: ContractState, fund_class_hash: felt252) {
self.owner.write(get_caller_address());
self.fund_class_hash.write(fund_class_hash.try_into().unwrap());
self.current_id.write(0);
}

// *************************************************************************
// ***************************************************************************************
// EXTERNALS
// *************************************************************************
// ***************************************************************************************
#[abi(embed_v0)]
impl FundManagerImpl of super::IFundManager<ContractState> {
fn newFund(ref self: ContractState, name: felt252, goal: u64) {
Expand All @@ -56,14 +58,20 @@ mod FundManager {
self.fund_class_hash.read(), 12345, calldata.span(), false
)
.unwrap();
self.funds.write(self.current_id.read(), address_0);
self.current_id.write(self.current_id.read() + 1);
self.funds.write(self.current_id.read(), address_0);
}
fn getCurrentId(self: @ContractState) -> u128 {
return self.current_id.read();
}
fn getFund(self: @ContractState, id: u128) -> ContractAddress {
return self.funds.read(id);
}
fn getOwner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn getFundClassHash(self: @ContractState) -> ClassHash {
return self.fund_class_hash.read();
}
}
}
}
5 changes: 3 additions & 2 deletions contracts/tests/test_donator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ fn OWNER() -> ContractAddress {
}

fn __setup__() -> ContractAddress {
let contract = declare("Donator");
let contract = declare("Donator").unwrap();
let mut calldata: Array<felt252> = array![];
calldata.append_serde(OWNER());
contract.deploy(@calldata).unwrap()
let (address, _) = contract.deploy(@calldata).unwrap();
address
}

// *************************************************************************
Expand Down
Loading

0 comments on commit 263b8e3

Please sign in to comment.