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

feat: library improvements #2396

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
scarb 2.7.0
starknet-foundry 0.28.0
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use component_macros::example::{IMyContractDispatcherTrait, IMyContractDispatche
#[test]
fn test_mint() {
let contract = declare("MyContract").unwrap().contract_class();
let (address, _) = contract.deploy(@array!['minter']).unwrap();
let (address, _) = contract.deploy(['minter'].span()).unwrap();
let minter: ContractAddress = 'minter'.try_into().unwrap();

let dispatcher = IMyContractDispatcher { contract_address: address };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use contract_printing::IHelloStarknetDispatcherTrait;

fn deploy_contract(name: ByteArray) -> ContractAddress {
let contract = declare(name).unwrap().contract_class();
let (address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (address, _) = contract.deploy([].span()).unwrap();
address
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use traits::Into;
use starknet::ClassHashIntoFelt252;
use starknet::ContractAddress;
use starknet::Felt252TryIntoContractAddress;
use snforge_std::{declare, ContractAddress, ContractClassTrait, start_cheat_caller_address, start_cheat_block_number, start_cheat_block_timestamp};
use snforge_std::{
declare, ContractClassTrait, start_cheat_caller_address,
start_cheat_block_number, start_cheat_block_timestamp
};

#[starknet::interface]
trait IHelloStarknet<TContractState> {
Expand All @@ -17,7 +20,7 @@ trait IHelloStarknet<TContractState> {
fn declare_and_interact() {
assert(1 == 1, 'simple check');
let contract = declare("HelloStarknet").unwrap();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
let dispatcher = IHelloStarknetDispatcher { contract_address };

dispatcher.get_balance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn deploy_erc20(
constructor_calldata.append_span(initial_supply_serialized.span());
constructor_calldata.append(recipient.into());

let (address, _) = contract.deploy(@constructor_calldata).unwrap();
let (address, _) = contract.deploy(constructor_calldata.span()).unwrap();
address
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use simple_package::hello_starknet::IHelloStarknetDispatcherTrait;
#[test]
fn call_and_invoke() {
let contract = declare("HelloStarknet").unwrap().contract_class();
let constructor_calldata = @ArrayTrait::new();
let constructor_calldata = [].span();
let (contract_address, _) = contract.deploy(constructor_calldata).unwrap();
let dispatcher = IHelloStarknetDispatcher { contract_address };

Expand Down
6 changes: 3 additions & 3 deletions crates/forge/tests/data/trace/tests/test_trace.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use trace_info::{
fn test_trace() {
let sc = declare("SimpleContract").unwrap().contract_class();

let (contract_address_A, _) = sc.deploy(@array![]).unwrap();
let (contract_address_B, _) = sc.deploy(@array![]).unwrap();
let (contract_address_C, _) = sc.deploy(@array![]).unwrap();
let (contract_address_A, _) = sc.deploy([].span()).unwrap();
let (contract_address_B, _) = sc.deploy([].span()).unwrap();
let (contract_address_C, _) = sc.deploy([].span()).unwrap();

let calls = array![
RecursiveCall {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ fn test_call() {

trace_resources::use_builtins_and_syscalls(empty_hash, 7);

let (checker_address, _) = checker.deploy(@array![]).unwrap();
let (checker_address, _) = checker.deploy([].span()).unwrap();
let (proxy_address, _) = proxy
.deploy(@array![checker_address.into(), empty_hash.into(), 5])
.deploy([checker_address.into(), empty_hash.into(), 5].span())
.unwrap();
let (dummy_address, _) = dummy.deploy(@array![]).unwrap();
let (dummy_address, _) = dummy.deploy([].span()).unwrap();

let proxy_dispatcher = ITraceInfoProxyDispatcher { contract_address: proxy_address };
proxy_dispatcher.regular_call(checker_address, empty_hash, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ fn test_deploy() {

trace_resources::use_builtins_and_syscalls(empty_hash, 7);

let (checker_address, _) = checker.deploy(@array![]).unwrap();
let (checker_address, _) = checker.deploy([].span()).unwrap();

proxy.deploy(@array![checker_address.into(), empty_hash.into(), 1]).unwrap();
proxy.deploy([checker_address.into(), empty_hash.into(), 1].span()).unwrap();

deploy_syscall(
proxy.class_hash, 0, array![checker_address.into(), empty_hash.into(), 2].span(), false
)
.unwrap_syscall();

proxy
.deploy_at(@array![checker_address.into(), empty_hash.into(), 3], 123.try_into().unwrap())
.deploy_at([checker_address.into(), empty_hash.into(), 3].span(), 123.try_into().unwrap())
.unwrap();

deploy_syscall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn test_failed_call() {

trace_resources::use_builtins_and_syscalls(empty_hash, 7);

let (checker_address, _) = checker.deploy(@array![]).unwrap();
let (checker_address, _) = checker.deploy([].span()).unwrap();
let (proxy_address, _) = proxy
.deploy(@array![checker_address.into(), empty_hash.into(), 1])
.deploy([checker_address.into(), empty_hash.into(), 1].span())
.unwrap();

let proxy_dispatcher = ITraceInfoProxySafeDispatcher { contract_address: proxy_address };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_failed_lib_call() {
let empty_hash = declare("Empty").unwrap().contract_class().class_hash.clone();
let proxy_hash = declare("TraceInfoProxy").unwrap().contract_class().class_hash.clone();
let checker = declare("TraceInfoChecker").unwrap().contract_class().clone();
let (checker_address, _) = checker.deploy(@array![]).unwrap();
let (checker_address, _) = checker.deploy([].span()).unwrap();

trace_resources::use_builtins_and_syscalls(empty_hash, 7);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ fn test_l1_handler() {

trace_resources::use_builtins_and_syscalls(empty_hash, 7);

let (checker_address, _) = checker.deploy(@array![]).unwrap();
let (checker_address, _) = checker.deploy([].span()).unwrap();
let (proxy_address, _) = proxy
.deploy(@array![checker_address.into(), empty_hash.into(), 1])
.deploy([checker_address.into(), empty_hash.into(), 1].span())
.unwrap();

let mut l1_handler = L1HandlerTrait::new(checker_address, selector!("handle_l1_message"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ fn test_lib_call() {

trace_resources::use_builtins_and_syscalls(empty_hash, 7);

let (checker_address, _) = checker.deploy(@array![]).unwrap();
let (dummy_address, _) = dummy.deploy(@array![]).unwrap();
let (checker_address, _) = checker.deploy([].span()).unwrap();
let (dummy_address, _) = dummy.deploy([].span()).unwrap();

let proxy_lib_dispatcher = ITraceInfoProxyLibraryDispatcher { class_hash: proxy_hash };

Expand Down
20 changes: 10 additions & 10 deletions crates/forge/tests/integration/cheat_block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn cheat_block_number_basic() {
#[test]
fn test_stop_cheat_block_number() {
let contract = declare("CheatBlockNumberChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
let dispatcher = ICheatBlockNumberCheckerDispatcher { contract_address };

let old_block_number = dispatcher.get_block_number();
Expand All @@ -48,8 +48,8 @@ fn cheat_block_number_basic() {
fn test_cheat_block_number_multiple() {
let contract = declare("CheatBlockNumberChecker").unwrap().contract_class();

let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address1, _) = contract.deploy([].span()).unwrap();
let (contract_address2, _) = contract.deploy([].span()).unwrap();

let cheat_block_number_checker1 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address1 };
let cheat_block_number_checker2 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address2 };
Expand Down Expand Up @@ -77,8 +77,8 @@ fn cheat_block_number_basic() {
fn test_cheat_block_number_all() {
let contract = declare("CheatBlockNumberChecker").unwrap().contract_class();

let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address1, _) = contract.deploy([].span()).unwrap();
let (contract_address2, _) = contract.deploy([].span()).unwrap();

let cheat_block_number_checker1 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address1 };
let cheat_block_number_checker2 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address2 };
Expand Down Expand Up @@ -106,7 +106,7 @@ fn cheat_block_number_basic() {
#[test]
fn test_cheat_block_number_all_stop_one() {
let contract = declare("CheatBlockNumberChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
let dispatcher = ICheatBlockNumberCheckerDispatcher { contract_address };

let old_block_number = dispatcher.get_block_number();
Expand Down Expand Up @@ -155,16 +155,16 @@ fn cheat_block_number_complex() {

fn deploy_cheat_block_number_checker() -> ICheatBlockNumberCheckerDispatcher {
let contract = declare("CheatBlockNumberChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
ICheatBlockNumberCheckerDispatcher { contract_address }
}

#[test]
fn cheat_block_number_complex() {
let contract = declare("CheatBlockNumberChecker").unwrap().contract_class();

let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address1, _) = contract.deploy([].span()).unwrap();
let (contract_address2, _) = contract.deploy([].span()).unwrap();

let cheat_block_number_checker1 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address1 };
let cheat_block_number_checker2 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address2 };
Expand Down Expand Up @@ -237,7 +237,7 @@ fn cheat_block_number_with_span() {
}

fn deploy_cheat_block_number_checker() -> ICheatBlockNumberCheckerDispatcher {
let (contract_address, _) = declare("CheatBlockNumberChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = declare("CheatBlockNumberChecker").unwrap().contract_class().deploy([].span()).unwrap();
ICheatBlockNumberCheckerDispatcher { contract_address }
}

Expand Down
18 changes: 9 additions & 9 deletions crates/forge/tests/integration/cheat_block_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn cheat_block_timestamp_basic() {

fn deploy_cheat_block_timestamp_checker() -> ICheatBlockTimestampCheckerDispatcher {
let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
ICheatBlockTimestampCheckerDispatcher { contract_address }
}

Expand Down Expand Up @@ -69,8 +69,8 @@ fn cheat_block_timestamp_basic() {
fn cheat_block_timestamp_multiple() {
let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class();

let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address1, _) = contract.deploy([].span()).unwrap();
let (contract_address2, _) = contract.deploy([].span()).unwrap();

let cheat_block_timestamp_checker1 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address1 };
let cheat_block_timestamp_checker2 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address2 };
Expand Down Expand Up @@ -101,8 +101,8 @@ fn cheat_block_timestamp_basic() {
fn cheat_block_timestamp_all() {
let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class();

let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address1, _) = contract.deploy([].span()).unwrap();
let (contract_address2, _) = contract.deploy([].span()).unwrap();

let cheat_block_timestamp_checker1 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address1 };
let cheat_block_timestamp_checker2 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address2 };
Expand Down Expand Up @@ -163,16 +163,16 @@ fn cheat_block_timestamp_complex() {

fn deploy_cheat_block_timestamp_checker() -> ICheatBlockTimestampCheckerDispatcher {
let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
ICheatBlockTimestampCheckerDispatcher { contract_address }
}

#[test]
fn cheat_block_timestamp_complex() {
let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class();

let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address1, _) = contract.deploy([].span()).unwrap();
let (contract_address2, _) = contract.deploy([].span()).unwrap();

let cheat_block_timestamp_checker1 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address1 };
let cheat_block_timestamp_checker2 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address2 };
Expand Down Expand Up @@ -245,7 +245,7 @@ fn cheat_block_timestamp_with_span() {
}

fn deploy_cheat_block_timestamp_checker() -> ICheatBlockTimestampCheckerDispatcher {
let (contract_address, _) = declare("CheatBlockTimestampChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = declare("CheatBlockTimestampChecker").unwrap().contract_class().deploy([].span()).unwrap();
ICheatBlockTimestampCheckerDispatcher { contract_address }
}

Expand Down
12 changes: 6 additions & 6 deletions crates/forge/tests/integration/cheat_caller_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn cheat_caller_address() {
#[test]
fn test_stop_cheat_caller_address() {
let contract = declare("CheatCallerAddressChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
let dispatcher = ICheatCallerAddressCheckerDispatcher { contract_address };

let target_caller_address: felt252 = 123;
Expand All @@ -47,7 +47,7 @@ fn cheat_caller_address() {
#[test]
fn test_cheat_caller_address_all() {
let contract = declare("CheatCallerAddressChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
let dispatcher = ICheatCallerAddressCheckerDispatcher { contract_address };

let target_caller_address: felt252 = 123;
Expand All @@ -69,7 +69,7 @@ fn cheat_caller_address() {
#[test]
fn test_cheat_caller_address_all_stop_one() {
let contract = declare("CheatCallerAddressChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = contract.deploy([].span()).unwrap();
let dispatcher = ICheatCallerAddressCheckerDispatcher { contract_address };

let target_caller_address: felt252 = 123;
Expand All @@ -92,8 +92,8 @@ fn cheat_caller_address() {
fn test_cheat_caller_address_multiple() {
let contract = declare("CheatCallerAddressChecker").unwrap().contract_class();

let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let (contract_address1, _) = contract.deploy([].span()).unwrap();
let (contract_address2, _) = contract.deploy([].span()).unwrap();

let dispatcher1 = ICheatCallerAddressCheckerDispatcher { contract_address: contract_address1 };
let dispatcher2 = ICheatCallerAddressCheckerDispatcher { contract_address: contract_address2 };
Expand Down Expand Up @@ -155,7 +155,7 @@ fn cheat_caller_address_with_span() {
}

fn deploy_cheat_caller_address_checker() -> ICheatCallerAddressCheckerDispatcher {
let (contract_address, _) = declare("CheatCallerAddressChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap();
let (contract_address, _) = declare("CheatCallerAddressChecker").unwrap().contract_class().deploy([].span()).unwrap();
ICheatCallerAddressCheckerDispatcher { contract_address }
}

Expand Down
Loading
Loading