Skip to content

Commit

Permalink
Bump starknet foundry to 0.30.0 (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggonzalez94 authored Sep 11, 2024
1 parent e0e96c5 commit 7ced799
Show file tree
Hide file tree
Showing 33 changed files with 171 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
scarb-version: ${{ env.SCARB_VERSION }}
- name: Extract foundry version
run: |
FOUNDRY_VERSION=$(grep 'snforge_std = ' Scarb.toml | sed 's/snforge_std = .\+ tag = "v\(.*\)".*/\1/')
FOUNDRY_VERSION=$(grep 'snforge_std = ' Scarb.toml | sed 's/snforge_std = "\(.*\)"/\1/')
echo "FOUNDRY_VERSION=$FOUNDRY_VERSION" >> "$GITHUB_ENV"
- uses: foundry-rs/setup-snfoundry@v3
with:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- `into_base_16_string_no_padding` function to the test helpers (#1137)

### Changed

- Bump scarb to v2.8.2 (#1137)
- Bump snforge to 0.30.0 (#1137)
- `declare_class`, `declare_and_deploy`, and `declare_and_deploy_at` will skip declaration if the contract is already declared (#1137)

## 0.16.0 (2024-08-30)

### Added
Expand Down
14 changes: 12 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.2.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:2e4ce3ebe3f49548bd26908391b5d78537a765d827df0d96c32aeb88941d0d67"

[[package]]
name = "snforge_std"
version = "0.27.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de"
version = "0.30.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:2f3c4846881813ac0f5d1460981249c9f5e2a6831e752beedf9b70975495b4ec"
dependencies = [
"snforge_scarb_plugin",
]
10 changes: 6 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ version.workspace = true
[workspace.package]
version = "0.16.0"
edition = "2023_11"
cairo-version = "2.8.0"
scarb-version = "2.8.0"
cairo-version = "2.8.2"
scarb-version = "2.8.2"
authors = ["OpenZeppelin Community <[email protected]>"]
description = "OpenZeppelin Contracts written in Cairo for Starknet, a decentralized ZK Rollup"
documentation = "https://docs.openzeppelin.com/contracts-cairo"
Expand All @@ -39,8 +39,9 @@ keywords = [
]

[workspace.dependencies]
starknet = "2.8.0"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.27.0" }
assert_macros = "2.8.2"
starknet = "2.8.2"
snforge_std = "0.30.0"

[dependencies]
starknet.workspace = true
Expand All @@ -56,6 +57,7 @@ openzeppelin_upgrades = { path = "packages/upgrades" }
openzeppelin_utils = { path = "packages/utils" }

[dev-dependencies]
assert_macros.workspace = true
snforge_std.workspace = true
openzeppelin_test_common = { path = "packages/test_common" }
openzeppelin_testing = { path = "packages/testing" }
Expand Down
10 changes: 5 additions & 5 deletions docs/modules/ROOT/pages/api/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ following the Starknet Foundry emitted error format.
[[testing-common-IntoBase16StringTrait]]
==== `[.contract-item-name]#++IntoBase16StringTrait++#` [.item-kind]#trait#

A helper trait that enables a value to be represented as a `base16` string padded to 66 characters
(including the `0x` prefix). The type of the value must implement `Into<T, felt252>` to be
A helper trait that enables a value to be represented as a `base16`(hexadecimal) string padded to 66 characters
(including the `0x` prefix). There's also a version with no padding for compatibility with Starknet Foundry `0.28.0` and above, where addresses and selectors are not padded properly. The type of the value must implement `Into<T, felt252>` to be
convertible to `felt252`.

Usage example:
Expand Down Expand Up @@ -118,7 +118,7 @@ A module containing utilities that simplify declaring and deploying contracts us
[[testing-deployment-declare_class]]
==== `[.contract-item-name]#++declare_class++#++(contract_name: ByteArray) → ContractClass++` [.item-kind]#function#

Declares a contract with a `snforge` `declare` call and unwraps the result.
Declares a contract with a `snforge_std::declare` call and unwraps the result. This function will skip declaration and just return the `ContractClass` if the contract is already declared (the result of `snforge_std::declare` call is of type `DeclareResult::AlreadyDeclared`).

[.contract-item]
[[testing-deployment-deploy]]
Expand Down Expand Up @@ -155,13 +155,13 @@ deploy_another_at(alice_address, bob_address, array!['BOB_PUBKEY']);
[[testing-deployment-declare_and_deploy]]
==== `[.contract-item-name]#++declare_and_deploy++#++(contract_name: ByteArray, calldata: Array<felt252>) → ContractAddress++` [.item-kind]#function#

Combines the declaration of a class and the deployment of a contract into one function call.
Combines the declaration of a class and the deployment of a contract into one function call. This function will skip declaration if the contract is already declared (the result of `snforge_std::declare` call is of type `DeclareResult::AlreadyDeclared`).

[.contract-item]
[[testing-deployment-declare_and_deploy_at]]
==== `[.contract-item-name]#++declare_and_deploy_at++#++(contract_name: ByteArray, target_address: ContractAddress, calldata: Array<felt252>)++` [.item-kind]#function#

Combines the declaration of a class and the deployment of a contract at the given address into one function call.
Combines the declaration of a class and the deployment of a contract at the given address into one function call. This function will skip declaration if the contract is already declared (the result of `snforge_std::declare` call is of type `DeclareResult::AlreadyDeclared`).

[.contract]
[[testing-events]]
Expand Down
1 change: 1 addition & 0 deletions packages/access/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ openzeppelin_introspection = { path = "../introspection" }
openzeppelin_utils = { path = "../utils" }

[dev-dependencies]
assert_macros.workspace = true
snforge_std.workspace = true
openzeppelin_testing = { path = "../testing" }
openzeppelin_test_common = { path = "../test_common" }
Expand Down
22 changes: 11 additions & 11 deletions packages/access/src/tests/test_dual_accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn test_dual_no_supports_interface() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_supports_interface_exists_and_panics() {
let (snake_dispatcher, _) = setup_accesscontrol_panic();
snake_dispatcher.supports_interface(IACCESSCONTROL_ID);
Expand All @@ -90,7 +90,7 @@ fn test_dual_no_has_role() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_has_role_exists_and_panics() {
let (dispatcher, _) = setup_accesscontrol_panic();
dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand All @@ -112,7 +112,7 @@ fn test_dual_no_get_role_admin() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_get_role_admin_exists_and_panics() {
let (snake_dispatcher, _) = setup_accesscontrol_panic();
snake_dispatcher.get_role_admin(ROLE);
Expand All @@ -137,7 +137,7 @@ fn test_dual_no_grant_role() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_grant_role_exists_and_panics() {
let (snake_dispatcher, _) = setup_accesscontrol_panic();
snake_dispatcher.grant_role(ROLE, AUTHORIZED());
Expand All @@ -162,7 +162,7 @@ fn test_dual_no_revoke_role() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_revoke_role_exists_and_panics() {
let (snake_dispatcher, _) = setup_accesscontrol_panic();
snake_dispatcher.revoke_role(ROLE, AUTHORIZED());
Expand All @@ -187,7 +187,7 @@ fn test_dual_no_renounce_role() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_renounce_role_exists_and_panics() {
let (snake_dispatcher, _) = setup_accesscontrol_panic();
snake_dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand All @@ -208,7 +208,7 @@ fn test_dual_hasRole() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_hasRole_exists_and_panics() {
let (_, camel_dispatcher) = setup_accesscontrol_panic();
camel_dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand All @@ -225,7 +225,7 @@ fn test_dual_getRoleAdmin() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_getRoleAdmin_exists_and_panics() {
let (_, camel_dispatcher) = setup_accesscontrol_panic();
camel_dispatcher.get_role_admin(ROLE);
Expand All @@ -244,7 +244,7 @@ fn test_dual_grantRole() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_grantRole_exists_and_panics() {
let (_, camel_dispatcher) = setup_accesscontrol_panic();
camel_dispatcher.grant_role(ROLE, AUTHORIZED());
Expand All @@ -264,7 +264,7 @@ fn test_dual_revokeRole() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_revokeRole_exists_and_panics() {
let (_, camel_dispatcher) = setup_accesscontrol_panic();
camel_dispatcher.revoke_role(ROLE, AUTHORIZED());
Expand All @@ -283,7 +283,7 @@ fn test_dual_renounceRole() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_renounceRole_exists_and_panics() {
let (_, camel_dispatcher) = setup_accesscontrol_panic();
camel_dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN());
Expand Down
10 changes: 5 additions & 5 deletions packages/access/src/tests/test_dual_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn test_dual_no_owner() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_owner_exists_and_panics() {
let (dispatcher, _) = setup_ownable_panic();
dispatcher.owner();
Expand Down Expand Up @@ -98,7 +98,7 @@ fn test_dual_no_transfer_ownership() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_transfer_ownership_exists_and_panics() {
let (dispatcher, _) = setup_ownable_panic();
dispatcher.transfer_ownership(NEW_OWNER());
Expand All @@ -123,7 +123,7 @@ fn test_dual_no_renounce_ownership() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_renounce_ownership_exists_and_panics() {
let (dispatcher, _) = setup_ownable_panic();
dispatcher.renounce_ownership();
Expand All @@ -146,7 +146,7 @@ fn test_dual_transferOwnership() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_transferOwnership_exists_and_panics() {
let (_, camel_dispatcher) = setup_ownable_panic();
camel_dispatcher.transfer_ownership(NEW_OWNER());
Expand All @@ -165,7 +165,7 @@ fn test_dual_renounceOwnership() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_renounceOwnership_exists_and_panics() {
let (_, camel_dispatcher) = setup_ownable_panic();
camel_dispatcher.renounce_ownership();
Expand Down
1 change: 1 addition & 0 deletions packages/account/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ openzeppelin_introspection = { path = "../introspection" }
openzeppelin_utils = { path = "../utils" }

[dev-dependencies]
assert_macros.workspace = true
snforge_std.workspace = true
openzeppelin_testing = { path = "../testing" }
openzeppelin_test_common = { path = "../test_common" }
Expand Down
6 changes: 3 additions & 3 deletions packages/account/src/tests/test_account.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::num::traits::Zero;
use core::starknet::SyscallResultTrait;
use crate::AccountComponent::{InternalTrait, SRC6CamelOnlyImpl};
use crate::AccountComponent::{PublicKeyCamelImpl, PublicKeyImpl};
use crate::AccountComponent;
Expand All @@ -20,7 +19,7 @@ use snforge_std::{
start_cheat_signature_global, start_cheat_transaction_version_global,
start_cheat_transaction_hash_global
};
use snforge_std::{spy_events, declare, test_address, start_cheat_caller_address};
use snforge_std::{spy_events, test_address, start_cheat_caller_address};
use starknet::account::Call;

//
Expand All @@ -46,7 +45,8 @@ fn setup(key_pair: StarkKeyPair) -> ComponentState {
fn setup_dispatcher(
key_pair: StarkKeyPair, data: SignedTransactionData
) -> (AccountABIDispatcher, felt252) {
let contract_class = declare("DualCaseAccountMock").unwrap_syscall();
let contract_class = utils::declare_class("DualCaseAccountMock");

let calldata = array![key_pair.public_key];
let address = utils::deploy(contract_class, calldata);
let dispatcher = AccountABIDispatcher { contract_address: address };
Expand Down
14 changes: 7 additions & 7 deletions packages/account/src/tests/test_dual_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn test_dual_no_set_public_key() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_set_public_key_exists_and_panics() {
let (snake_dispatcher, _) = setup_account_panic();
let new_public_key = KEY_PAIR_2().public_key;
Expand All @@ -93,7 +93,7 @@ fn test_dual_no_get_public_key() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_get_public_key_exists_and_panics() {
let (snake_dispatcher, _) = setup_account_panic();
snake_dispatcher.get_public_key();
Expand Down Expand Up @@ -121,7 +121,7 @@ fn test_dual_no_is_valid_signature() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_is_valid_signature_exists_and_panics() {
let signature = array![];
let (snake_dispatcher, _) = setup_account_panic();
Expand All @@ -145,7 +145,7 @@ fn test_dual_no_supports_interface() {
}

#[test]
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_supports_interface_exists_and_panics() {
let (snake_dispatcher, _) = setup_account_panic();
snake_dispatcher.supports_interface(ISRC5_ID);
Expand Down Expand Up @@ -173,7 +173,7 @@ fn test_dual_setPublicKey() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_setPublicKey_exists_and_panics() {
let (_, camel_dispatcher) = setup_account_panic();
let new_public_key = KEY_PAIR_2().public_key;
Expand All @@ -191,7 +191,7 @@ fn test_dual_getPublicKey() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_getPublicKey_exists_and_panics() {
let (_, camel_dispatcher) = setup_account_panic();
camel_dispatcher.get_public_key();
Expand All @@ -211,7 +211,7 @@ fn test_dual_isValidSignature() {

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
#[should_panic(expected: ("Some error",))]
#[should_panic(expected: "Some error")]
fn test_dual_isValidSignature_exists_and_panics() {
let signature = array![];

Expand Down
Loading

0 comments on commit 7ced799

Please sign in to comment.