From 4cc7209552122e92fb69f1384dbf83f4fc59bc2d Mon Sep 17 00:00:00 2001 From: enitrat Date: Mon, 26 Aug 2024 16:59:44 +0200 Subject: [PATCH] feat: replace @Array by Span --- .../trace_resources/tests/test_deploy.cairo | 6 +++--- .../src/cheatcodes/contract_class.cairo | 20 ++++++++----------- snforge_std/src/cheatcodes/events.cairo | 8 ++++---- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo b/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo index e2f03db168..bcf32656fe 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo @@ -11,7 +11,7 @@ fn test_deploy() { let (checker_address, _) = checker.deploy(@array![]).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 @@ -19,11 +19,11 @@ fn test_deploy() { .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( - proxy.class_hash, 12412, array![checker_address.into(), empty_hash.into(), 4].span(), false + proxy.class_hash, 12412, [checker_address.into(), empty_hash.into(), 4].span(), false ) .unwrap_syscall(); } diff --git a/snforge_std/src/cheatcodes/contract_class.cairo b/snforge_std/src/cheatcodes/contract_class.cairo index fa833f25fb..8ba699033b 100644 --- a/snforge_std/src/cheatcodes/contract_class.cairo +++ b/snforge_std/src/cheatcodes/contract_class.cairo @@ -24,7 +24,7 @@ pub trait ContractClassTrait { /// `constructor_calldata` - serialized calldata for the deploy constructor /// Returns the precalculated `ContractAddress` fn precalculate_address( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> ContractAddress; /// Deploys a contract @@ -33,7 +33,7 @@ pub trait ContractClassTrait { /// Returns the address the contract was deployed at and serialized constructor return data, or /// panic data if it failed fn deploy( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> SyscallResult<(ContractAddress, Span)>; /// Deploys a contract at a given address @@ -43,9 +43,7 @@ pub trait ContractClassTrait { /// Returns the address the contract was deployed at and serialized constructor return data, or /// panic data if it failed fn deploy_at( - self: @ContractClass, - constructor_calldata: @Array::, - contract_address: ContractAddress + self: @ContractClass, constructor_calldata: Span, contract_address: ContractAddress ) -> SyscallResult<(ContractAddress, Span)>; /// Utility method for creating a new `ContractClass` instance @@ -59,16 +57,16 @@ pub trait ContractClassTrait { impl ContractClassImpl of ContractClassTrait { fn precalculate_address( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> ContractAddress { - let mut inputs: Array:: = _prepare_calldata(self.class_hash, constructor_calldata); + let mut inputs: Array = _prepare_calldata(self.class_hash, constructor_calldata); let outputs = handle_cheatcode(cheatcode::<'precalculate_address'>(inputs.span())); (*outputs[0]).try_into().unwrap() } fn deploy( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> SyscallResult<(ContractAddress, Span)> { let mut inputs = _prepare_calldata(self.class_hash, constructor_calldata); @@ -87,9 +85,7 @@ impl ContractClassImpl of ContractClassTrait { } fn deploy_at( - self: @ContractClass, - constructor_calldata: @Array::, - contract_address: ContractAddress + self: @ContractClass, constructor_calldata: Span, contract_address: ContractAddress ) -> SyscallResult<(ContractAddress, Span)> { let mut inputs = _prepare_calldata(self.class_hash, constructor_calldata); inputs.append(contract_address.into()); @@ -154,7 +150,7 @@ pub fn get_class_hash(contract_address: ContractAddress) -> ClassHash { } fn _prepare_calldata( - class_hash: @ClassHash, constructor_calldata: @Array:: + class_hash: @ClassHash, constructor_calldata: Span ) -> Array:: { let class_hash: felt252 = class_hash.clone().into(); let mut inputs: Array:: = array![class_hash]; diff --git a/snforge_std/src/cheatcodes/events.cairo b/snforge_std/src/cheatcodes/events.cairo index 539949927d..1863b070a6 100644 --- a/snforge_std/src/cheatcodes/events.cairo +++ b/snforge_std/src/cheatcodes/events.cairo @@ -58,14 +58,14 @@ impl EventFetcherImpl of EventFetcher { } pub trait EventAssertions, impl TDrop: Drop> { - fn assert_emitted(ref self: EventSpy, events: @Array<(ContractAddress, T)>); - fn assert_not_emitted(ref self: EventSpy, events: @Array<(ContractAddress, T)>); + fn assert_emitted(ref self: EventSpy, events: Span<(ContractAddress, T)>); + fn assert_not_emitted(ref self: EventSpy, events: Span<(ContractAddress, T)>); } impl EventAssertionsImpl< T, impl TEvent: starknet::Event, impl TDrop: Drop > of EventAssertions { - fn assert_emitted(ref self: EventSpy, events: @Array<(ContractAddress, T)>) { + fn assert_emitted(ref self: EventSpy, events: Span<(ContractAddress, T)>) { self.fetch_events(); let mut i = 0; @@ -86,7 +86,7 @@ impl EventAssertionsImpl< }; } - fn assert_not_emitted(ref self: EventSpy, events: @Array<(ContractAddress, T)>) { + fn assert_not_emitted(ref self: EventSpy, events: Span<(ContractAddress, T)>) { self.fetch_events(); let mut i = 0;