-
Notifications
You must be signed in to change notification settings - Fork 48
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
Test deploy cheatcode #2132
Test deploy cheatcode #2132
Changes from 5 commits
7b706c3
9a2f8ad
b497942
5e59488
876eb86
649b9f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "deploy_test" | ||
version = "0.1.0" | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
|
||
[dependencies] | ||
starknet = "2.0.0-rc2" | ||
|
||
[tool.protostar] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[starknet::contract] | ||
mod HelloStarknet { | ||
#[storage] | ||
struct Storage { | ||
balance: felt252, | ||
} | ||
|
||
// Increases the balance by the given amount. | ||
#[external] | ||
fn increase_balance(ref self: ContractState, amount: felt252) { | ||
self.balance.write(self.balance.read() + amount); | ||
} | ||
|
||
// Returns the current balance. | ||
#[external] | ||
fn get_balance(self: @ContractState) -> felt252 { | ||
self.balance.read() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use result::ResultTrait; | ||
use protostar_print::PrintTrait; | ||
use array::ArrayTrait; | ||
use cheatcodes::PreparedContract; | ||
|
||
#[test] | ||
fn test_deploy_simple() { | ||
let calldata = ArrayTrait::<felt252>::new(); | ||
let class_hash = declare('deploy_test').expect('Could not declare'); | ||
|
||
let contract_address = deploy( | ||
PreparedContract { | ||
class_hash, | ||
constructor_calldata: @calldata, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if error is raised by the constructor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure constructor is executed, can we have test case for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For now it panics, but it's not the target behavior
OK. |
||
contract_address: 'addr' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So deploy will use whatever contract address it gets passed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes sir There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you can see here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if he had some simplification here so user can write something like this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally user would use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think deploy_contract will be obsolete when we remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was not aware of such idea, fair point. Although this is out of scope for this PR. |
||
} | ||
).expect('Could not deploy'); | ||
assert(contract_address == 'addr', 'incorrect contract_address'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if non-existing class_hash is passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess panic, but this can be tested