Skip to content

Commit 0dcae6d

Browse files
committed
chore: cargo fmt-stacks
1 parent d1be1f7 commit 0dcae6d

File tree

6 files changed

+80
-49
lines changed

6 files changed

+80
-49
lines changed

clarity/src/vm/contexts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use serde::Serialize;
2323
use serde_json::json;
2424
use stacks_common::consts::CHAIN_ID_TESTNET;
2525
use stacks_common::types::chainstate::StacksBlockId;
26-
use stacks_common::types::StacksEpochId;
27-
use stacks_common::types::{StacksHashMap as HashMap, StacksHashSet as HashSet};
26+
use stacks_common::types::{StacksEpochId, StacksHashMap as HashMap, StacksHashSet as HashSet};
2827

2928
use super::EvalHook;
3029
use crate::vm::ast::{ASTRules, ContractAST};

clarity/src/vm/database/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ mod key_value_wrapper;
3434
mod sqlite;
3535
mod structures;
3636
#[cfg(feature = "testing")]
37-
mod tests;
37+
mod tests;

clarity/src/vm/database/tests/clarity_db_tests.rs

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
use fake::{Faker, Fake};
1+
use fake::{Fake, Faker};
22
use rusqlite::NO_PARAMS;
33
use stacks_common::util::hash::Sha512Trunc256Sum;
44

5-
use crate::vm::{contracts::Contract, database::{clarity_store::ContractCommitment, ClarityBackingStore, ClarityDatabase, ClaritySerializable, MemoryBackingStore, NULL_BURN_STATE_DB, NULL_HEADER_DB}, fakes::raw::EnglishWord, Value};
5+
use crate::vm::contracts::Contract;
6+
use crate::vm::database::clarity_store::ContractCommitment;
7+
use crate::vm::database::{
8+
ClarityBackingStore, ClarityDatabase, ClaritySerializable, MemoryBackingStore,
9+
NULL_BURN_STATE_DB, NULL_HEADER_DB,
10+
};
11+
use crate::vm::fakes::raw::EnglishWord;
12+
use crate::vm::Value;
613

714
#[test]
815
fn insert_contract() {
@@ -18,12 +25,12 @@ fn insert_contract() {
1825
db.insert_contract(&contract_id, contract)
1926
.expect("failed to insert contract into backing store");
2027

21-
let exists = sql_exists(
28+
let exists = sql_exists(
2229
&mut store,
2330
&format!(
24-
"SELECT * FROM metadata_table WHERE key LIKE '%{}%'",
31+
"SELECT * FROM metadata_table WHERE key LIKE '%{}%'",
2532
contract_id.to_string()
26-
)
33+
),
2734
);
2835
assert!(!exists);
2936
}
@@ -43,7 +50,8 @@ fn get_contract() {
4350
db.insert_contract(&contract_id, contract.clone())
4451
.expect("failed to insert contract into backing store");
4552

46-
let retrieved_contract = db.get_contract(&contract_id)
53+
let retrieved_contract = db
54+
.get_contract(&contract_id)
4755
.expect("failed to retrieve contract from backing store");
4856

4957
assert_eq!(contract, retrieved_contract);
@@ -81,10 +89,14 @@ fn insert_contract_with_commit_should_exist_in_backing_store() {
8189
db.commit().expect("failed to commit to backing store");
8290

8391
let count = sql_query_u32(
84-
&mut store,
85-
&format!("SELECT COUNT(*) FROM metadata_table WHERE key LIKE '{}'",
86-
format!("clr-meta::{}::vm-metadata::9::contract", contract_id.to_string())
87-
)
92+
&mut store,
93+
&format!(
94+
"SELECT COUNT(*) FROM metadata_table WHERE key LIKE '{}'",
95+
format!(
96+
"clr-meta::{}::vm-metadata::9::contract",
97+
contract_id.to_string()
98+
)
99+
),
88100
);
89101

90102
assert_eq!(1, count);
@@ -99,10 +111,14 @@ fn put_data_no_commit() {
99111

100112
db.begin();
101113

102-
db.put("hello", &ContractCommitment {
103-
block_height: 1,
104-
hash: Sha512Trunc256Sum::from_data(&[1, 2, 3, 4])
105-
}).expect("failed to put data");
114+
db.put(
115+
"hello",
116+
&ContractCommitment {
117+
block_height: 1,
118+
hash: Sha512Trunc256Sum::from_data(&[1, 2, 3, 4]),
119+
},
120+
)
121+
.expect("failed to put data");
106122

107123
let count = sql_query_u32(&mut store, "SELECT COUNT(*) FROM data_table");
108124
assert_eq!(0, count);
@@ -118,16 +134,20 @@ fn put_data_with_commit_should_exist_in_backing_store() {
118134
db.begin();
119135

120136
let key = Faker.fake::<String>();
121-
db.put(&key, &ContractCommitment {
122-
block_height: Faker.fake(),
123-
hash: Sha512Trunc256Sum::from_data(&Faker.fake::<Vec<u8>>())
124-
}).expect("failed to put data");
137+
db.put(
138+
&key,
139+
&ContractCommitment {
140+
block_height: Faker.fake(),
141+
hash: Sha512Trunc256Sum::from_data(&Faker.fake::<Vec<u8>>()),
142+
},
143+
)
144+
.expect("failed to put data");
125145

126146
db.commit().expect("failed to commit to backing store");
127147

128148
let count = sql_query_u32(
129-
&mut store,
130-
&format!("SELECT COUNT(*) FROM data_table where key = '{}'", key)
149+
&mut store,
150+
&format!("SELECT COUNT(*) FROM data_table where key = '{}'", key),
131151
);
132152
assert_eq!(1, count);
133153
}
@@ -140,38 +160,38 @@ fn put_data_without_begin_fails() {
140160
let mut db = ClarityDatabase::new(&mut store, &NULL_HEADER_DB, &NULL_BURN_STATE_DB);
141161

142162
let key = Faker.fake::<String>();
143-
db.put(&key, &ContractCommitment {
144-
block_height: Faker.fake(),
145-
hash: Sha512Trunc256Sum::from_data(&Faker.fake::<Vec<u8>>())
146-
}).expect_err("expected not-nested error");
163+
db.put(
164+
&key,
165+
&ContractCommitment {
166+
block_height: Faker.fake(),
167+
hash: Sha512Trunc256Sum::from_data(&Faker.fake::<Vec<u8>>()),
168+
},
169+
)
170+
.expect_err("expected not-nested error");
147171
}
148172
}
149173

150174
/// Executes the provided SQL query, which is expected to return a positive
151175
/// integer, and returns it as a u32. Panics upon SQL failure.
152176
fn sql_query_u32<S: ClarityBackingStore>(store: &mut S, sql: &str) -> u32 {
153177
let sqlite = store.get_side_store();
154-
sqlite.query_row(
155-
sql,
156-
NO_PARAMS,
157-
|row| {
178+
sqlite
179+
.query_row(sql, NO_PARAMS, |row| {
158180
let i: u32 = row.get(0)?;
159181
Ok(i)
160-
}
161-
).expect("failed to verify results in sqlite")
182+
})
183+
.expect("failed to verify results in sqlite")
162184
}
163185

164-
/// Executes the provided SQL query as a subquery within a `SELECT EXISTS(...)`
186+
/// Executes the provided SQL query as a subquery within a `SELECT EXISTS(...)`
165187
/// statement. Returns true if the statement returns any rows, false otherwise.
166188
/// Panics upon SQL failure.
167189
fn sql_exists<S: ClarityBackingStore>(store: &mut S, sql: &str) -> bool {
168190
let sqlite = store.get_side_store();
169-
sqlite.query_row(
170-
&format!("SELECT EXISTS({});", sql),
171-
NO_PARAMS,
172-
|row| {
191+
sqlite
192+
.query_row(&format!("SELECT EXISTS({});", sql), NO_PARAMS, |row| {
173193
let exists: bool = row.get(0)?;
174194
Ok(exists)
175-
}
176-
).expect("failed to verify results in sqlite")
177-
}
195+
})
196+
.expect("failed to verify results in sqlite")
197+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mod clarity_db_tests;
1+
mod clarity_db_tests;

clarity/src/vm/fakes.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ pub mod raw {
103103

104104
impl Dummy<Faker> for DefinedFunction {
105105
fn dummy_with_rng<R: Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
106-
107106
let arg_types: Vec<TypeSignature> = (0..rng.gen_range(1..3))
108107
.into_iter()
109108
.map(|_| random_type_signature(None, rng))
@@ -116,12 +115,11 @@ pub mod raw {
116115

117116
DefinedFunction {
118117
define_type: Faker.fake_with_rng(rng),
119-
name: Faker.fake_with_rng(rng),
118+
name: Faker.fake_with_rng(rng),
120119
arg_types,
121120
arguments,
122121
body: Faker.fake_with_rng(rng),
123122
identifier: Faker.fake_with_rng(rng),
124-
125123
}
126124
}
127125
}
@@ -177,7 +175,12 @@ pub mod raw {
177175
))),
178176
TypeSignature::TupleType(TupleTypeSignature {
179177
type_map: (0..rng.gen_range(1..3))
180-
.map(|_| (Faker.fake_with_rng(rng), random_type_signature(next_level, rng)))
178+
.map(|_| {
179+
(
180+
Faker.fake_with_rng(rng),
181+
random_type_signature(next_level, rng),
182+
)
183+
})
181184
.collect(),
182185
}),
183186
];
@@ -251,7 +254,12 @@ pub mod raw {
251254
.collect(),
252255
type_signature: TupleTypeSignature {
253256
type_map: (0..rng.gen_range(1..3))
254-
.map(|_| (Faker.fake_with_rng(rng), random_type_signature(next_level, rng)))
257+
.map(|_| {
258+
(
259+
Faker.fake_with_rng(rng),
260+
random_type_signature(next_level, rng),
261+
)
262+
})
255263
.collect(),
256264
},
257265
}),
@@ -366,7 +374,11 @@ pub mod raw {
366374
FunctionType::ArithmeticUnary,
367375
FunctionType::ArithmeticComparison,
368376
FunctionType::ArithmeticVariadic,
369-
FunctionType::Binary(Faker.fake_with_rng(rng), Faker.fake_with_rng(rng), Faker.fake_with_rng(rng)),
377+
FunctionType::Binary(
378+
Faker.fake_with_rng(rng),
379+
Faker.fake_with_rng(rng),
380+
Faker.fake_with_rng(rng),
381+
),
370382
];
371383

372384
fn_types[rng.gen_range(0..fn_types.len())].clone()

stacks-common/src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use crate::util::hash::Hash160;
1313
use crate::util::secp256k1::{MessageSignature, Secp256k1PublicKey};
1414

1515
pub mod chainstate;
16-
pub mod net;
1716
pub mod hashmap;
1817
pub mod hashset;
18+
pub mod net;
1919

2020
pub use hashmap::StacksHashMap;
2121
pub use hashset::StacksHashSet;

0 commit comments

Comments
 (0)