diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b4a9327 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: Continuous Integration + +on: + push: + branches: [main] + pull_request: + branches: + - "**" + workflow_dispatch: + branches: + - "**" + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test Suite + runs-on: ubuntu-latest + timeout-minutes: 30 + if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')" + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Set up rust cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Run cargo test + run: cargo test --workspace + env: + RUSTFLAGS: -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 + + lints: + name: Formatting and Clippy + runs-on: ubuntu-latest + timeout-minutes: 10 + if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')" + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install nightly toolchain + uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt, clippy + + - name: Set up rust cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Run cargo fmt + run: cargo fmt --all --check + + - name: Run cargo clippy + run: cargo clippy --all-features --all-targets -- -D warnings -A incomplete-features diff --git a/src/lib.rs b/src/lib.rs index 3b6bdf9..b7fd861 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,6 @@ //! hash of the node it replaces. #![allow(incomplete_features)] -#![feature(return_position_impl_trait_in_trait)] pub mod nibbles; pub mod partial_trie; diff --git a/src/nibbles.rs b/src/nibbles.rs index 38f6237..b463feb 100644 --- a/src/nibbles.rs +++ b/src/nibbles.rs @@ -607,13 +607,11 @@ impl Nibbles { let hex_string_raw = hex_encode_f(&byte_buf[(64 - count_bytes)..64]); let hex_char_iter_raw = hex_string_raw.chars(); - let hex_char_iter = match is_even(self.count) { - false => hex_char_iter_raw.skip(1), - true => hex_char_iter_raw.skip(0), - }; - let mut hex_string = String::from("0x"); - hex_string.extend(hex_char_iter); + match is_even(self.count) { + false => hex_string.extend(hex_char_iter_raw.skip(1)), + true => hex_string.extend(hex_char_iter_raw), + }; hex_string } diff --git a/src/partial_trie.rs b/src/partial_trie.rs index a39a9ef..dca6df6 100644 --- a/src/partial_trie.rs +++ b/src/partial_trie.rs @@ -423,7 +423,7 @@ where V: Into, { let mut root = N::new(Node::Empty); - root.extend(nodes.into_iter()); + root.extend(nodes); root } diff --git a/src/trie_hashing.rs b/src/trie_hashing.rs index 0f00a0b..55acab1 100644 --- a/src/trie_hashing.rs +++ b/src/trie_hashing.rs @@ -383,15 +383,12 @@ mod tests { #[test] fn replacing_branch_of_leaves_with_hash_nodes_produced_same_hash() { - let mut trie = HashedPartialTrie::from_iter( - [ - large_entry(0x1), - large_entry(0x2), - large_entry(0x3), - large_entry(0x4), - ] - .into_iter(), - ); + let mut trie = HashedPartialTrie::from_iter([ + large_entry(0x1), + large_entry(0x2), + large_entry(0x3), + large_entry(0x4), + ]); let orig_hash = trie.hash(); diff --git a/src/trie_ops.rs b/src/trie_ops.rs index 4b7bc6a..93f65eb 100644 --- a/src/trie_ops.rs +++ b/src/trie_ops.rs @@ -180,8 +180,8 @@ impl PartialTrieIter { } Node::Extension { nibbles, child } => { if TrieNodeType::from(child) != TrieNodeType::Hash { - self.trie_stack - .push(IterStackEntry::Extension(nibbles.count)); + self.trie_stack + .push(IterStackEntry::Extension(nibbles.count)); } curr_key = curr_key.merge_nibbles(nibbles); @@ -857,7 +857,7 @@ mod tests { let mut entries = [entry(0x1234), entry(0x1234)]; entries[1].1 = vec![100]; - let trie = StandardTrie::from_iter(entries.into_iter()); + let trie = StandardTrie::from_iter(entries); assert_eq!(trie.get(0x1234), Some([100].as_slice())); } diff --git a/src/trie_subsets.rs b/src/trie_subsets.rs index d317e6a..be9aae4 100644 --- a/src/trie_subsets.rs +++ b/src/trie_subsets.rs @@ -464,7 +464,7 @@ mod tests { fn multi_node_trie_returns_proper_subset() { let trie = create_trie_with_large_entry_nodes(&[0x1234, 0x56, 0x12345_u64]); - let trie_subset = create_trie_subset(&trie, vec![0x1234, 0x56].into_iter()).unwrap(); + let trie_subset = create_trie_subset(&trie, vec![0x1234, 0x56]).unwrap(); let leaf_keys = get_all_nibbles_of_leaf_nodes_in_trie(&trie_subset); assert!(leaf_keys.contains(&(Nibbles::from(0x1234))));