Skip to content

Commit 4cdb89a

Browse files
tkumor3THenry14
andauthored
Fix false positive test (#1529)
<!-- Reference any GitHub issues resolved by this PR --> Closes # ## Introduced changes <!-- A brief description of the changes --> - ## 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: Wojciech Szymczyk <[email protected]>
1 parent 064d945 commit 4cdb89a

File tree

6 files changed

+86
-15
lines changed

6 files changed

+86
-15
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"deployment": {
3+
"address": "0x4ee94bdf625820bc562c49c4d1ca4b2ef82bcfc5ed0cf67464770bea333b19a",
4+
"class_hash": "0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f",
5+
"status": "deployed"
6+
},
7+
"variant": {
8+
"public_key": "0xd39cc3278f855cb025b28409d16137792175638a8acec3b5b3d2487d2472a6",
9+
"type": "open_zeppelin",
10+
"version": 1
11+
},
12+
"version": 1
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"crypto": {
3+
"cipher": "aes-128-ctr",
4+
"cipherparams": { "iv": "969dc1d196eccd96518b4945820a7ac0" },
5+
"ciphertext": "fd20c0dfa110976bffa70b54321487c4546d0c26816c8383ffcfa1ba099f73b1",
6+
"kdf": "scrypt",
7+
"kdfparams": {
8+
"dklen": 32,
9+
"n": 8192,
10+
"p": 1,
11+
"r": 8,
12+
"salt": "177919634a458573cf15ee537f658cca630d32aaae1a3b7cecf86a427ef01ea9"
13+
},
14+
"mac": "adada9c6d157999ba340dc99c6b6596698904026e3f619d025962d1cbcd2a50e"
15+
},
16+
"id": "caf9c371-4e46-45c7-b682-a44667a83725",
17+
"version": 3
18+
}

crates/sncast/tests/e2e/declare.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::helpers::fixtures::{
55
use indoc::indoc;
66
use snapbox::cmd::{cargo_bin, Command};
77
use starknet::core::types::TransactionReceipt::Declare;
8-
use std::fs;
98
use test_case::test_case;
109

1110
#[tokio::test]
@@ -38,8 +37,6 @@ async fn test_happy_case() {
3837
let receipt = get_transaction_receipt(hash).await;
3938

4039
assert!(matches!(receipt, Declare(_)));
41-
42-
fs::remove_dir_all(contract_path).unwrap();
4340
}
4441

4542
#[tokio::test]
@@ -144,8 +141,6 @@ fn test_too_low_max_fee() {
144141
command: declare
145142
error: Max fee is smaller than the minimal transaction cost
146143
"});
147-
148-
fs::remove_dir_all(contract_path).unwrap();
149144
}
150145

151146
#[test]

crates/sncast/tests/e2e/main_tests.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ async fn test_keystore_undeployed_account() {
250250
async fn test_keystore_declare() {
251251
let contract_path =
252252
duplicate_directory_with_salt(CONTRACTS_DIR.to_string() + "/map", "put", "999");
253-
let my_key_path = get_keystores_path("tests/data/keystore/my_key.json");
254-
let my_account_path = get_keystores_path("tests/data/keystore/my_account.json");
253+
let my_key_path = get_keystores_path("tests/data/keystore/predeployed_key.json");
254+
let my_account_path = get_keystores_path("tests/data/keystore/predeployed_account.json");
255255
let args = vec![
256256
"--url",
257257
URL,
@@ -269,7 +269,5 @@ async fn test_keystore_declare() {
269269
.current_dir(contract_path.path())
270270
.args(args);
271271

272-
snapbox.assert().success().get_output().stderr.is_empty();
273-
274-
fs::remove_dir_all(contract_path).unwrap();
272+
assert!(snapbox.assert().success().get_output().stderr.is_empty());
275273
}

crates/sncast/tests/helpers/devnet.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::helpers::constants::{DEVNET_ENV_FILE, SEED, URL};
2-
use crate::helpers::fixtures::{declare_contract, declare_deploy_contract, remove_devnet_env};
2+
use crate::helpers::fixtures::{
3+
declare_contract, declare_deploy_contract, deploy_keystore_account, remove_devnet_env,
4+
};
35
use ctor::{ctor, dtor};
46
use std::net::TcpStream;
57
use std::process::{Command, Stdio};
@@ -66,6 +68,9 @@ fn start_devnet() {
6668
"/constructor_with_params/target/dev/constructor_with_params_ConstructorWithParams",
6769
"CAST_WITH_CONSTRUCTOR",
6870
));
71+
72+
rt.block_on(deploy_keystore_account());
73+
6974
dotenv::from_filename(DEVNET_ENV_FILE).unwrap();
7075
}
7176

crates/sncast/tests/helpers/fixtures.rs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
use crate::helpers::constants::{ACCOUNT_FILE_PATH, CONTRACTS_DIR, DEVNET_ENV_FILE, URL};
1+
use crate::helpers::constants::{
2+
ACCOUNT_FILE_PATH, CONTRACTS_DIR, DEVNET_ENV_FILE, DEVNET_OZ_CLASS_HASH, URL,
3+
};
24
use camino::Utf8PathBuf;
35
use primitive_types::U256;
46
use serde::de::DeserializeOwned;
57
use serde::Deserialize;
68
use serde_json::{json, Map, Value};
7-
use sncast::{apply_optional, get_keystore_password};
9+
use sncast::{apply_optional, get_chain_id, get_keystore_password};
810
use sncast::{get_account, get_provider, parse_number};
9-
use starknet::accounts::{Account, Call, Execution};
11+
use starknet::accounts::{Account, AccountFactory, Call, Execution, OpenZeppelinAccountFactory};
1012
use starknet::contract::ContractFactory;
1113
use starknet::core::types::contract::{CompiledClass, SierraClass};
1214
use starknet::core::types::TransactionReceipt;
@@ -15,7 +17,7 @@ use starknet::core::utils::get_contract_address;
1517
use starknet::core::utils::get_selector_from_name;
1618
use starknet::providers::jsonrpc::HttpTransport;
1719
use starknet::providers::JsonRpcClient;
18-
use starknet::signers::SigningKey;
20+
use starknet::signers::{LocalWallet, SigningKey};
1921
use std::env;
2022
use std::fs;
2123
use std::fs::OpenOptions;
@@ -69,6 +71,46 @@ pub async fn declare_contract(account: &str, path: &str, shortname: &str) -> Fie
6971
class_hash
7072
}
7173

74+
pub async fn deploy_keystore_account() {
75+
let keystore_path = "tests/data/keystore/predeployed_key.json";
76+
let account_path = "tests/data/keystore/predeployed_account.json";
77+
let private_key =
78+
SigningKey::from_keystore(keystore_path, "123").expect("Could not get the private_key");
79+
80+
let provider = get_provider(URL).expect("Could not get the provider");
81+
let chain_id = get_chain_id(&provider)
82+
.await
83+
.expect("Could not get chain_id from provider");
84+
85+
let contents =
86+
std::fs::read_to_string(account_path).expect("Failed to read keystore account file");
87+
let items: serde_json::Value = serde_json::from_str(&contents)
88+
.unwrap_or_else(|_| panic!("Failed to parse keystore account file at = {account_path}"));
89+
90+
let factory = OpenZeppelinAccountFactory::new(
91+
parse_number(DEVNET_OZ_CLASS_HASH).expect("Could not parse DEVNET_OZ_CLASS_HASH"),
92+
chain_id,
93+
LocalWallet::from_signing_key(private_key),
94+
provider,
95+
)
96+
.await
97+
.expect("Could not create Account Factory");
98+
99+
mint_token(
100+
items["deployment"]["address"]
101+
.as_str()
102+
.expect("Could not get address"),
103+
9_999_999_999_999_999_999,
104+
)
105+
.await;
106+
107+
factory
108+
.deploy(parse_number("0xa5d90c65b1b1339").expect("Could not parse salt"))
109+
.send()
110+
.await
111+
.expect("Could not deploy keystore account");
112+
}
113+
72114
pub async fn declare_deploy_contract(account: &str, path: &str, shortname: &str) {
73115
let class_hash = declare_contract(account, path, shortname).await;
74116

0 commit comments

Comments
 (0)