Skip to content

Commit bc976b1

Browse files
committed
Add tests for diagnostics
commit-id:34dd50be
1 parent b0ef916 commit bc976b1

40 files changed

+1080
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/forge/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ tempfile.workspace = true
6565
cairo-lang-starknet-classes.workspace = true
6666
walkdir.workspace = true
6767
test-case.workspace = true
68+
itertools.workspace = true
6869
docs = { workspace = true, features = ["testing"] }
6970
packages_validation = { path = "../testing/packages_validation"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "attributes"
3+
version = "0.1.0"
4+
edition = "2024_07"
5+
6+
[dependencies]
7+
starknet = "2.9.3"
8+
9+
[dev-dependencies]
10+
snforge_std = { path = "../../../../../../snforge_std" }
11+
12+
[[target.starknet-contract]]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#[starknet::interface]
2+
pub trait IHelloStarknet<TContractState> {
3+
fn increase_balance(ref self: TContractState, amount: felt252);
4+
fn get_balance(self: @TContractState) -> felt252;
5+
fn do_a_panic(self: @TContractState);
6+
fn do_a_panic_with(self: @TContractState, panic_data: Array<felt252>);
7+
}
8+
9+
#[starknet::contract]
10+
pub mod HelloStarknet {
11+
use core::array::ArrayTrait;
12+
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
13+
14+
#[storage]
15+
struct Storage {
16+
balance: felt252,
17+
}
18+
19+
#[abi(embed_v0)]
20+
impl IHelloStarknetImpl of super::IHelloStarknet<ContractState> {
21+
// Increases the balance by the given amount
22+
fn increase_balance(ref self: ContractState, amount: felt252) {
23+
self.balance.write(self.balance.read() + amount);
24+
}
25+
26+
// Returns the current balance
27+
fn get_balance(self: @ContractState) -> felt252 {
28+
self.balance.read()
29+
}
30+
31+
// Panics
32+
fn do_a_panic(self: @ContractState) {
33+
let mut arr = ArrayTrait::new();
34+
arr.append('PANIC');
35+
arr.append('DAYTAH');
36+
panic(arr);
37+
}
38+
39+
// Panics with given array data
40+
fn do_a_panic_with(self: @ContractState, panic_data: Array<felt252>) {
41+
panic(panic_data);
42+
}
43+
}
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod hello_starknet;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use core::array::ArrayTrait;
2+
use core::result::ResultTrait;
3+
use snforge_std::cheatcodes::contract_class::DeclareResultTrait;
4+
use snforge_std::{ContractClassTrait, declare};
5+
6+
@attrs@
7+
fn call_and_invoke1(_a: felt252, b: u256) {
8+
let contract = declare("HelloStarknet").unwrap().contract_class();
9+
let constructor_calldata = @ArrayTrait::new();
10+
let (_contract_address1, _) = contract.deploy(constructor_calldata).unwrap()
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "generic"
3+
version = "0.1.0"
4+
edition = "2024_07"
5+
6+
[dependencies]
7+
starknet = "2.9.3"
8+
9+
[dev-dependencies]
10+
snforge_std = { path = "../../../../../../snforge_std" }
11+
12+
[[target.starknet-contract]]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#[starknet::interface]
2+
pub trait IHelloStarknet<TContractState> {
3+
fn increase_balance(ref self: TContractState, amount: felt252);
4+
fn get_balance(self: @TContractState) -> felt252;
5+
fn do_a_panic(self: @TContractState);
6+
fn do_a_panic_with(self: @TContractState, panic_data: Array<felt252>);
7+
}
8+
9+
#[starknet::contract]
10+
pub mod HelloStarknet {
11+
use core::array::ArrayTrait;
12+
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
13+
14+
#[storage]
15+
struct Storage {
16+
balance: felt252,
17+
}
18+
19+
#[abi(embed_v0)]
20+
impl IHelloStarknetImpl of super::IHelloStarknet<ContractState> {
21+
// Increases the balance by the given amount
22+
fn increase_balance(ref self: ContractState, amount: felt252) {
23+
self.balance.write(self.balance.read() + amount);
24+
}
25+
26+
// Returns the current balance
27+
fn get_balance(self: @ContractState) -> felt252 {
28+
self.balance.read()
29+
}
30+
31+
// Panics
32+
fn do_a_panic(self: @ContractState) {
33+
let mut arr = ArrayTrait::new();
34+
arr.append('PANIC');
35+
arr.append('DAYTAH');
36+
panic(arr);
37+
}
38+
39+
// Panics with given array data
40+
fn do_a_panic_with(self: @ContractState, panic_data: Array<felt252>) {
41+
panic(panic_data);
42+
}
43+
}
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod hello_starknet;

0 commit comments

Comments
 (0)