Skip to content

Commit 8399dab

Browse files
authored
Test deployment scenarios (#721)
1 parent d49b605 commit 8399dab

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

tests/integration/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod test_advancing_time;
1515
mod test_balance;
1616
mod test_blocks_generation;
1717
mod test_call;
18+
mod test_deploy;
1819
mod test_dump_and_load;
1920
mod test_estimate_fee;
2021
mod test_estimate_message_fee;

tests/integration/test_deploy.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use std::sync::Arc;
2+
3+
use server::test_utils::assert_contains;
4+
use starknet_rs_accounts::{Account, ExecutionEncoding, SingleOwnerAccount};
5+
use starknet_rs_contract::ContractFactory;
6+
use starknet_rs_core::types::Felt;
7+
8+
use crate::common::background_devnet::BackgroundDevnet;
9+
use crate::common::constants;
10+
use crate::common::utils::get_simple_contract_in_sierra_and_compiled_class_hash;
11+
12+
#[tokio::test]
13+
async fn double_deployment_not_allowed() {
14+
let devnet = BackgroundDevnet::spawn().await.unwrap();
15+
16+
let (signer, account_address) = devnet.get_first_predeployed_account().await;
17+
let account = SingleOwnerAccount::new(
18+
&devnet.json_rpc_client,
19+
signer,
20+
account_address,
21+
constants::CHAIN_ID,
22+
ExecutionEncoding::New,
23+
);
24+
25+
// declare
26+
let (contract_class, casm_hash) = get_simple_contract_in_sierra_and_compiled_class_hash();
27+
let declaration_result = account
28+
.declare_v3(Arc::new(contract_class), casm_hash)
29+
.gas(1e7 as u64)
30+
.send()
31+
.await
32+
.unwrap();
33+
34+
// prepare deployment
35+
let contract_factory = ContractFactory::new(declaration_result.class_hash, account.clone());
36+
let ctor_args = vec![Felt::ZERO]; // initial value
37+
let salt = Felt::from(10);
38+
let unique = false;
39+
40+
// first deployment should be successful
41+
contract_factory.deploy_v3(ctor_args.clone(), salt, unique).send().await.unwrap();
42+
43+
// second deployment should be unsuccessful
44+
match contract_factory.deploy_v3(ctor_args, salt, unique).send().await {
45+
Err(e) => assert_contains(&format!("{e:?}"), "unavailable for deployment"),
46+
other => panic!("Unexpected result: {other:?}"),
47+
};
48+
}
49+
50+
#[tokio::test]
51+
async fn cannot_deploy_undeclared_class() {
52+
let devnet = BackgroundDevnet::spawn().await.unwrap();
53+
54+
let (signer, account_address) = devnet.get_first_predeployed_account().await;
55+
let account = SingleOwnerAccount::new(
56+
&devnet.json_rpc_client,
57+
signer,
58+
account_address,
59+
constants::CHAIN_ID,
60+
ExecutionEncoding::New,
61+
);
62+
63+
// skip declaration
64+
let (contract_class, _) = get_simple_contract_in_sierra_and_compiled_class_hash();
65+
66+
// prepare deployment
67+
let contract_factory = ContractFactory::new(contract_class.class_hash(), account.clone());
68+
let ctor_args = vec![Felt::ZERO]; // initial value
69+
let salt = Felt::from(10);
70+
let unique = false;
71+
72+
// deployment should fail
73+
match contract_factory.deploy_v3(ctor_args, salt, unique).send().await {
74+
Err(e) => assert_contains(&format!("{e:?}"), "not declared"),
75+
other => panic!("Unexpected result: {other:?}"),
76+
};
77+
}

0 commit comments

Comments
 (0)