-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling deploy constructor errors
- Loading branch information
Showing
7 changed files
with
239 additions
and
8 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
protostar-rust/tests/data/deploy_error_handling_test/Scarb.toml
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,11 @@ | ||
[package] | ||
name = "deploy_error_handling_test" | ||
version = "0.1.0" | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
|
||
[dependencies] | ||
starknet = "2.0.0-rc2" | ||
|
||
[tool.protostar] |
15 changes: 15 additions & 0 deletions
15
protostar-rust/tests/data/deploy_error_handling_test/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,15 @@ | ||
#[starknet::contract] | ||
mod PanickingConstructor { | ||
use array::ArrayTrait; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState) { | ||
let mut panic_data = ArrayTrait::new(); | ||
panic_data.append('PANIK'); | ||
panic_data.append('DEJTA'); | ||
panic(panic_data); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
protostar-rust/tests/data/deploy_error_handling_test/tests/test_deploy_error_handling.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,23 @@ | ||
use result::ResultTrait; | ||
use protostar_print::PrintTrait; | ||
use cheatcodes::RevertedTransactionTrait; | ||
use cheatcodes::PreparedContract; | ||
use array::ArrayTrait; | ||
|
||
#[test] | ||
fn test_deploy_error_handling() { | ||
let class_hash = declare('PanickingConstructor').expect('Could not declare'); | ||
let prepared_contract = PreparedContract { | ||
contract_address: 'addr', | ||
class_hash: class_hash, | ||
constructor_calldata: @ArrayTrait::new() | ||
}; | ||
|
||
match deploy(prepared_contract) { | ||
Result::Ok(_) => panic_with_felt252('Should have panicked'), | ||
Result::Err(x) => { | ||
assert(*x.panic_data.at(0_usize) == 'PANIK', *x.panic_data.at(0_usize)); | ||
assert(*x.panic_data.at(1_usize) == 'DEJTA', *x.panic_data.at(1_usize)); | ||
} | ||
} | ||
} |
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