Skip to content

Commit

Permalink
Merge pull request #5 from topos-protocol/ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored Jan 22, 2024
2 parents 7fc3c3f + 5a4c754 commit 95ea070
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 21 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/nibbles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/partial_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ where
V: Into<ValOrHash>,
{
let mut root = N::new(Node::Empty);
root.extend(nodes.into_iter());
root.extend(nodes);

root
}
15 changes: 6 additions & 9 deletions src/trie_hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/trie_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ impl<N: PartialTrie> PartialTrieIter<N> {
}
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);
Expand Down Expand Up @@ -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()));
}

Expand Down
2 changes: 1 addition & 1 deletion src/trie_subsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand Down

0 comments on commit 95ea070

Please sign in to comment.