Skip to content

Commit 8d4963d

Browse files
committed
Fix clippy warnings in test code
1 parent fdb143c commit 8d4963d

6 files changed

Lines changed: 57 additions & 73 deletions

File tree

.github/workflows/linter.yml

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ env:
1515
jobs:
1616
examples-rustfmt:
1717
name: Examples format
18-
# Don't run on draft pull requests
1918
if: ${{ !github.event.pull_request.draft }}
2019
runs-on: ubuntu-latest
2120
steps:
@@ -29,21 +28,18 @@ jobs:
2928
3029
rustfmt:
3130
name: Format
32-
# Don't run on draft pull requests
3331
if: ${{ !github.event.pull_request.draft }}
3432
runs-on: ubuntu-latest
3533
steps:
3634
- name: Checkout
3735
uses: actions/checkout@v3
3836
- name: Format
39-
working-directory: examples
4037
run: |
4138
rustup component add rustfmt
4239
cargo fmt -- --color=always --check
4340
4441
rustdoc:
4542
name: Lint docs
46-
# Don't run on draft pull requests
4743
if: ${{ !github.event.pull_request.draft }}
4844
runs-on: ubuntu-latest
4945
steps:
@@ -56,6 +52,31 @@ jobs:
5652
rustup component add rust-docs
5753
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
5854
55+
clippy:
56+
name: Clippy
57+
if: ${{ !github.event.pull_request.draft }}
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v3
62+
with:
63+
submodules: recursive
64+
- name: Clippy
65+
run: |
66+
rustup component add clippy
67+
cargo clippy --color=always --all-targets --all-features -- -D warnings
68+
69+
test:
70+
name: Test
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@v3
75+
with:
76+
submodules: recursive
77+
- name: Test
78+
run: cargo test -- --skip io_tests # Skip the I/O tests in the testing library.
79+
5980
# Run unit-tests for concordium-std compiled to wasm using cargo concordium test.
6081
std-internal-wasm-test:
6182
name: concordium-std internal wasm tests
@@ -66,13 +87,6 @@ jobs:
6687
uses: actions/checkout@v3
6788
with:
6889
submodules: recursive
69-
70-
- name: Install toolchain
71-
uses: actions-rust-lang/setup-rust-toolchain@v1
72-
with:
73-
toolchain: ${{ env.RUST_VERSION }}
74-
target: wasm32-unknown-unknown
75-
7690
- name: Run internal wasm unit test
7791
working-directory: concordium-std
7892
run: |
@@ -81,6 +95,14 @@ jobs:
8195
sudo mv /tmp/cargo-concordium /usr/bin/cargo-concordium
8296
cargo concordium test --only-unit-tests -- --features internal-wasm-test
8397
98+
99+
100+
101+
102+
103+
104+
105+
84106
clippy-cis2:
85107
name: Clippy
86108
runs-on: ubuntu-latest
@@ -155,40 +177,7 @@ jobs:
155177
command: clippy
156178
args: --manifest-path ${{ matrix.lib-crates }} --target=${{ matrix.target }} --features=${{ matrix.features }} -- -D warnings
157179

158-
clippy-crypto-primitives:
159-
name: Clippy concordium-std with crypto-primitives
160-
runs-on: ubuntu-latest
161-
needs: rustfmt
162-
strategy:
163-
matrix:
164-
target:
165-
- wasm32-unknown-unknown
166-
- x86_64-unknown-linux-gnu
167-
168-
lib-crates:
169-
- concordium-std/Cargo.toml
170-
171-
features:
172-
- crypto-primitives
173-
174-
steps:
175-
- name: Checkout sources
176-
uses: actions/checkout@v2
177-
with:
178-
submodules: recursive
179-
180-
- name: Install toolchain with clippy available
181-
uses: actions-rust-lang/setup-rust-toolchain@v1
182-
with:
183-
toolchain: ${{ env.RUST_VERSION }}
184-
target: ${{ matrix.target }}
185-
components: clippy
186180

187-
- name: Run cargo clippy
188-
uses: actions-rs/cargo@v1
189-
with:
190-
command: clippy
191-
args: --manifest-path ${{ matrix.lib-crates }} --target=${{ matrix.target }} --features=${{ matrix.features }} -- -D warnings
192181

193182
clippy-wasm32-only:
194183
name: Clippy Wasm32

concordium-cis2/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ impl TryFrom<String> for TokenIdUnit {
693693
type Error = ParseError;
694694

695695
fn try_from(s: String) -> Result<Self, Self::Error> {
696-
if s == "" {
696+
if s.is_empty() {
697697
Ok(Self())
698698
} else {
699699
Err(ParseError {})

concordium-std/src/state_btree.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ mod wasm_test_btree {
13831383
}
13841384

13851385
for i in 1..root.keys.len() {
1386-
if &root.keys[i - 1] >= &root.keys[i] {
1386+
if root.keys[i - 1] >= root.keys[i] {
13871387
return Err(InvariantViolation::NodeKeysOutOfOrder);
13881388
}
13891389
}
@@ -1440,7 +1440,7 @@ mod wasm_test_btree {
14401440
K: Serialize + fmt::Debug + Ord,
14411441
{
14421442
let Some(root_node_id) = self.root else {
1443-
return format!("no root");
1443+
return "no root".to_string();
14441444
};
14451445
let mut string = String::new();
14461446
let root: Node<M, K> = self.get_node(root_node_id);
@@ -1475,7 +1475,7 @@ mod wasm_test_btree {
14751475
K: Ord,
14761476
{
14771477
for i in 1..self.keys.len() {
1478-
if &self.keys[i - 1] >= &self.keys[i] {
1478+
if self.keys[i - 1] >= self.keys[i] {
14791479
return Err(InvariantViolation::NodeKeysOutOfOrder);
14801480
}
14811481
}
@@ -1667,7 +1667,7 @@ mod wasm_test_btree {
16671667
for n in 0..500 {
16681668
claim!(tree.insert(n));
16691669
}
1670-
for n in (500..1000).into_iter().rev() {
1670+
for n in (500..1000).rev() {
16711671
claim!(tree.insert(n));
16721672
}
16731673

@@ -1729,7 +1729,7 @@ mod wasm_test_btree {
17291729
fn test_btree_remove_only_key_higher_leaf_in_three_node() {
17301730
let mut state_builder = StateBuilder::open(StateApi::open());
17311731
let mut tree = state_builder.new_btree_set_degree::<2, _>();
1732-
for n in (0..4).into_iter().rev() {
1732+
for n in (0..4).rev() {
17331733
tree.insert(n);
17341734
}
17351735
tree.remove(&3);
@@ -1752,7 +1752,7 @@ mod wasm_test_btree {
17521752
fn test_btree_remove_from_higher_leaf_in_three_node_taking_from_sibling() {
17531753
let mut state_builder = StateBuilder::open(StateApi::open());
17541754
let mut tree = state_builder.new_btree_set_degree::<2, _>();
1755-
for n in (0..4).into_iter().rev() {
1755+
for n in (0..4).rev() {
17561756
tree.insert(n);
17571757
}
17581758
claim!(tree.contains(&3));
@@ -1830,7 +1830,7 @@ mod wasm_test_btree {
18301830
fn test_btree_remove_from_root_in_three_node_taking_key_from_lower_child() {
18311831
let mut state_builder = StateBuilder::open(StateApi::open());
18321832
let mut tree = state_builder.new_btree_set_degree::<2, _>();
1833-
for n in (0..4).into_iter().rev() {
1833+
for n in (0..4).rev() {
18341834
tree.insert(n);
18351835
}
18361836
claim!(tree.contains(&2));
@@ -1843,11 +1843,11 @@ mod wasm_test_btree {
18431843
fn test_btree_iter() {
18441844
let mut state_builder = StateBuilder::open(StateApi::open());
18451845
let mut tree = state_builder.new_btree_set_degree::<2, _>();
1846-
let keys: Vec<u32> = (0..15).into_iter().collect();
1846+
let keys: Vec<u32> = (0..15).collect();
18471847
for &k in &keys {
18481848
tree.insert(k);
18491849
}
1850-
let iter_keys: Vec<u32> = tree.iter().map(|k| k.clone()).collect();
1850+
let iter_keys: Vec<u32> = tree.iter().map(|k| *k).collect();
18511851
claim_eq!(keys, iter_keys);
18521852
}
18531853

@@ -2064,6 +2064,7 @@ mod wasm_test_btree {
20642064
}
20652065

20662066
/// The different mutating operations to generate for the btree.
2067+
#[allow(clippy::enum_variant_names)]
20672068
#[derive(Debug, Clone, Copy)]
20682069
enum Operation {
20692070
/// Insert a new key in the set.
@@ -2083,7 +2084,7 @@ mod wasm_test_btree {
20832084
tree: &mut StateBTreeSet<u32, M>,
20842085
mutations: &[(u32, Operation)],
20852086
) -> Result<(), String> {
2086-
for (k, op) in mutations.into_iter() {
2087+
for (k, op) in mutations.iter() {
20872088
if let Err(violation) = tree.check_invariants() {
20882089
return Err(format!("Invariant violated: {:?}", violation));
20892090
}
@@ -2115,14 +2116,13 @@ mod wasm_test_btree {
21152116

21162117
impl Arbitrary for Operation {
21172118
fn arbitrary(g: &mut Gen) -> Self {
2118-
g.choose(&[
2119+
*g.choose(&[
21192120
Self::InsertKeyNotPresent,
21202121
Self::InsertKeyPresent,
21212122
Self::RemoveKeyPresent,
21222123
Self::RemoveKeyNotPresent,
21232124
])
21242125
.unwrap()
2125-
.clone()
21262126
}
21272127
}
21282128

@@ -2141,9 +2141,8 @@ mod wasm_test_btree {
21412141
while mutations.len() < g.size() {
21422142
let op: Operation = Operation::arbitrary(g);
21432143
match op {
2144-
Operation::InsertKeyPresent if inserted_keys.len() > 0 => {
2145-
let indexes: Vec<usize> =
2146-
(0..inserted_keys.len()).into_iter().collect();
2144+
Operation::InsertKeyPresent if !inserted_keys.is_empty() => {
2145+
let indexes: Vec<usize> = (0..inserted_keys.len()).collect();
21472146
let k_index = g.choose(&indexes).unwrap();
21482147
let k = &inserted_keys[*k_index];
21492148
mutations.push((k.clone(), op));
@@ -2155,9 +2154,8 @@ mod wasm_test_btree {
21552154
mutations.push((k, op));
21562155
}
21572156
}
2158-
Operation::RemoveKeyPresent if inserted_keys.len() > 0 => {
2159-
let indexes: Vec<usize> =
2160-
(0..inserted_keys.len()).into_iter().collect();
2157+
Operation::RemoveKeyPresent if !inserted_keys.is_empty() => {
2158+
let indexes: Vec<usize> = (0..inserted_keys.len()).collect();
21612159
let k_index = g.choose(&indexes).unwrap();
21622160
let k = inserted_keys.remove(*k_index);
21632161
mutations.push((k, op));
@@ -2173,9 +2171,7 @@ mod wasm_test_btree {
21732171
}
21742172

21752173
Self {
2176-
expected_keys: crate::collections::BTreeSet::from_iter(
2177-
inserted_keys.into_iter(),
2178-
),
2174+
expected_keys: crate::collections::BTreeSet::from_iter(inserted_keys),
21792175
mutations,
21802176
}
21812177
}

concordium-std/src/test_env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ mod wasm_test {
227227
let event_size = unsafe { prims::get_event_size(0) };
228228

229229
claim_eq!(store_status, 1);
230-
claim_eq!(event_size, event_prim.len().try_into().unwrap_abort());
230+
claim_eq!(event_size, i32::try_from(event_prim.len()).unwrap_abort());
231231

232232
let mut buf = vec![0; event_prim.len()];
233233
let bytes_written = unsafe { prims::get_event(0, buf.as_mut_ptr()) };

concordium-std/src/traits.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
use crate::vec::Vec;
66
use crate::{
77
AccountSignatures, CallContractResult, CheckAccountSignatureResult, EntryRaw, ExchangeRates,
8-
HashKeccak256, HashSha2256, HashSha3256, Key, OccupiedEntryRaw,
9-
PublicKeyEcdsaSecp256k1, PublicKeyEd25519, QueryAccountBalanceResult,
10-
QueryAccountPublicKeysResult, QueryContractBalanceResult, ReadOnlyCallContractResult,
11-
SignatureEcdsaSecp256k1, SignatureEd25519, StateBuilder, TransferResult, UpgradeResult,
12-
VacantEntryRaw,
8+
HashKeccak256, HashSha2256, HashSha3256, Key, OccupiedEntryRaw, PublicKeyEcdsaSecp256k1,
9+
PublicKeyEd25519, QueryAccountBalanceResult, QueryAccountPublicKeysResult,
10+
QueryContractBalanceResult, ReadOnlyCallContractResult, SignatureEcdsaSecp256k1,
11+
SignatureEd25519, StateBuilder, TransferResult, UpgradeResult, VacantEntryRaw,
1312
types::{LogError, StateError},
1413
};
1514
use crate::{QueryContractModuleReferenceResult, QueryContractNameResult};

concordium-std/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
cell::UnsafeCell, marker::PhantomData, num::NonZeroU32, Cursor, HasStateApi, Serial, Vec,
2+
Cursor, HasStateApi, Serial, Vec, cell::UnsafeCell, marker::PhantomData, num::NonZeroU32,
33
};
44
use concordium_contracts_common::{
55
AccountBalance, Amount, ModuleReference, OwnedContractName, ParseError,

0 commit comments

Comments
 (0)