Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge cairo-2 #760

Merged
merged 105 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
331844d
fix: link (#545)
ericnordelo Jan 20, 2023
b9ec20b
add submodule
andrew-fleming Feb 18, 2023
bb40124
update cairo
andrew-fleming Feb 18, 2023
a0c3157
add Cargo and Makefile
andrew-fleming Feb 18, 2023
3a6e20d
update cairo
andrew-fleming Feb 18, 2023
96431de
add deps in cairo_project, create lib
andrew-fleming Feb 18, 2023
7b38706
add presets
andrew-fleming Feb 18, 2023
2fa00dd
add base lib
andrew-fleming Feb 18, 2023
f0036e7
add tests
andrew-fleming Feb 18, 2023
8d781a8
remove old cairo lib and interface
andrew-fleming Feb 18, 2023
ae37b1c
remove unused import
andrew-fleming Feb 18, 2023
da57a91
fix vars
andrew-fleming Feb 18, 2023
fd42fdd
change external funcs to snake case
andrew-fleming Feb 18, 2023
1cb1252
remove unused import
andrew-fleming Feb 18, 2023
f0330cd
update cairo
andrew-fleming Feb 21, 2023
abc737a
add tests for externals
andrew-fleming Feb 21, 2023
4ca2620
add bool assertions
andrew-fleming Feb 21, 2023
8dd8ed3
update cairo
andrew-fleming Feb 22, 2023
091a29c
remove preset mods
andrew-fleming Feb 22, 2023
1c866f2
add IERC20 trait
andrew-fleming Feb 22, 2023
3405063
update cairo
andrew-fleming Feb 22, 2023
8fe3c82
clean up test
andrew-fleming Feb 22, 2023
ad928bc
remove assertion
andrew-fleming Feb 23, 2023
d883eb5
update cairo
andrew-fleming Feb 23, 2023
543501b
simplify max_u256
andrew-fleming Feb 23, 2023
2ecba91
clarify error msg
andrew-fleming Feb 23, 2023
6c3978b
add erc165 + tests
martriay Mar 3, 2023
60365c8
kickstart account module
martriay Mar 3, 2023
be1e9df
clean up python project. ready for rust/cairo1
martriay Mar 7, 2023
c20fd02
rebase to cairo-1
martriay Mar 7, 2023
bce2506
re-structure project
martriay Mar 7, 2023
35ede09
re-structure project
martriay Mar 8, 2023
e55889a
re-structure project
martriay Mar 8, 2023
9d5079c
update makefile
martriay Mar 8, 2023
ae89fa5
bump submodule
martriay Mar 8, 2023
a54e98c
Update erc20 migration branch (#586)
andrew-fleming Mar 28, 2023
91dcad3
Migrate security/initializable (#592)
andrew-fleming Mar 31, 2023
f48da2c
Use zeroable::zero() instead of contract_address_const::<0>() (#598)
Amxx Mar 31, 2023
d671d4c
Migrate security/pausable (#593)
andrew-fleming Mar 31, 2023
e86bcd2
add utils and constants
andrew-fleming Apr 18, 2023
42a160f
Revert "add utils and constants"
andrew-fleming Apr 18, 2023
598c232
Migrate ERC165 (#582)
martriay Apr 26, 2023
b2624ee
Migrate constants (#611)
andrew-fleming Apr 26, 2023
4a4bca9
Set up new CI (#599)
andrew-fleming Apr 27, 2023
0962051
fix formatting (#613)
andrew-fleming Apr 28, 2023
a1950ee
Normalize error message style (#606)
andrew-fleming Apr 28, 2023
c29b45c
Add `BoundedInt` and internal macros, update cairo (#600)
andrew-fleming Apr 28, 2023
e48a682
Migrate ownable (#604)
andrew-fleming May 11, 2023
5f86f65
Migrate security/reentrancyguard (#590)
andrew-fleming May 19, 2023
897facb
Migrate access control (#605)
andrew-fleming May 19, 2023
372de37
Migrate account (#620)
andrew-fleming May 23, 2023
d86eb73
Migrate ERC721 (#619)
martriay May 30, 2023
62688e7
Dual interface dispatcher for ERC721 (#623)
martriay Jul 2, 2023
ba69328
Replace ERC-165 with SRC-5 (Update Interface Ids) (#637)
ericnordelo Jul 2, 2023
8534ec6
Fix conflicts from the dual721 and src5 merge (#641)
andrew-fleming Jul 3, 2023
bc90bd5
Add camel support for ownable (#625)
andrew-fleming Jul 3, 2023
c8fa9f9
Add camel support for access control (#626)
andrew-fleming Jul 5, 2023
3a8e3e7
erc20 dual dispatcher (#622)
andrew-fleming Jul 5, 2023
6a1f729
Add `UnwrapAndCast` trait (#644)
andrew-fleming Jul 6, 2023
bbcb875
add test_dual721 mod (#648)
andrew-fleming Jul 8, 2023
5a27baa
Update account interface (#646)
ericnordelo Jul 10, 2023
ba29133
Add camel support for Account (#647)
ericnordelo Jul 12, 2023
b44f7dc
Add src5 dual dispatcher (#659)
andrew-fleming Jul 12, 2023
33dbd56
Add dual case erc721 receiver (#649)
andrew-fleming Jul 13, 2023
65d03ae
Add owner param to ownable initializer (#660)
ericnordelo Jul 13, 2023
a863859
Migrate SRC5 to Cairo 2 (#664)
ericnordelo Jul 18, 2023
c4590b9
Migrate initializable to cairo2 (#661)
andrew-fleming Jul 18, 2023
f18fcdb
Migrate Account to Cairo 2 (#666)
ericnordelo Jul 20, 2023
dc4a233
Migrate pausable to cairo2 (#662)
andrew-fleming Jul 20, 2023
27514b1
Migrate reentrancyguard to cairo2 (#663)
andrew-fleming Jul 20, 2023
8e10821
Migrate ERC721 to Cairo2 (#667)
ericnordelo Jul 21, 2023
a00a9d3
Migrate ownable to cairo2 (#665)
andrew-fleming Jul 21, 2023
0b40485
Migrate ERC20 to Cairo 2 (#669)
ericnordelo Jul 22, 2023
4e64434
Migrate access control to cairo2 (#668)
andrew-fleming Jul 22, 2023
79fe2db
Migrate to Scarb for cairo-2 (#671)
maciektr Aug 4, 2023
177ad63
Add spdx (#684)
andrew-fleming Aug 4, 2023
495ed8a
feat: sort imports (#679)
ericnordelo Aug 4, 2023
c28c758
Migrate upgrades (#603)
andrew-fleming Aug 10, 2023
f9c30da
Add testing for Ownable events (#675)
ericnordelo Aug 11, 2023
457b98b
Add account events (#687)
andrew-fleming Aug 11, 2023
544ddac
Add testing for AccessControl events (#674)
ericnordelo Aug 15, 2023
4473243
Add testing for Pausable events (#676)
ericnordelo Aug 15, 2023
e95def8
Add testing for ERC20 events (#677)
ericnordelo Aug 15, 2023
77089c1
Add mint to erc721 preset constructor (#700)
andrew-fleming Aug 15, 2023
3e08fa6
Add testing for ERC721 events (#678)
ericnordelo Aug 16, 2023
8307644
Update README and fix scarb package (#688)
martriay Aug 18, 2023
cece32b
Bump scarb and fix dual721 test context (#703)
andrew-fleming Aug 23, 2023
32f9974
add rc version (#708)
martriay Aug 23, 2023
b40c35b
remove unused imports (#707)
andrew-fleming Aug 23, 2023
fbdd759
Upgrade Cairo version and Scarb version to latest releases (#712)
bal7hazar Aug 24, 2023
05429e4
bump antora (#715)
martriay Aug 28, 2023
adac09f
Add selector inline macro/fix `tokenURI` (#724)
andrew-fleming Sep 8, 2023
90be39f
fix: naming convention (#732)
ericnordelo Sep 14, 2023
fcdd6d1
feat: add Errors modules (#691)
ericnordelo Sep 14, 2023
7373daa
Update account docs (#709)
ericnordelo Sep 15, 2023
cbb5bf5
Add Interface & Dispatchers docs (#730)
martriay Sep 20, 2023
4e388f5
Update overview docs (#735)
ericnordelo Sep 20, 2023
a1b559c
remove underscore from name_ and symbol_ (#738)
andrew-fleming Sep 21, 2023
74eb4e8
Add prefixes to storage members (#743)
ericnordelo Sep 26, 2023
420f320
Sanitizing for release. (#736)
ericnordelo Sep 27, 2023
a6731c3
Update Access Control docs (#719)
ericnordelo Sep 28, 2023
2ac98be
Add indexed keys to token events (#746)
andrew-fleming Sep 29, 2023
4ce5309
Update Introspection docs (#721)
ericnordelo Sep 29, 2023
fe695e4
Update upgrade docs (#731)
ericnordelo Sep 29, 2023
88c62e6
Merge branch 'main' into cairo-2
martriay Sep 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.cairo linguist-language=python
*.cairo linguist-language=rust
52 changes: 0 additions & 52 deletions .github/workflows/coverage.yml

This file was deleted.

41 changes: 0 additions & 41 deletions .github/workflows/release.yml

This file was deleted.

57 changes: 22 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@
name: Test
name: Lint and test

on:
pull_request:
branches:
- main
- cairo-2
push:
tags:
- "v*"
branches:
- main
- cairo-2

jobs:
validate:
lint_and_test:
name: Lint and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Get commits
id: commits
run: |
echo "MAIN=$(git show -s --format="%H" origin/main)" >> $GITHUB_OUTPUT
echo "TAG=$(git rev-list -n 1 ${GITHUB_REF#refs/*/})" >> $GITHUB_OUTPUT
- name: Print commits
run: |
echo "Main commit: ${{ steps.commits.outputs.MAIN }}"
echo "Tag commit: ${{ steps.commits.outputs.TAG }}"
- name: Compare commits
if: ${{ steps.commits.outputs.MAIN != steps.commits.outputs.TAG }}
uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # v6.3.3
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
script: |
core.setFailed('Tagged commit does not match main')

test:
runs-on: ubuntu-latest
needs: [validate]
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
scarb-version: "0.7.0"
- name: Markdown lint
uses: DavidAnson/markdownlint-cli2-action@5b7c9f74fec47e6b15667b2cc23c63dff11e449e # v9
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest tox
- name: Run tests
run: |
tox
globs: |
*.md
!PULL_REQUEST_TEMPLATE.md
- name: Cairo lint
run: scarb fmt --check
- name: Cairo test
run: scarb test
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
artifacts/
.DS_Store

# Cairo 1
corelib/

# Scarb
target/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -73,9 +79,6 @@ instance/
# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cairo"]
path = cairo
url = https://github.com/starkware-libs/cairo.git
5 changes: 5 additions & 0 deletions .markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
// Disable line length check to enable paragraphs without internal line breaks.
// See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md013---line-length
"MD013": false
}
8 changes: 0 additions & 8 deletions .markdownlintrc

This file was deleted.

91 changes: 14 additions & 77 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,11 @@ We really appreciate and value contributions to OpenZeppelin Contracts for Cairo

Before starting development, please [create an issue](https://github.com/OpenZeppelin/cairo-contracts/issues/new/choose) to open the discussion, validate that the PR is wanted, and coordinate overall implementation details.

Also, consider that snake case is used for Cairo development in general due to its strong Python bias.
This project follows our [Extensibility pattern](https://docs.openzeppelin.com/contracts-cairo/extensibility), camelCasing all exposed function names and their parameters:

```cairo
@external
func exposedFunc(paramOne, paramTwo){
}
```

All internal and otherwise unexposed functions should resort to snake_case:

```cairo
func internal_func(param_one, param_two){
}
```

Compare our preset contracts with the libraries from which they're derived such as the [ERC20 preset](./src/openzeppelin/token/erc20/presets/ERC20.cairo) and [ERC20 library](./src/openzeppelin/token/erc20/presets/ERC20.cairo) for full examples.
See [Function names and coding style](https://docs.openzeppelin.com/contracts-cairo/0.4.0/extensibility#function_names_and_coding_style) for more information.

And make sure to always include tests and documentation for the new developments. Please consider the following conventions:

- Naming
- Libraries should be named `library.cairo`, e.g. `erc20/library.cairo`
- Contracts should be PascalCased i.e. `MyContract.cairo`
- Interfaces should be prefixed with an `I`, as in `IAccount.cairo`
- Test modules should begin with `test_` followed by the contract name i.e. `test_MyContract.py`

- Structure
- Libraries should cede their names to their parent directory and are named `library.cairo` instead
- Interfaces should be alongside the library that the interface defines
- Preset contracts should be within a `presets` directory of the library to which they are a preset
- Here are example paths:
- `openzeppelin.token.erc20.library`
- `openzeppelin.token.erc20.IERC20`
- `openzeppelin.token.erc20.presets.ERC20Mintable`
- And a visual guide:

```python
openzeppelin
└──token
└── erc20
├── library.cairo
├── IERC20.cairo
└── presets
└── ERC20Mintable.cairo
```

- Preset contract testing
- Though, inheritance is not possible in Cairo, this repo utilizes inheritance for testing. This proves useful for testing multiple contracts that stem from the same base library. For example, the preset contracts [ERC20Mintable](./src/openzeppelin/token/erc20/presets/ERC20Mintable.cairo) and [ERC20Burnable](./src/openzeppelin/token/erc20/presets/ERC20Burnable.cairo) both share the base ERC20 functionality. To reduce code repetition, we follow these guidelines:
- `BaseSuites`
- module names are not prefixed with `test_`
- set base tests inside a class
- class name should not be prefixed with `Test`; otherwise, these tests run twice

- test modules
- define the base fixture (`contract_factory`) and any other fixtures not used in the base suite i.e. `erc721_minted`
- define the test class and inherit the base class i.e. `class TestERC20(OwnableBase)`
- add tests specific to the preset flavor within the test class

- fixtures
- are not defined in the base suite but are passed, unpacked, and used
- are defined in the tests where they are used
- for modularity, the basic contract factory fixture is always called `contract_factory`
### Coding style

After a few radical changes in the Cairo language (mainly the transition to Cairo 1), our coding style guidelines became automatically deprecated.
That's why [we're working on setting new ones](https://github.com/OpenZeppelin/cairo-contracts/issues/696).
Feel free to read, contribute, discuss, and ask questions in the issue.

## Creating Pull Requests (PRs)

Expand Down Expand Up @@ -98,32 +40,29 @@ As a contributor, you are expected to fork this repository, work on your own for
3. Make your changes, add your files, update documentation ([see Documentation section](#documentation)), commit, and push to your fork.

```sh
git add SomeFile.js
git add src/file.cairo
git commit "Fix some bug short description #123"
git push origin fix/some-bug-short-description-#123
```

4. Run tests, linter, etc. This can be done by running local continuous integration and make sure it passes. We recommend to use a [python virtual environment](https://docs.python.org/3/tutorial/venv.html).
4. Run tests and linter. This can be done by running local continuous integration and make sure it passes.

```bash
# install tox from testing dependencies
pip install .[testing] # '.[testing]' in zsh

# run tests
tox
scarb test

# stop the build if there are Markdown documentation errors
tox -e lint
# run linter
scarb fmt --check
```

5. Go to [github.com/OpenZeppelin/cairo-contracts](https://github.com/OpenZeppelin/cairo-contracts) in your web browser and issue a new pull request.
5. Go to [OpenZeppelin/cairo-contracts](https://github.com/OpenZeppelin/cairo-contracts) in your web browser and issue a new pull request.
Begin the body of the PR with "Fixes #123" or "Resolves #123" to link the PR to the issue that it is resolving.
*IMPORTANT* Read the PR template very carefully and make sure to follow all the instructions. These instructions
refer to some very important conditions that your PR must meet in order to be accepted, such as making sure that all PR checks pass.

6. Maintainers will review your code and possibly ask for changes before your code is pulled in to the main repository. We'll check that all tests pass, review the coding style, and check for general code correctness. If everything is OK, we'll merge your pull request and your code will be part of OpenZeppelin Contracts for Cairo.

*IMPORTANT* Please pay attention to the maintainer's feedback, since its a necessary step to keep up with the standards OpenZeppelin Contracts attains to.
*IMPORTANT* Please pay attention to the maintainer's feedback, since it's a necessary step to keep up with the standards OpenZeppelin Contracts attains to.

## Documentation

Expand All @@ -145,15 +84,13 @@ If you want to run the documentation UI locally:

## Integration tests

Currently, [starknet's test suite](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/testing/starknet.py) has important differences with public networks. Like [not checking signature hints toward the end of the tx flow](https://github.com/OpenZeppelin/cairo-contracts/issues/386).

That's why we strongly suggest testing new features against a testnet before submitting the PR, to make sure that everything works as expected in a real environment.
Currently, Starknet's test suite has important differences with public networks. We strongly suggest testing new features against a testnet before submitting the PR, to make sure that everything works as expected in a real environment.

We are looking into defining a better process for these integration tests, but for now the PR author/contributor must suggest an approach to test the feature when applicable, which has to be agreed and reproduced by the reviewer.

## All set

If you have any questions, feel free to post them to github.com/OpenZeppelin/cairo-contracts/issues.
If you have any questions, feel free to post them as an [issue](https://github.com/OpenZeppelin/cairo-contracts/issues).

Finally, if you're looking to collaborate and want to find easy tasks to start, look at the issues we marked as ["Good first issue"](https://github.com/OpenZeppelin/cairo-contracts/labels/good%20first%20issue).

Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

1 change: 0 additions & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Fixes #??? <!-- Fill in with issue number -->
<!-- Describe the changes introduced in this pull request. -->
<!-- Include any context necessary for understanding the PR's purpose. -->


#### PR Checklist

<!-- Before merging the pull request all of the following must be complete. -->
Expand Down
Loading