Skip to content

Commit

Permalink
#1430 - enable clippy for tests, fix some
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Feb 16, 2022
1 parent d5a774a commit 1198d2f
Show file tree
Hide file tree
Showing 30 changed files with 241 additions and 276 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ clean:

lint: license clean
cargo fmt --all --check
cargo clippy -- -D warnings
cargo clippy --all-targets -- -D warnings

build:
cargo build --bin forest
Expand Down
52 changes: 26 additions & 26 deletions blockchain/chain/src/store/base_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,32 @@ mod tests {

fn construct_tests() -> Vec<(i64, i64, usize, i64, i64)> {
// (base_fee, limit_used, no_of_blocks, output)
let mut cases = Vec::new();
cases.push((100_000_000, 0, 1, 87_500_000, 87_500_000));
cases.push((100_000_000, 0, 5, 87_500_000, 87_500_000));
cases.push((100_000_000, BLOCK_GAS_TARGET, 1, 103_125_000, 100_000_000));
cases.push((
100_000_000,
BLOCK_GAS_TARGET * 2,
2,
103_125_000,
100_000_000,
));
cases.push((
100_000_000,
BLOCK_GAS_LIMIT * 2,
2,
112_500_000,
112_500_000,
));
cases.push((
100_000_000,
BLOCK_GAS_LIMIT * 15 / 10,
2,
110_937_500,
106_250_000,
));
cases
vec![
(100_000_000, 0, 1, 87_500_000, 87_500_000),
(100_000_000, 0, 5, 87_500_000, 87_500_000),
(100_000_000, BLOCK_GAS_TARGET, 1, 103_125_000, 100_000_000),
(
100_000_000,
BLOCK_GAS_TARGET * 2,
2,
103_125_000,
100_000_000,
),
(
100_000_000,
BLOCK_GAS_LIMIT * 2,
2,
112_500_000,
112_500_000,
),
(
100_000_000,
BLOCK_GAS_LIMIT * 15 / 10,
2,
110_937_500,
106_250_000,
),
]
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions blockchain/chain/src/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,9 +971,9 @@ mod tests {
let cs = ChainStore::new(Arc::new(db));

let cid = cid::new_from_cbor(&[1, 2, 3], Blake2b256);
assert_eq!(cs.is_block_validated(&cid).unwrap(), false);
assert!(!cs.is_block_validated(&cid).unwrap());

cs.mark_block_as_validated(&cid).unwrap();
assert_eq!(cs.is_block_validated(&cid).unwrap(), true);
assert!(cs.is_block_validated(&cid).unwrap());
}
}
4 changes: 2 additions & 2 deletions blockchain/message_pool/src/block_prob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ fn test_winner_probability() {

for _ in 0..n {
let mut miners_rand: f64 = rng.gen::<f64>() * f64::MAX;
for j in 0..MAX_BLOCKS {
miners_rand -= winner_prob[j];
for prob in winner_prob.iter().take(MAX_BLOCKS) {
miners_rand -= prob;
if miners_rand < 0.0 {
break;
}
Expand Down
5 changes: 2 additions & 3 deletions blockchain/message_pool/src/msgpool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,8 @@ pub mod tests {
.build()
.unwrap();
let msg_signing_bytes = umsg.to_signing_bytes();
let sig = wallet.sign(&from, msg_signing_bytes.as_slice()).unwrap();
let smsg = SignedMessage::new_from_parts(umsg, sig).unwrap();
smsg
let sig = wallet.sign(from, msg_signing_bytes.as_slice()).unwrap();
SignedMessage::new_from_parts(umsg, sig).unwrap()
}

#[test]
Expand Down
46 changes: 22 additions & 24 deletions blockchain/message_pool/src/msgpool/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,26 +742,26 @@ mod test_selection {
assert_eq!(msgs.len(), 20, "Expected 20 messages, got {}", msgs.len());

let mut next_nonce = 0;
for i in 0..10 {
for (i, msg) in msgs.iter().enumerate().take(10) {
assert_eq!(
*msgs[i].from(),
*msg.from(),
a1,
"first 10 returned messages should be from actor a1 {}",
i
);
assert_eq!(msgs[i].sequence(), next_nonce, "nonce should be in order");
assert_eq!(msg.sequence(), next_nonce, "nonce should be in order");
next_nonce += 1;
}

next_nonce = 0;
for i in 10..20 {
for (i, msg) in msgs.iter().enumerate().take(20).skip(10) {
assert_eq!(
*msgs[i].from(),
*msg.from(),
a2,
"next 10 returned messages should be from actor a2 {}",
i
);
assert_eq!(msgs[i].sequence(), next_nonce, "nonce should be in order");
assert_eq!(msg.sequence(), next_nonce, "nonce should be in order");
next_nonce += 1;
}

Expand Down Expand Up @@ -832,23 +832,23 @@ mod test_selection {
);

let mut next_nonce = 20;
for i in 0..10 {
for msg in msgs.iter().take(10) {
assert_eq!(
*msgs[i].from(),
*msg.from(),
a1,
"first 10 returned messages should be from actor a1"
);
assert_eq!(msgs[i].sequence(), next_nonce, "nonce should be in order");
assert_eq!(msg.sequence(), next_nonce, "nonce should be in order");
next_nonce += 1;
}
next_nonce = 20;
for i in 10..20 {
for msg in msgs.iter().take(20).skip(10) {
assert_eq!(
*msgs[i].from(),
*msg.from(),
a2,
"next 10 returned messages should be from actor a2"
);
assert_eq!(msgs[i].sequence(), next_nonce, "nonce should be in order");
assert_eq!(msg.sequence(), next_nonce, "nonce should be in order");
next_nonce += 1;
}
}
Expand Down Expand Up @@ -1010,23 +1010,23 @@ mod test_selection {
assert_eq!(msgs.len(), 20);

let mut next_nonce = 0;
for i in 0..10 {
for msg in msgs.iter().take(10) {
assert_eq!(
*msgs[i].from(),
*msg.from(),
a1,
"first 10 returned messages should be from actor a1"
);
assert_eq!(msgs[i].sequence(), next_nonce, "nonce should be in order");
assert_eq!(msg.sequence(), next_nonce, "nonce should be in order");
next_nonce += 1;
}
next_nonce = 0;
for i in 10..20 {
for msg in msgs.iter().take(20).skip(10) {
assert_eq!(
*msgs[i].from(),
*msg.from(),
a2,
"next 10 returned messages should be from actor a2"
);
assert_eq!(msgs[i].sequence(), next_nonce, "nonce should be in order");
assert_eq!(msg.sequence(), next_nonce, "nonce should be in order");
next_nonce += 1;
}
}
Expand Down Expand Up @@ -1100,17 +1100,15 @@ mod test_selection {

assert_eq!(msgs.len(), expected_msgs as usize);

let mut next_nonce = 0u64;
for m in msgs {
for (next_nonce, m) in msgs.into_iter().enumerate() {
assert_eq!(m.message().from(), &a1, "Expected message from a1");
assert_eq!(
m.message().sequence,
next_nonce,
next_nonce as u64,
"expected nonce {} but got {}",
next_nonce,
m.message().sequence
);
next_nonce += 1;
}
}

Expand Down Expand Up @@ -1278,7 +1276,7 @@ mod test_selection {
for a in &mut actors {
api.write()
.await
.set_state_balance_raw(&a, types::DefaultNetworkParams::from_fil(1));
.set_state_balance_raw(a, types::DefaultNetworkParams::from_fil(1));
// in FIL
}

Expand Down Expand Up @@ -1317,7 +1315,7 @@ mod test_selection {
}
}
// Lotus has -1, but since we don't have -ve indexes, set it some unrealistic number
return 9999999;
9999999
};

let mut nonces = vec![0; n_actors as usize];
Expand Down
13 changes: 7 additions & 6 deletions crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,17 @@ mod tests {
.collect();

let mut public_keys_slice: Vec<&[u8]> = vec![];
for i in 0..num_sigs {
public_keys_slice.push(&public_keys[i]);
for key in public_keys.iter().take(num_sigs) {
public_keys_slice.push(key);
}

let calculated_bls_agg =
Signature::new_bls(bls_signatures::aggregate(&signatures).unwrap().as_bytes());
assert_eq!(
verify_bls_aggregate(&data, &public_keys_slice, &calculated_bls_agg),
true
);
assert!(verify_bls_aggregate(
&data,
&public_keys_slice,
&calculated_bls_agg
),);
}

#[test]
Expand Down
15 changes: 7 additions & 8 deletions forest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ const RELEASE_TRACK: &str = "unstable";
#[cfg(feature = "release")]
const RELEASE_TRACK: &str = "alpha";

#[cfg(feature = "devnet")]
const NETWORK: &str = "devnet";

#[cfg(feature = "interopnet")]
const NETWORK: &str = "interopnet";

#[cfg(all(not(feature = "devnet"), not(feature = "interopnet")))]
const NETWORK: &str = "mainnet";
const NETWORK: &str = if cfg!(devnet) {
"devnet"
} else if cfg!(interopnet) {
"interopnet"
} else {
"mainnet"
};

fn main() {
// expose environment variable FOREST_VERSON at build time
Expand Down
2 changes: 1 addition & 1 deletion ipld/amt/benches/amt_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Serialize for BenchData {
where
S: Serializer,
{
(()).serialize(serializer)
().serialize(serializer)
}
}
impl<'de> Deserialize<'de> for BenchData {
Expand Down
5 changes: 2 additions & 3 deletions ipld/car/tests/car_file_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use forest_car::*;
async fn load_into_blockstore() {
let file = File::open("tests/test.car").await.unwrap();
let buf_reader = BufReader::new(file);
let mut bs = MemoryDB::default();

let _ = load_car(&mut bs, buf_reader).await.unwrap();
let bs = MemoryDB::default();
let _ = load_car(&bs, buf_reader).await.unwrap();
}
3 changes: 2 additions & 1 deletion ipld/tests/selector_explore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ fn selector_explore_tests() {
assert!(
test_equal(&result, &tv.result_selector),
"({}) Failed:\nExpected: {:?}\nFound: {:?}",
tv.description.unwrap_or("Unnamed test case".to_owned()),
tv.description
.unwrap_or_else(|| "Unnamed test case".to_owned()),
tv.result_selector,
result
);
Expand Down
Loading

0 comments on commit 1198d2f

Please sign in to comment.