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 snforge_std to edition 2024_07 #2691

Merged
merged 28 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
32887a0
Add `pub`
kkawula Nov 19, 2024
80a5791
Change impls to traits
kkawula Dec 5, 2024
5a392cf
.
kkawula Dec 5, 2024
61363b8
Merge branch 'master' into kkawula/2638-migrate-snforge_std-to-editio…
kkawula Dec 5, 2024
4108395
Fmt
kkawula Dec 5, 2024
6d6aa4b
Update visibility
kkawula Dec 8, 2024
23d07bc
Update 'File' visibility
kkawula Dec 10, 2024
8a251a5
Update 'MessageToL1Spy' visibility
kkawula Dec 10, 2024
b8793df
Update 'ExecutionInfoMockImpl' visibility
kkawula Dec 10, 2024
9c90bc7
Update 'BlockInfoMockImpl' visibility
kkawula Dec 10, 2024
1f50a3c
Update '_event_offset' visibility
kkawula Dec 10, 2024
4ab76c8
Update 'L1Handler' visibility
kkawula Dec 10, 2024
65149bc
Upadte 'test_filtering' test
kkawula Dec 10, 2024
d9b49ad
Update 'CheatArguments' visibility
kkawula Dec 10, 2024
b6b33ca
Update 'Operation' visibility
kkawula Dec 10, 2024
9349fcf
Update 'TxInfoMock' and 'ExecutionInfoMock' visibility
kkawula Dec 10, 2024
d684145
Update 'handle_cheatcode' visibility
kkawula Dec 10, 2024
3c4351f
Update 'cheat_execution_info' visibility
kkawula Dec 10, 2024
6ff4987
Merge branch 'master' into kkawula/2638-migrate-snforge_std-to-editio…
kkawula Dec 10, 2024
3ab3144
Update `_is_config_run` description
kkawula Dec 13, 2024
48cb1e6
Ignore tests
kkawula Dec 13, 2024
e61c64c
Ignore tests
kkawula Dec 13, 2024
0745bda
Ignore tests
kkawula Dec 13, 2024
3e05dc6
Add toto
kkawula Dec 13, 2024
12c7740
Fix formattig
kkawula Dec 13, 2024
bf7fad9
Fix formattig
kkawula Dec 13, 2024
be4157a
Fix formattig
kkawula Dec 13, 2024
0c6488f
Create `_internals` mod
kkawula Dec 13, 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
11 changes: 7 additions & 4 deletions crates/forge/tests/integration/cheat_execution_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn start_and_stop_cheat_transaction_hash_single_attribute() {
}

#[test]
#[ignore] // TODO(#2765)
#[allow(clippy::too_many_lines)]
fn start_cheat_execution_info_all_attributes_mocked() {
let test = test_case!(
Expand Down Expand Up @@ -283,7 +284,7 @@ fn start_cheat_transaction_hash_cancel_mock_by_setting_attribute_to_none() {
use serde::Serde;
use starknet::ContractAddress;
use array::SpanTrait;
use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, stop_cheat_transaction_hash, TxInfoMock, Operation, CheatArguments, CheatSpan };
use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, stop_cheat_transaction_hash, CheatSpan };
use starknet::info::v2::ResourceBounds;

#[starknet::interface]
Expand Down Expand Up @@ -361,7 +362,7 @@ fn start_cheat_transaction_hash_multiple() {
use starknet::ContractAddress;
use starknet::ContractAddressIntoFelt252;
use array::SpanTrait;
use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, TxInfoMock, Operation, CheatArguments, CheatSpan};
use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, CheatSpan};

#[starknet::interface]
trait ICheatTxInfoChecker<TContractState> {
Expand Down Expand Up @@ -402,6 +403,7 @@ fn start_cheat_transaction_hash_multiple() {
}

#[test]
#[ignore] // TODO(#2765)
#[allow(clippy::too_many_lines)]
fn start_cheat_execution_info_all() {
let test = test_case!(
Expand Down Expand Up @@ -456,6 +458,7 @@ fn start_cheat_execution_info_all() {
let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address };

let mut execution_info_mock: ExecutionInfoMock = Default::default();

execution_info_mock.tx_info.nonce = Operation::StartGlobal(411);
execution_info_mock.tx_info.account_contract_address = Operation::StartGlobal(422.try_into().unwrap());
execution_info_mock.tx_info.version = Operation::StartGlobal(433);
Expand Down Expand Up @@ -546,7 +549,7 @@ fn start_cheat_transaction_hash_complex() {
use starknet::ContractAddress;
use starknet::ContractAddressIntoFelt252;
use array::SpanTrait;
use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, start_cheat_transaction_hash_global, TxInfoMock, Operation, CheatArguments, CheatSpan };
use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, start_cheat_transaction_hash_global, CheatSpan };

#[starknet::interface]
trait ICheatTxInfoChecker<TContractState> {
Expand Down Expand Up @@ -609,7 +612,7 @@ fn cheat_transaction_hash_with_span() {
use serde::Serde;
use starknet::ContractAddress;
use array::SpanTrait;
use snforge_std::{ test_address, declare, ContractClassTrait, DeclareResultTrait, cheat_transaction_hash, stop_cheat_transaction_hash, CheatSpan, Operation, CheatArguments};
use snforge_std::{ test_address, declare, ContractClassTrait, DeclareResultTrait, cheat_transaction_hash, stop_cheat_transaction_hash, CheatSpan};
use starknet::info::v2::ResourceBounds;

#[starknet::interface]
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/tests/integration/message_to_l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ fn test_filtering() {
let second_address = second_dispatcher.contract_address;

let mut spy = spy_messages_to_l1();
assert(spy._message_offset == 0, 'Message offset should be 0');
kkawula marked this conversation as resolved.
Show resolved Hide resolved
// assert(spy._message_offset == 0, 'Message offset should be 0'); TODO(#2765)

first_dispatcher.send_message(
array![123, 421, 420],
Expand Down
1 change: 1 addition & 0 deletions crates/forge/tests/integration/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn cairo_test_cheatcode_error() {
}

#[test]
#[ignore] // TODO(#2765)
fn cheatcode_invalid_args() {
let test = test_utils::test_case!(indoc!(
r"
Expand Down
5 changes: 2 additions & 3 deletions crates/forge/tests/integration/spy_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ fn spy_events_simple() {
let dispatcher = ISpyEventsCheckerDispatcher { contract_address };

let mut spy = spy_events();
assert(spy._event_offset == 0, 'Event offset should be 0');
kkawula marked this conversation as resolved.
Show resolved Hide resolved

// assert(spy._event_offset == 0, 'Event offset should be 0'); TODO(#2765)
dispatcher.emit_one_event(123);

spy.assert_emitted(@array![
Expand Down Expand Up @@ -779,7 +778,7 @@ fn test_filtering() {
let second_dispatcher = ISpyEventsCheckerDispatcher { contract_address: second_address };

let mut spy = spy_events();
assert(spy._event_offset == 0, 'Event offset should be 0');
kkawula marked this conversation as resolved.
Show resolved Hide resolved
// assert(spy._event_offset == 0, 'Event offset should be 0'); TODO(#2765)

first_dispatcher.emit_one_event(123);
second_dispatcher.emit_one_event(234);
Expand Down
5 changes: 2 additions & 3 deletions crates/forge/tests/integration/test_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ fn simple_cheatcodes() {
start_cheat_block_number, stop_cheat_block_number,
start_cheat_block_timestamp, stop_cheat_block_timestamp,
start_cheat_transaction_hash, stop_cheat_transaction_hash,
test_address, TxInfoMock,
Operation, CheatArguments, CheatSpan
test_address, CheatSpan
};
use starknet::{
SyscallResultTrait, SyscallResult, syscalls::get_execution_info_v2_syscall,
Expand Down Expand Up @@ -585,7 +584,7 @@ fn spy_events_simple() {
fn spy_events_simple() {
let contract_address = test_address();
let mut spy = spy_events();
assert(spy._event_offset == 0, 'Events offset should be 0');
kkawula marked this conversation as resolved.
Show resolved Hide resolved
// assert(spy._event_offset == 0, 'Events offset should be 0'); TODO(#2765)

starknet::emit_event_syscall(array![1234].span(), array![2345].span()).unwrap_syscall();

Expand Down
6 changes: 3 additions & 3 deletions crates/snforge-scarb-plugin/src/config_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ pub fn append_config_statements(
return None;
};

// this function is named "snforge_std::_cheatcode::_is_config_run"
// this function is named "snforge_std::_internals::_is_config_run"
let segments = expr.path(db).elements(db);

let [snforge_std, cheatcode, is_config_run] = segments.as_slice() else {
return None;
};

if snforge_std.identifier(db) != "snforge_std"
|| cheatcode.identifier(db) != "_cheatcode"
|| cheatcode.identifier(db) != "_internals"
|| is_config_run.identifier(db) != "_is_config_run"
{
return None;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn append_config_statements(
"
{attrs}
{vis} {declaration} {{
if snforge_std::_cheatcode::_is_config_run() {{
if snforge_std::_internals::_is_config_run() {{
{if_content}

{config_statements}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn works_with_few_attributes() {
#[snforge_internal_test_executable]
#[__internal_config_statement]
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::AvailableGasConfig {
Expand Down Expand Up @@ -62,7 +62,7 @@ fn works_with_few_attributes() {
#[snforge_internal_test_executable]
#[__internal_config_statement]
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::AvailableGasConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn work_with_number() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::AvailableGasConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn accepts_string() {
&result,
r#"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {

let mut data = array![];

Expand Down Expand Up @@ -132,7 +132,7 @@ fn accepts_inline_config() {
&result,
r#"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {

let mut data = array![];

Expand Down Expand Up @@ -166,7 +166,7 @@ fn overriding_config_name_first() {
&result,
r#"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {

let mut data = array![];

Expand Down Expand Up @@ -200,7 +200,7 @@ fn overriding_config_name_second() {
&result,
r#"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {

let mut data = array![];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn work_without_args() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::FuzzerConfig {
Expand Down Expand Up @@ -47,7 +47,7 @@ fn work_with_both_args() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::FuzzerConfig {
Expand Down Expand Up @@ -78,7 +78,7 @@ fn work_with_runs_only() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::FuzzerConfig {
Expand Down Expand Up @@ -109,7 +109,7 @@ fn work_with_seed_only() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::FuzzerConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn works_without_args() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::IgnoreConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn appends_config_statement() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn work_with_empty() {
&result,
r"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::ShouldPanicConfig {
Expand Down Expand Up @@ -45,7 +45,7 @@ fn work_with_expected_string() {
&result,
r#"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::ShouldPanicConfig {
Expand Down Expand Up @@ -74,7 +74,7 @@ fn work_with_expected_string_escaped() {
&result,
r#"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::ShouldPanicConfig {
Expand Down Expand Up @@ -103,7 +103,7 @@ fn work_with_expected_short_string() {
&result,
r"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::ShouldPanicConfig {
Expand Down Expand Up @@ -132,7 +132,7 @@ fn work_with_expected_short_string_escaped() {
&result,
r"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::ShouldPanicConfig {
Expand Down Expand Up @@ -161,7 +161,7 @@ fn work_with_expected_tuple() {
&result,
"
fn empty_fn() {
if snforge_std::_cheatcode::_is_config_run() {
if snforge_std::_internals::_is_config_run() {
let mut data = array![];

snforge_std::_config_types::ShouldPanicConfig {
Expand Down
2 changes: 1 addition & 1 deletion snforge_std/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "snforge_std"
version = "0.34.0"
edition = "2023_10"
edition = "2024_07"
description = "Cairo testing library"
documentation = "https://foundry-rs.github.io/starknet-foundry/appendix/snforge-library.html"
repository = "https://github.com/foundry-rs/starknet-foundry"
Expand Down
6 changes: 4 additions & 2 deletions snforge_std/src/_cheatcode.cairo
kkawula marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::array::ArrayTrait;
use core::traits::Into;
use core::array::SpanTrait;

pub fn handle_cheatcode(input: Span<felt252>) -> Span<felt252> {
pub(crate) fn handle_cheatcode(input: Span<felt252>) -> Span<felt252> {
let first = *input.at(0);
let input = input.slice(1, input.len() - 1);

Expand All @@ -18,7 +18,9 @@ pub fn handle_cheatcode(input: Span<felt252>) -> Span<felt252> {
}
}

fn _is_config_run() -> bool {
// Do not use this function directly.
kkawula marked this conversation as resolved.
Show resolved Hide resolved
// It is an internal part of the snforge architecture used by macros.
pub fn _is_config_run() -> bool {
let mut res = handle_cheatcode(
starknet::testing::cheatcode::<'is_config_mode'>(array![].span())
);
Expand Down
Loading
Loading