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

snforge migration #1077

Merged
merged 21 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
14 changes: 11 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Lint and test

on:
pull_request:
branches:
- main
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
push:
branches:
- main
Expand All @@ -21,6 +19,13 @@ jobs:
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- name: Extract foundry version
run: |
FOUNDRY_VERSION=$(grep 'snforge_std = ' Scarb.toml | sed 's/snforge_std = .\+ tag = "v\(.*\)".*/\1/')
echo "FOUNDRY_VERSION=$FOUNDRY_VERSION" >> "$GITHUB_ENV"
- uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: ${{ env.FOUNDRY_VERSION }}
- name: Markdown lint
uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 # v16
with:
Expand All @@ -29,5 +34,8 @@ jobs:
!PULL_REQUEST_TEMPLATE.md
- name: Cairo lint
run: scarb fmt --check
- 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: scarb test
run: snforge test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ corelib/
# Scarb
target/

# Starknet Foundry
.snfoundry_cache/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
8 changes: 8 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ version = 1
[[package]]
name = "openzeppelin"
version = "0.15.0-rc.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_std"
version = "0.26.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.26.0#50eb589db65e113efe4f09241feb59b574228c7e"
4 changes: 1 addition & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "stand

[dependencies]
starknet = "2.7.0-rc.3"

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

[lib]

Expand Down
2 changes: 0 additions & 2 deletions docs/modules/ROOT/pages/accounts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ Here’s an example of a basic contract:
mod MyEthAccount {
use openzeppelin::account::EthAccountComponent;
use openzeppelin::account::interface::EthPublicKey;
use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde;
use openzeppelin::introspection::src5::SRC5Component;
use starknet::ClassHash;

Expand Down Expand Up @@ -389,7 +388,6 @@ First, let's take the example account we created before and deploy it:
mod MyEthAccount {
use openzeppelin::account::EthAccountComponent;
use openzeppelin::account::interface::EthPublicKey;
use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde;
use openzeppelin::introspection::src5::SRC5Component;

component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);
Expand Down
1 change: 0 additions & 1 deletion src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod cryptography;
mod governance;
#[cfg(test)]
mod introspection;
#[cfg(test)]
mod mocks;
#[cfg(test)]
mod presets;
Expand Down
44 changes: 24 additions & 20 deletions src/tests/access/common.cairo
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
use openzeppelin::access::ownable::OwnableComponent::OwnershipTransferred;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::tests::utils::EventSpyExt;
use openzeppelin::tests::utils;
use openzeppelin::utils::serde::SerializedAppend;
use snforge_std::EventSpy;
use starknet::ContractAddress;

pub(crate) fn assert_only_event_ownership_transferred(
contract: ContractAddress, previous_owner: ContractAddress, new_owner: ContractAddress
) {
assert_event_ownership_transferred(contract, previous_owner, new_owner);
utils::assert_no_events_left(contract);
}

pub(crate) fn assert_event_ownership_transferred(
contract: ContractAddress, previous_owner: ContractAddress, new_owner: ContractAddress
) {
let event = utils::pop_log::<OwnableComponent::Event>(contract).unwrap();
let expected = OwnableComponent::Event::OwnershipTransferred(
OwnershipTransferred { previous_owner, new_owner }
);
assert!(event == expected);
#[generate_trait]
pub(crate) impl OwnableSpyHelpersImpl of OwnableSpyHelpers {
fn assert_only_event_ownership_transferred(
ref self: EventSpy,
contract: ContractAddress,
previous_owner: ContractAddress,
new_owner: ContractAddress
) {
self.assert_event_ownership_transferred(contract, previous_owner, new_owner);
self.assert_no_events_left_from(contract);
}

let mut indexed_keys = array![];
indexed_keys.append_serde(selector!("OwnershipTransferred"));
indexed_keys.append_serde(previous_owner);
indexed_keys.append_serde(new_owner);
utils::assert_indexed_keys(event, indexed_keys.span());
fn assert_event_ownership_transferred(
ref self: EventSpy,
contract: ContractAddress,
previous_owner: ContractAddress,
new_owner: ContractAddress
) {
let expected = OwnableComponent::Event::OwnershipTransferred(
OwnershipTransferred { previous_owner, new_owner }
);
self.assert_emitted_single(contract, expected);
}
}
Loading