diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..63a75c4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @drspacemn @glihm \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/01_FEATURE_REQUEST.md b/.github/ISSUE_TEMPLATE/01_FEATURE_REQUEST.md new file mode 100644 index 0000000..ff34057 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/01_FEATURE_REQUEST.md @@ -0,0 +1,11 @@ +--- +name: Feature request +about: suggest new feature +title: "[feat] " +labels: "feature" +assignees: "" +--- + + + +#### References diff --git a/.github/ISSUE_TEMPLATE/02_BUG_REPORT.md b/.github/ISSUE_TEMPLATE/02_BUG_REPORT.md new file mode 100644 index 0000000..57a92f1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/02_BUG_REPORT.md @@ -0,0 +1,13 @@ +--- +name: Bug report +about: create bug report +title: "[bug] " +labels: "bug" +assignees: "" +--- + +**ver:** + + + +**How to reproduce:** diff --git a/.github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md b/.github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md new file mode 100644 index 0000000..0132b95 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md @@ -0,0 +1,7 @@ +--- +name: Codebase improvement +about: docs, ci, tooling, other +title: "[dev] " +labels: "dev" +assignees: "" +--- diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..539461b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,8 @@ + + +- [ ] issue # +- [ ] follows contribution [guide](../CONTRIBUTING.md) +- [ ] code change includes tests +- [ ] breaking change + + diff --git a/.github/linter/base_style.rb b/.github/linter/base_style.rb new file mode 100644 index 0000000..8d98105 --- /dev/null +++ b/.github/linter/base_style.rb @@ -0,0 +1,4 @@ +all +# lame rules +exclude_rule 'MD002' +exclude_rule 'MD041' diff --git a/.github/linter/readme_style.rb b/.github/linter/readme_style.rb new file mode 100644 index 0000000..9b6cfc9 --- /dev/null +++ b/.github/linter/readme_style.rb @@ -0,0 +1,10 @@ +all +# allow inline HTML for README fmt +exclude_rule 'MD033' +# badges trigger rule +exclude_rule 'MD034' +# README img serves as 'First Header' +exclude_rule 'MD002' +exclude_rule 'MD041' +# TODO: disable/enable not working for all-contribs +exclude_rule 'MD013' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a46b060 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,18 @@ +name: build + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: +permissions: read-all + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: asdf-vm/actions/install@v3 + - run: scarb fmt --check + - run: scarb build diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..6b0977a --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,26 @@ +name: check + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: +permissions: read-all + +jobs: + markdown: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: | + sudo gem install mdl + mdl -s .github/linter/readme_style.rb README.md + mdl -s .github/linter/base_style.rb book .github + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: asdf-vm/actions/install@v3 + - run: snforge test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85caaf6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Sys files +**/.DS_Store + +# Scarb and Starknet Foundry +**/target +.snfoundry_cache/ + +# Starkli +**/account.json +**/keystore.json diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..4267afd --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +scarb 2.4.4 +starknet-foundry 0.16.0 diff --git a/Contributing.md b/Contributing.md new file mode 100644 index 0000000..4baec02 --- /dev/null +++ b/Contributing.md @@ -0,0 +1,58 @@ +## 🛠️ Contributing to Piltover 🛠️ + +Welcome, contributing to `piltover` is easy! + +1. Submit or comment your intent on an issue +1. We will try to respond quickly +1. Fork this repo +1. Submit your PR against `main` +1. Address PR Review + +### Issue + +Project tracking is done via GitHub [issues](https://github.com/keep-starknet-strange/piltover/issues). +First look at open issues to see if your request is already submitted. +If it is comment on the issue requesting assignment, if not open an issue. + +We use 3 issue labels for development: + +- `feat` -> suggest new feature +- `bug` -> create a reproducible bug report +- `dev` -> non-functional repository changes + +These labels are used as prefixes as follows for `issue`, `branch name`, `pr title`: + +- `[feat]` -> `feat/{issue #}-{issue name}` -> `feat:` +- `[bug]` -> `bug/{issue #}-{issue name}` -> `bug:` +- `[dev]` -> `dev/{issue #}-{issue name}` -> `dev:` + +### Submit PR + +Ensure your code is well formatted, well tested and well documented. A core contributor +will review your work. Address changes, ensure ci passes, +and voilà you're a piltover contributor. + +Markdown [linter](https://github.com/markdownlint/markdownlint?tab=readme-ov-file#markdown-lint-tool): + +```bash +mdl -s .github/linter/readme_style.rb README.md +``` + +Scarb linter: + +```bash +scarb fmt +``` + +### Additional Resources + +- [Cairo Book](https://book.cairo-lang.org/) +- [Starknet Book](https://book.starknet.io/) +- [Starknet Foundry Book](https://foundry-rs.github.io/starknet-foundry/) +- [Starknet By Example](https://starknet-by-example.voyager.online/) +- [Starkli Book](https://book.starkli.rs/) +- [Syncing a Fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) + +## + +Thank you for your contribution! diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..885707a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Keep Starknet Strange + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4bd68c9 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +
+ + + [![Check Workflow Status](https://github.com/keep-starknet-strange/blobstream-starknet/actions/workflows/check.yml/badge.svg)](https://github.com/keep-starknet-strange/blobstream-starknet/actions/workflows/check.yml) + [![Build Workflow Status](https://github.com/keep-starknet-strange/blobstream-starknet/actions/workflows/build.yml/badge.svg)](https://github.com/keep-starknet-strange/blobstream-starknet/actions/workflows/build.yml) + + [![Exploration_Team](https://img.shields.io/badge/Exploration_Team-29296E.svg?&style=for-the-badge&logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJhIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxODEgMTgxIj48ZGVmcz48c3R5bGU+LmJ7ZmlsbDojZmZmO308L3N0eWxlPjwvZGVmcz48cGF0aCBjbGFzcz0iYiIgZD0iTTE3Ni43Niw4OC4xOGwtMzYtMzcuNDNjLTEuMzMtMS40OC0zLjQxLTIuMDQtNS4zMS0xLjQybC0xMC42MiwyLjk4LTEyLjk1LDMuNjNoLjc4YzUuMTQtNC41Ny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bC0xMi45NS0xNC4xMmMtLjY0LS40NS0xLjE0LTEuMDgtMS40Mi0xLjgxbDE5LjA0LDUuMTgsMi41OSwuNzhjMi4wNCwuNzYsNC4zMywuMTQsNS43LTEuNTVsMTIuOTUtMTQuMzhzLjc4LTEuMDQsMS42OC0xLjE3Yy0xLjgxLDYuNi0yLjk4LDE0LjEyLTUuNDQsMjAuNDYtMS4wOCwyLjk2LS4wOCw2LjI4LDIuNDYsOC4xNiw0LjI3LDQuMTQsOC4yOSw4LjU1LDEyLjk1LDEyLjk1LDAsMCwxLjMsLjkxLDEuNDIsMi4wN2wtMTMuMzQtMy42M1oiLz48L3N2Zz4=)](https://github.com/keep-starknet-strange) + +
+ +## Overview + +Starknet Core Contract components in Cairo. + +## Build + +To build the project, run: + +```bash +scarb build +``` + +## Test + +To test the project, run: + +```bash +snforge test +``` diff --git a/Scarb.lock b/Scarb.lock new file mode 100644 index 0000000..51471f5 --- /dev/null +++ b/Scarb.lock @@ -0,0 +1,14 @@ +# Code generated by scarb DO NOT EDIT. +version = 1 + +[[package]] +name = "piltover" +version = "0.1.0" +dependencies = [ + "snforge_std", +] + +[[package]] +name = "snforge_std" +version = "0.16.0" +source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.16.0#f58e0ab42b6095b7d0cb841ede595aecbc9cb45d" diff --git a/Scarb.toml b/Scarb.toml new file mode 100644 index 0000000..a4a5e93 --- /dev/null +++ b/Scarb.toml @@ -0,0 +1,11 @@ +[package] +name = "piltover" +version = "0.1.0" +edition = "2023_10" + +[dependencies] +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.16.0" } +starknet = "2.4.4" + +[[target.starknet-contract]] +casm = true diff --git a/book/src/assets/piltover.png b/book/src/assets/piltover.png new file mode 100644 index 0000000..5e1918f Binary files /dev/null and b/book/src/assets/piltover.png differ diff --git a/src/lib.cairo b/src/lib.cairo new file mode 100644 index 0000000..1f94d45 --- /dev/null +++ b/src/lib.cairo @@ -0,0 +1,25 @@ +#[starknet::interface] +trait IHelloStarknet { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; +} + +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl HelloStarknetImpl of super::IHelloStarknet { + fn increase_balance(ref self: ContractState, amount: felt252) { + assert(amount != 0, 'Amount cannot be 0'); + self.balance.write(self.balance.read() + amount); + } + + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + } +} diff --git a/tests/test_contract.cairo b/tests/test_contract.cairo new file mode 100644 index 0000000..e13999a --- /dev/null +++ b/tests/test_contract.cairo @@ -0,0 +1,45 @@ +use starknet::ContractAddress; + +use snforge_std::{declare, ContractClassTrait}; + +use piltover::IHelloStarknetSafeDispatcher; +use piltover::IHelloStarknetSafeDispatcherTrait; +use piltover::IHelloStarknetDispatcher; +use piltover::IHelloStarknetDispatcherTrait; + +fn deploy_contract(name: felt252) -> ContractAddress { + let contract = declare(name); + contract.deploy(@ArrayTrait::new()).unwrap() +} + +#[test] +fn test_increase_balance() { + let contract_address = deploy_contract('HelloStarknet'); + + let dispatcher = IHelloStarknetDispatcher { contract_address }; + + let balance_before = dispatcher.get_balance(); + assert(balance_before == 0, 'Invalid balance'); + + dispatcher.increase_balance(42); + + let balance_after = dispatcher.get_balance(); + assert(balance_after == 42, 'Invalid balance'); +} + +#[test] +fn test_cannot_increase_balance_with_zero_value() { + let contract_address = deploy_contract('HelloStarknet'); + + let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; + + let balance_before = safe_dispatcher.get_balance().unwrap(); + assert(balance_before == 0, 'Invalid balance'); + + match safe_dispatcher.increase_balance(0) { + Result::Ok(_) => panic_with_felt252('Should have panicked'), + Result::Err(panic_data) => { + assert(*panic_data.at(0) == 'Amount cannot be 0', *panic_data.at(0)); + } + }; +}