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

Migrate to multiple packages (workspace) #1065

Merged
merged 51 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3cd9ed9
Migrate erc20 tests (#1022)
ericnordelo Jun 28, 2024
a96b50a
Snforge utils and some common changes (#1030)
immrsd Jul 4, 2024
9b333cc
Re-add dual20 tests (#1028)
ericnordelo Jul 4, 2024
0d149da
Migrate security tests (#1034)
andrew-fleming Jul 5, 2024
a9b4eb3
refacto repo into packages
ametel01 Jul 7, 2024
890608e
fmt
ametel01 Jul 7, 2024
c3df288
Migrate erc1155 tests (#1037)
ericnordelo Jul 10, 2024
ef89fb2
Migrate erc721 tests (#1027)
ericnordelo Jul 11, 2024
fbfb819
Check ignored tests (#1049)
ericnordelo Jul 16, 2024
8fe4f80
Migrate Ownable tests (#1033)
immrsd Jul 17, 2024
6f7130f
Migrate Upgrades tests (#1051)
immrsd Jul 17, 2024
4850245
Migrate erc20 preset tests (#1055)
ericnordelo Jul 18, 2024
78aa934
feat: update ignored tests messages (#1056)
ericnordelo Jul 19, 2024
daff8e5
Migrate erc1155 preset tests (#1057)
ericnordelo Jul 19, 2024
c34d4d0
Migrate cryptography and UDC tests (#1059)
andrew-fleming Jul 22, 2024
ba8004c
Migrate eth account tests (#1058)
ericnordelo Jul 23, 2024
9e091d4
Migrate eth account preset tests (#1060)
ericnordelo Jul 23, 2024
a794ca0
Migrate AccessControl Tests (#1044)
immrsd Jul 25, 2024
9e9adf9
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Jul 26, 2024
bc316ca
Migrate Starknet Account tests (#1050)
immrsd Jul 26, 2024
852c43b
feat: make contracts build
ericnordelo Jul 26, 2024
b8d597a
feat: update packages Scarb.toml
ericnordelo Jul 26, 2024
fddddbd
refactor: remove gitmodules file
ericnordelo Jul 26, 2024
8851d2b
feat: refactor tests
ericnordelo Jul 26, 2024
4ac1903
feat: update workflow
ericnordelo Jul 26, 2024
094ab98
feat: test utils
ericnordelo Jul 26, 2024
6dcdad3
feat: add missing tests
ericnordelo Jul 26, 2024
b0be872
Merge branch 'snforge-migration' of github.com:OpenZeppelin/cairo-con…
ericnordelo Jul 26, 2024
d678419
fix: tests
ericnordelo Jul 26, 2024
47ab176
fix: remaining tests
ericnordelo Jul 29, 2024
cf80dd5
refactor: format files
ericnordelo Jul 29, 2024
05b877d
tmp: workflow update
ericnordelo Jul 29, 2024
6bd4ac8
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Jul 29, 2024
0af0fff
feat: add entry to CHANGELOG and update README
ericnordelo Jul 29, 2024
15d5fcb
doc: update imports
ericnordelo Jul 29, 2024
2e0f3c6
Migrate Starknet Account Preset tests (#1069)
immrsd Jul 29, 2024
6601f24
Bump scarb, merge changes from main in snforge migration (#1076)
andrew-fleming Jul 31, 2024
e09af84
Migrate timelock tests (#1061)
andrew-fleming Aug 1, 2024
fc8b397
Update docs/modules/ROOT/pages/components.adoc
ericnordelo Aug 1, 2024
25c199b
Update docs/modules/ROOT/pages/components.adoc
ericnordelo Aug 1, 2024
493b426
feat: apply review updates
ericnordelo Aug 1, 2024
29b6e01
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Aug 1, 2024
fc929c3
Merge branch 'snforge-migration' of github.com:OpenZeppelin/cairo-con…
ericnordelo Aug 1, 2024
530b087
feat: update governance package
ericnordelo Aug 1, 2024
66e6d2f
refactor: format files
ericnordelo Aug 1, 2024
39cf6c1
Merge branch 'workspace-conversion' of github.com:ericnordelo/cairo-c…
ericnordelo Aug 1, 2024
72bd08a
refactor: remove unused files
ericnordelo Aug 1, 2024
44492c7
fix: workflow
ericnordelo Aug 1, 2024
d8b88eb
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Aug 1, 2024
97b4cac
refactor: remove warnings
ericnordelo Aug 1, 2024
d58c751
feat: remove old tests
ericnordelo Aug 1, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
*.md
!PULL_REQUEST_TEMPLATE.md
- name: Cairo lint
run: scarb fmt --check
run: scarb fmt --check --workspace
- name: Temporary USC manually install
run: |
curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh -s -- v2.2.0-rc.1
- name: Cairo test
run: snforge test
run: snforge test --workspace
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- TimelockController component (#996)
- HashCall implementation (#996)
- Separated package for each submodule (#1065)
- `openzeppelin_access`
- `openzeppelin_account`
- `openzeppelin_governance`
- `openzeppelin_introspection`
- `openzeppelin_presets`
- `openzeppelin_security`
- `openzeppelin_token`
- `openzeppelin_upgrades`
- `openzeppelin_utils`

### Changed

- Bump scarb to v2.7.0-rc.1 (#1025)
- Bump scarb to v2.7.0-rc.2 (#1052)
- Bump scarb to v2.7.0-rc.4 (#1064)
- Bump scarb to v2.7.0 (#1065)

## 0.15.0-rc.0 (2024-07-8)

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Edit `scarb.toml` and add:
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0-rc.0" }
```

The previous example would import the entire library. we can also add each package as a separated dependency to improve the time for building by not including modules that won't be used:

```toml
[dependencies]
openzeppelin_token = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0-rc.0" }
```

ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
Build the project to download it:

```bash
Expand All @@ -65,6 +72,7 @@ For example, this is how to write an ERC20-compliant contract:
```cairo
#[starknet::contract]
mod MyToken {
// If only the token package was added as a dependency, use `openzeppelin_token::` instead
use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use starknet::ContractAddress;

Expand Down
90 changes: 90 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,96 @@ version = 1
[[package]]
name = "openzeppelin"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
"snforge_std",
]

[[package]]
name = "openzeppelin_access"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
"snforge_std",
]

[[package]]
name = "openzeppelin_account"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_utils",
"snforge_std",
]

[[package]]
name = "openzeppelin_governance"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_access",
"openzeppelin_introspection",
"openzeppelin_utils",
"snforge_std",
]

[[package]]
name = "openzeppelin_introspection"
version = "0.15.0-rc.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "openzeppelin_presets"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
"snforge_std",
]

[[package]]
name = "openzeppelin_security"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_utils",
"snforge_std",
]

[[package]]
name = "openzeppelin_token"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
"snforge_std",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.15.0-rc.0"
dependencies = [
"openzeppelin_utils",
"snforge_std",
]

[[package]]
name = "openzeppelin_utils"
version = "0.15.0-rc.0"
dependencies = [
"snforge_std",
]
Expand Down
53 changes: 47 additions & 6 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
[workspace]
members = [
"packages/access",
"packages/account",
"packages/governance",
"packages/introspection",
"packages/presets",
"packages/security",
"packages/token",
"packages/upgrades",
"packages/utils",
]

[package]
name = "openzeppelin"
version.workspace = true

[workspace.package]
version = "0.15.0-rc.0"
edition = "2023_11"
cairo-version = "2.7.0-rc.3"
scarb-version = "2.7.0-rc.4"
cairo-version = "2.7.0"
scarb-version = "2.7.0"
authors = ["OpenZeppelin Community <[email protected]>"]
description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup"
documentation = "https://docs.openzeppelin.com/contracts-cairo"
readme = "README.md"
repository = "https://github.com/OpenZeppelin/cairo-contracts"
license-file = "LICENSE"
keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"]
keywords = [
"openzeppelin",
"starknet",
"cairo",
"contracts",
"security",
"standards",
]

[dependencies]
starknet = "2.7.0-rc.3"
[workspace.dependencies]
starknet = "2.7.0"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.26.0" }

[dependencies]
starknet.workspace = true
openzeppelin_access = { path = "packages/access" }
openzeppelin_account = { path = "packages/account" }
openzeppelin_governance = { path = "packages/governance" }
openzeppelin_introspection = { path = "packages/introspection" }
openzeppelin_presets = { path = "packages/presets" }
openzeppelin_security = { path = "packages/security" }
openzeppelin_token = { path = "packages/token" }
openzeppelin_upgrades = { path = "packages/upgrades" }
openzeppelin_utils = { path = "packages/utils" }

[dev-dependencies]
snforge_std.workspace = true

[lib]

[[target.starknet-contract]]
allowed-libfuncs-list.name = "experimental"
sierra = true
casm = false

[tool.fmt]
[workspace.tool.fmt]
sort-module-level-items = true

[tool]
fmt.workspace = true
12 changes: 6 additions & 6 deletions docs/modules/ROOT/pages/api/utilities.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:deploy_syscall: link:https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/system-calls-cairo1/#deploy[deploy_syscall]

The following documentation provides reasoning and examples for functions and constants found in `openzeppelin::utils`
and `openzeppelin::tests::utils`.
and `use openzeppelin::utils::test_utils;`.

CAUTION: Expect this module to evolve (as it has already done).

Expand Down Expand Up @@ -387,7 +387,7 @@ xref:/guides/snip12.adoc[SNIP12 and Typed Messages] guide.
=== `++utils++`

```cairo
use openzeppelin::tests::utils;
use openzeppelin::utils::test_utils;
```

Module containing utilities for testing the library.
Expand Down Expand Up @@ -420,14 +420,14 @@ Usage example:

```cairo
use openzeppelin::presets::AccountUpgradeable;
use openzeppelin::tests::utils;
use openzeppelin::utils::test_utils;
use starknet::ContractAddress;

const PUBKEY: felt252 = 'PUBKEY';

fn deploy_test_contract() -> ContractAddress {
let calldata = array![PUBKEY];
utils::deploy(AccountUpgradeable::TEST_CLASS_HASH, calldata)
test_utils::deploy(AccountUpgradeable::TEST_CLASS_HASH, calldata)
}
```

Expand Down Expand Up @@ -459,15 +459,15 @@ Requirements:
Usage example:

```cairo
use openzeppelin::tests::utils;
use openzeppelin::utils::test_utils;
use openzeppelin::token::erc20::ERC20Component;
use openzeppelin::token::erc20::ERC20Component::Transfer;
use starknet::ContractAddress;

fn assert_emitted_event(
target: ContractAddress, from: ContractAddress, to: ContractAddress, value: u256
) {
let event = utils::pop_log::<ERC20Component::Event>(target).unwrap();
let event = test_utils::pop_log::<ERC20Component::Event>(target).unwrap();
let expected = ERC20Component::Event::Transfer(Transfer { from, to, value });
assert!(event == expected);
}
Expand Down
31 changes: 31 additions & 0 deletions packages/access/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "openzeppelin_access"
version.workspace = true
edition.workspace = true
cairo-version.workspace = true
scarb-version.workspace = true
authors.workspace = true
description.workspace = true
documentation.workspace = true
readme.workspace = true
repository.workspace = true
license-file.workspace = true
keywords.workspace = true

[tool]
fmt.workspace = true

[dependencies]
starknet.workspace = true
openzeppelin_introspection = { path = "../introspection" }
openzeppelin_utils = { path = "../utils" }

[dev-dependencies]
snforge_std.workspace = true

[lib]

[[target.starknet-contract]]
allowed-libfuncs-list.name = "experimental"
sierra = true
casm = false
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
/// Roles are referred to by their `felt252` identifier.
#[starknet::component]
pub mod AccessControlComponent {
use openzeppelin::access::accesscontrol::interface;
use openzeppelin::introspection::src5::SRC5Component::InternalImpl as SRC5InternalImpl;
use openzeppelin::introspection::src5::SRC5Component::SRC5Impl;
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin_access::accesscontrol::interface;
use openzeppelin_introspection::src5::SRC5Component::InternalImpl as SRC5InternalImpl;
use openzeppelin_introspection::src5::SRC5Component::SRC5Impl;
use openzeppelin_introspection::src5::SRC5Component;
use starknet::ContractAddress;
use starknet::get_caller_address;
use starknet::storage::Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (access/accesscontrol/dual_accesscontrol.cairo)

use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use openzeppelin::utils::try_selector_with_fallback;
use openzeppelin_utils::selectors;
use openzeppelin_utils::serde::SerializedAppend;
use openzeppelin_utils::try_selector_with_fallback;
use openzeppelin_utils::unwrap_and_cast::UnwrapAndCast;
use starknet::ContractAddress;
use starknet::SyscallResultTrait;
use starknet::syscalls::call_contract_syscall;
Expand Down
2 changes: 2 additions & 0 deletions src/access.cairo → packages/access/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod accesscontrol;
pub mod ownable;

pub mod tests;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (access/ownable/dual_ownable.cairo)

use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use openzeppelin::utils::try_selector_with_fallback;
use openzeppelin_utils::UnwrapAndCast;
use openzeppelin_utils::selectors;
use openzeppelin_utils::serde::SerializedAppend;
use openzeppelin_utils::try_selector_with_fallback;
use starknet::ContractAddress;
use starknet::SyscallResultTrait;
use starknet::syscalls::call_contract_syscall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#[starknet::component]
pub mod OwnableComponent {
use core::num::traits::Zero;
use openzeppelin::access::ownable::interface::IOwnableTwoStep;
use openzeppelin::access::ownable::interface;
use openzeppelin_access::ownable::interface::IOwnableTwoStep;
use openzeppelin_access::ownable::interface;
use starknet::ContractAddress;
use starknet::get_caller_address;

Expand Down
8 changes: 7 additions & 1 deletion src/tests/access.cairo → packages/access/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
pub(crate) mod common;
pub mod common;
pub(crate) mod mocks;

#[cfg(test)]
mod test_accesscontrol;
#[cfg(test)]
mod test_dual_accesscontrol;
#[cfg(test)]
mod test_dual_ownable;
#[cfg(test)]
mod test_ownable;
#[cfg(test)]
mod test_ownable_twostep;
Loading