Skip to content

Commit

Permalink
Upgrade Cairo version and Scarb version to latest releases (#712)
Browse files Browse the repository at this point in the history
* 👽️ Update code due to breaking changes

* ⬆️ Upgrade scarb and cairo versions

* 💄 Code format
  • Loading branch information
bal7hazar authored Aug 24, 2023
1 parent b40c35b commit fbdd759
Show file tree
Hide file tree
Showing 23 changed files with 239 additions and 285 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.6.2"
scarb-version: "0.7.0"
- name: Markdown lint
uses: DavidAnson/markdownlint-cli2-action@5b7c9f74fec47e6b15667b2cc23c63dff11e449e # v9
with:
Expand Down
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "openzeppelin"
version = "0.7.0-rc.0"
cairo-version = "2.1.1"
cairo-version = "2.2.0"
authors = ["OpenZeppelin Community <maintainers@openzeppelin.org>"]
description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup"
documentation = "https://docs.openzeppelin.com/contracts-cairo"
Expand All @@ -11,7 +11,7 @@ license-file = "LICENSE"
keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"]

[dependencies]
starknet = ">=2.1.1"
starknet = ">=2.2.0"

[lib]

Expand Down
2 changes: 1 addition & 1 deletion src/account/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,6 @@ mod Account {
#[internal]
fn _execute_single_call(call: Call) -> Span<felt252> {
let Call{to, selector, calldata } = call;
starknet::call_contract_syscall(to, selector, calldata.span()).unwrap_syscall()
starknet::call_contract_syscall(to, selector, calldata.span()).unwrap()
}
}
20 changes: 10 additions & 10 deletions src/tests/access/test_accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn test_assert_only_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_assert_only_role_unauthorized() {
let state = setup();
testing::set_caller_address(OTHER());
Expand All @@ -120,7 +120,7 @@ fn test_assert_only_role_unauthorized() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_assert_only_role_unauthorized_when_authorized_for_another_role() {
let mut state = setup();
AccessControlImpl::grant_role(ref state, ROLE, AUTHORIZED());
Expand Down Expand Up @@ -181,7 +181,7 @@ fn test_grantRole_multiple_times_for_granted_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_grant_role_unauthorized() {
let mut state = setup();
testing::set_caller_address(AUTHORIZED());
Expand All @@ -190,7 +190,7 @@ fn test_grant_role_unauthorized() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_grantRole_unauthorized() {
let mut state = setup();
testing::set_caller_address(AUTHORIZED());
Expand Down Expand Up @@ -277,7 +277,7 @@ fn test_revokeRole_multiple_times_for_granted_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_revoke_role_unauthorized() {
let mut state = setup();
testing::set_caller_address(OTHER());
Expand All @@ -286,7 +286,7 @@ fn test_revoke_role_unauthorized() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_revokeRole_unauthorized() {
let mut state = setup();
testing::set_caller_address(OTHER());
Expand Down Expand Up @@ -380,7 +380,7 @@ fn test_renounceRole_multiple_times_for_granted_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Can only renounce role for self', ))]
#[should_panic(expected: ('Can only renounce role for self',))]
fn test_renounce_role_unauthorized() {
let mut state = setup();
testing::set_caller_address(ADMIN());
Expand All @@ -392,7 +392,7 @@ fn test_renounce_role_unauthorized() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Can only renounce role for self', ))]
#[should_panic(expected: ('Can only renounce role for self',))]
fn test_renounceRole_unauthorized() {
let mut state = setup();
testing::set_caller_address(ADMIN());
Expand Down Expand Up @@ -456,7 +456,7 @@ fn test_new_admin_can_revoke_roles() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_previous_admin_cannot_grant_roles() {
let mut state = setup();
InternalImpl::_set_role_admin(ref state, ROLE, OTHER_ROLE);
Expand All @@ -466,7 +466,7 @@ fn test_previous_admin_cannot_grant_roles() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Caller is missing role', ))]
#[should_panic(expected: ('Caller is missing role',))]
fn test_previous_admin_cannot_revoke_roles() {
let mut state = setup();
InternalImpl::_set_role_admin(ref state, ROLE, OTHER_ROLE);
Expand Down
57 changes: 24 additions & 33 deletions src/tests/access/test_dual_accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ fn setup_snake() -> (DualCaseAccessControl, IAccessControlDispatcher) {
calldata.append_serde(ADMIN());
let target = utils::deploy(SnakeAccessControlMock::TEST_CLASS_HASH, calldata);
(
DualCaseAccessControl {
contract_address: target
}, IAccessControlDispatcher {
contract_address: target
}
DualCaseAccessControl { contract_address: target },
IAccessControlDispatcher { contract_address: target }
)
}

Expand All @@ -41,11 +38,8 @@ fn setup_camel() -> (DualCaseAccessControl, IAccessControlCamelDispatcher) {
calldata.append_serde(ADMIN());
let target = utils::deploy(CamelAccessControlMock::TEST_CLASS_HASH, calldata);
(
DualCaseAccessControl {
contract_address: target
}, IAccessControlCamelDispatcher {
contract_address: target
}
DualCaseAccessControl { contract_address: target },
IAccessControlCamelDispatcher { contract_address: target }
)
}

Expand All @@ -58,11 +52,8 @@ fn setup_accesscontrol_panic() -> (DualCaseAccessControl, DualCaseAccessControl)
let snake_target = utils::deploy(SnakeAccessControlPanicMock::TEST_CLASS_HASH, array![]);
let camel_target = utils::deploy(CamelAccessControlPanicMock::TEST_CLASS_HASH, array![]);
(
DualCaseAccessControl {
contract_address: snake_target
}, DualCaseAccessControl {
contract_address: camel_target
}
DualCaseAccessControl { contract_address: snake_target },
DualCaseAccessControl { contract_address: camel_target }
)
}

Expand All @@ -79,15 +70,15 @@ fn test_dual_supports_interface() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_supports_interface() {
let dispatcher = setup_non_accesscontrol();
dispatcher.supports_interface(IACCESSCONTROL_ID);
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_supports_interface_exists_and_panics() {
let (dispatcher, _) = setup_accesscontrol_panic();
dispatcher.supports_interface(IACCESSCONTROL_ID);
Expand All @@ -102,15 +93,15 @@ fn test_dual_has_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_has_role() {
let dispatcher = setup_non_accesscontrol();
dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN());
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_has_role_exists_and_panics() {
let (dispatcher, _) = setup_accesscontrol_panic();
dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand All @@ -125,15 +116,15 @@ fn test_dual_get_role_admin() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_get_role_admin() {
let dispatcher = setup_non_accesscontrol();
dispatcher.get_role_admin(ROLE);
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_get_role_admin_exists_and_panics() {
let (dispatcher, _) = setup_accesscontrol_panic();
dispatcher.get_role_admin(ROLE);
Expand All @@ -150,15 +141,15 @@ fn test_dual_grant_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_grant_role() {
let dispatcher = setup_non_accesscontrol();
dispatcher.grant_role(ROLE, AUTHORIZED());
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_grant_role_exists_and_panics() {
let (dispatcher, _) = setup_accesscontrol_panic();
dispatcher.grant_role(ROLE, AUTHORIZED());
Expand All @@ -175,15 +166,15 @@ fn test_dual_revoke_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_revoke_role() {
let dispatcher = setup_non_accesscontrol();
dispatcher.revoke_role(ROLE, AUTHORIZED());
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_revoke_role_exists_and_panics() {
let (dispatcher, _) = setup_accesscontrol_panic();
dispatcher.revoke_role(ROLE, AUTHORIZED());
Expand All @@ -200,15 +191,15 @@ fn test_dual_renounce_role() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_renounce_role() {
let dispatcher = setup_non_accesscontrol();
dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN());
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_renounce_role_exists_and_panics() {
let (dispatcher, _) = setup_accesscontrol_panic();
dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand All @@ -227,7 +218,7 @@ fn test_dual_supportsInterface() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_supportsInterface_exists_and_panics() {
let (_, dispatcher) = setup_accesscontrol_panic();
dispatcher.supports_interface(IACCESSCONTROL_ID);
Expand All @@ -242,7 +233,7 @@ fn test_dual_hasRole() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_hasRole_exists_and_panics() {
let (_, dispatcher) = setup_accesscontrol_panic();
dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand All @@ -257,7 +248,7 @@ fn test_dual_getRoleAdmin() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_getRoleAdmin_exists_and_panics() {
let (_, dispatcher) = setup_accesscontrol_panic();
dispatcher.get_role_admin(ROLE);
Expand All @@ -274,7 +265,7 @@ fn test_dual_grantRole() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_grantRole_exists_and_panics() {
let (_, dispatcher) = setup_accesscontrol_panic();
dispatcher.grant_role(ROLE, AUTHORIZED());
Expand All @@ -292,7 +283,7 @@ fn test_dual_revokeRole() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_revokeRole_exists_and_panics() {
let (_, dispatcher) = setup_accesscontrol_panic();
dispatcher.revoke_role(ROLE, AUTHORIZED());
Expand All @@ -309,7 +300,7 @@ fn test_dual_renounceRole() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_renounceRole_exists_and_panics() {
let (_, dispatcher) = setup_accesscontrol_panic();
dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand Down
Loading

0 comments on commit fbdd759

Please sign in to comment.