-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get features from all targets (#2570)
<!-- Reference any GitHub issues resolved by this PR --> Closes #2568 Closes #2567 ## Introduced changes <!-- A brief description of the changes --> - Fixed features support for optimized compilation - Changed the starknet artifacts loading logic so they work with custom test targets. - Artifacts are now loaded from all test targets - Artifacts are now compiled to casm concurrently - Refactored the scarb-api crate ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --------- Co-authored-by: Piotr Magiera <56825108+piotmag769@users.noreply.github.com>
- Loading branch information
1 parent
5b152d7
commit 44f3196
Showing
52 changed files
with
1,611 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "custom_target" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
starknet = "2.7.0" | ||
|
||
[dev-dependencies] | ||
snforge_std = { path = "../../../../../../snforge_std" } | ||
|
||
[[target.starknet-contract]] | ||
|
||
[[test]] | ||
name = "custom_target_integrationtest" | ||
kind = "test" | ||
source-path = "./tests/tests.cairo" | ||
test-type = "integration" | ||
|
||
[[test]] | ||
name = "custom_target_unittest" | ||
kind = "test" | ||
test-type = "unit" | ||
|
||
[tool.snforge] | ||
exit_first = false |
55 changes: 55 additions & 0 deletions
55
crates/forge/tests/data/targets/custom_target/src/lib.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#[starknet::interface] | ||
trait IHelloStarknet<TContractState> { | ||
fn increase_balance(ref self: TContractState, amount: felt252); | ||
fn get_balance(self: @TContractState) -> felt252; | ||
fn do_a_panic(self: @TContractState); | ||
fn do_a_panic_with(self: @TContractState, panic_data: Array<felt252>); | ||
} | ||
|
||
#[starknet::contract] | ||
mod HelloStarknet { | ||
use array::ArrayTrait; | ||
|
||
#[storage] | ||
struct Storage { | ||
balance: felt252, | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl IHelloStarknetImpl of super::IHelloStarknet<ContractState> { | ||
// Increases the balance by the given amount | ||
fn increase_balance(ref self: ContractState, amount: felt252) { | ||
self.balance.write(self.balance.read() + amount); | ||
} | ||
|
||
// Returns the current balance | ||
fn get_balance(self: @ContractState) -> felt252 { | ||
self.balance.read() | ||
} | ||
|
||
// Panics | ||
fn do_a_panic(self: @ContractState) { | ||
let mut arr = ArrayTrait::new(); | ||
arr.append('PANIC'); | ||
arr.append('DAYTAH'); | ||
panic(arr); | ||
} | ||
|
||
// Panics with given array data | ||
fn do_a_panic_with(self: @ContractState, panic_data: Array<felt252>) { | ||
panic(panic_data); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use snforge_std::{declare, ContractClassTrait}; | ||
use snforge_std::cheatcodes::contract_class::DeclareResultTrait; | ||
|
||
#[test] | ||
fn declare_contract_from_lib() { | ||
let _ = declare("HelloStarknet").unwrap().contract_class(); | ||
assert(2 == 2, 'Should declare'); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
crates/forge/tests/data/targets/custom_target/tests/tests.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use array::ArrayTrait; | ||
use result::ResultTrait; | ||
use option::OptionTrait; | ||
use traits::TryInto; | ||
use starknet::ContractAddress; | ||
use starknet::Felt252TryIntoContractAddress; | ||
|
||
use snforge_std::{declare, ContractClassTrait}; | ||
use snforge_std::cheatcodes::contract_class::DeclareResultTrait; | ||
|
||
use custom_target::IHelloStarknetDispatcher; | ||
use custom_target::IHelloStarknetDispatcherTrait; | ||
|
||
#[test] | ||
fn declare_and_call_contract_from_lib() { | ||
let contract = declare("HelloStarknet").unwrap().contract_class(); | ||
let constructor_calldata = @ArrayTrait::new(); | ||
let (contract_address, _) = contract.deploy(constructor_calldata).unwrap(); | ||
let dispatcher = IHelloStarknetDispatcher { contract_address }; | ||
|
||
let balance = dispatcher.get_balance(); | ||
assert(balance == 0, 'balance == 0'); | ||
|
||
dispatcher.increase_balance(100); | ||
|
||
let balance = dispatcher.get_balance(); | ||
assert(balance == 100, 'balance != 100'); | ||
} |
Oops, something went wrong.