From 82313ed5dd00be0e17bea0ee0815d59c66e27c98 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 10 Nov 2022 11:35:48 +0100 Subject: [PATCH] chore: add git actions (#111) * add go tests * add js tests * fix how license is shown * add rust flow * fix syntax * cd into rust * test * test++ * test++ * test++ * migrate * add rust linting * fix concurrency * formatting * lint pr * rename main to master * fix test * fix clippy issues Co-authored-by: Marko Baricevic --- .circleci/config.yml | 139 ---------------------------------- .github/workflows/lint-pr.yml | 22 ++++++ .github/workflows/lint.yml | 38 ++++++++++ .github/workflows/test.yml | 69 +++++++++++++++++ LICENSE | 3 - rust/src/ics23.rs | 32 ++++---- 6 files changed, 145 insertions(+), 158 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/lint-pr.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index c5082dfd..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,139 +0,0 @@ -# This is a bit complex with multiple jobs. -# https://circleci.com/docs/2.0/local-cli/ will let you test this locally -version: 2 -workflows: - version: 2 - test: - jobs: - - typescript - - golang - - rust - - lint-rust - -jobs: - typescript: - docker: - - image: circleci/node:12 - working_directory: ~/proofs/js - steps: - # we checkout here, all other code runs in js subdir - - checkout: - path: ~/proofs - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package.json" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - run: yarn install - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package.json" }} - - run: yarn test - golang: - docker: - # specify the version - - image: circleci/golang:1.14 - environment: - GO111MODULE=on - working_directory: ~/proofs/go - steps: - # we checkout here, all other code runs in go subdir - - checkout: - path: ~/proofs - - restore_cache: - keys: - - go-mod-v1-{{ checksum "go.sum" }} - - run: make test - - save_cache: - key: go-mod-v1-{{ checksum "go.sum" }} - paths: - - "/go/pkg/mod" - rust: - docker: - - image: rust:1.56.1 - working_directory: ~/proofs/rust - steps: - - checkout: - path: ~/proofs - - run: - name: Version information - command: rustc --version; cargo --version; rustup --version - - restore_cache: - keys: - - v4-cargo-cache-rust:1.56.1-{{ arch }}-{{ checksum "Cargo.toml" }} - - run: - name: install protobuf dependencies - command: | - apt update - apt install -y libprotobuf-dev protobuf-compiler - - run: - name: Check all targets in std - command: cargo check --all - - run: - name: Check all target in no_std - command: cargo check --no-default-features --all - - run: - name: Build all targets in std - command: cargo build --all --all-targets - - run: - name: Build all targets in no_std - command: cargo build --all --no-default-features - - run: - name: Run all tests with no-std - command: cargo test --all --no-default-features - - run: - name: Run all tests with std - command: cargo test --all - - save_cache: - paths: - - /usr/local/cargo/registry - - target/debug/.fingerprint - - target/debug/build - - target/debug/deps - key: v4-cargo-cache-rust:1.56.1-{{ arch }}-{{ checksum "Cargo.toml" }} - - run: - name: Run all tests - command: cargo test --all - - run: - name: Check no_std compatibility - command: cd no-std-check/; make setup; make all - - lint-rust: - docker: - - image: rust:1.56.1 - working_directory: ~/proofs/rust - steps: - - checkout: - path: ~/proofs - - run: - name: Version information - command: rustc --version; cargo --version; rustup --version; rustup target list --installed - - restore_cache: - keys: - - cargocache-v2-lint-rust:1.56.1-{{ checksum "Cargo.toml" }} - - run: - name: Add rustfmt component - command: rustup component add rustfmt - - run: - name: Add clippy component - command: rustup component add clippy - - run: - name: Check formatting of workspace - command: cargo fmt -- --check - - run: - name: Clippy linting on workspace (host-functions + std) - command: cargo clippy --tests -- -D warnings - - run: - name: Clippy linting on workspace (no-std) - command: cargo clippy --tests --no-default-features -- -D warnings - - run: - name: Clippy linting on workspace (host functions only) - command: cargo clippy --tests --no-default-features --features host-functions -- -D warnings - - save_cache: - paths: - - /usr/local/cargo/registry - - target/debug/.fingerprint - - target/debug/build - - target/debug/deps - key: cargocache-v2-lint-rust:1.56.1-{{ checksum "Cargo.toml" }} diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml new file mode 100644 index 00000000..d5b4d46b --- /dev/null +++ b/.github/workflows/lint-pr.yml @@ -0,0 +1,22 @@ +name: "Lint PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +permissions: + contents: read + +jobs: + main: + permissions: + pull-requests: read # for amannn/action-semantic-pull-request to analyze PRs + statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..dadfbc51 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,38 @@ +name: Lint +on: + pull_request: + push: + branches: + - master + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }}-linting + cancel-in-progress: true + +jobs: + rust: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Check formatting of workspace + working-directory: ./rust + run: cargo fmt -- --check + + - name: Clippy linting on workspace (host-functions + std) + working-directory: ./rust + run: cargo clippy --tests -- -D warnings + + - name: Clippy linting on workspace (no-std) + working-directory: ./rust + run: cargo clippy --tests --no-default-features -- -D warnings + + - name: Clippy linting on workspace (host functions only) + working-directory: ./rust + run: cargo clippy --tests --no-default-features --features host-functions -- -D warnings + \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..ace5bd5a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,69 @@ +name: Tests +on: + pull_request: + push: + branches: + - master + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }}-tests + cancel-in-progress: true + +jobs: + go: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - name: test + working-directory: ./go + run: make test + + ts: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: test + working-directory: ./js + run: yarn && yarn test + + rust: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Check all target in std + working-directory: ./rust + run: cargo check --all + + - name: Check all target in no_std + working-directory: ./rust + run: cargo check --no-default-features --all + + - name: Build all targets in std + working-directory: ./rust + run: cargo build --all --all-targets + + - name: Build all targets in no_std + working-directory: ./rust + run: cargo build --all --no-default-features + + - name: Run all tests with no-std + working-directory: ./rust + run: cargo test --all --no-default-features + + - name: Run all tests with std + working-directory: ./rust + run: cargo test --all + + - name: check no_std compatibility + run: cd rust/no-std-check/; make setup; make all + + diff --git a/LICENSE b/LICENSE index 625252a8..290e57b9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,3 @@ -Confio/ICS23 -License: Apache2.0 - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ diff --git a/rust/src/ics23.rs b/rust/src/ics23.rs index d6191201..45b7b895 100644 --- a/rust/src/ics23.rs +++ b/rust/src/ics23.rs @@ -18,7 +18,7 @@ /// With LengthOp this is tricker but not impossible. Which is why the "leafPrefixEqual" field /// in the ProofSpec is valuable to prevent this mutability. And why all trees should /// length-prefix the data before hashing it. -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct ExistenceProof { #[prost(bytes = "vec", tag = "1")] pub key: ::prost::alloc::vec::Vec, @@ -33,7 +33,7 @@ pub struct ExistenceProof { /// NonExistenceProof takes a proof of two neighbors, one left of the desired key, /// one right of the desired key. If both proofs are valid AND they are neighbors, /// then there is no valid proof for the given key. -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct NonExistenceProof { /// TODO: remove this as unnecessary??? we prove a range #[prost(bytes = "vec", tag = "1")] @@ -45,14 +45,14 @@ pub struct NonExistenceProof { } /// /// CommitmentProof is either an ExistenceProof or a NonExistenceProof, or a Batch of such messages -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct CommitmentProof { #[prost(oneof = "commitment_proof::Proof", tags = "1, 2, 3, 4")] pub proof: ::core::option::Option, } /// Nested message and enum types in `CommitmentProof`. pub mod commitment_proof { - #[derive(Clone, PartialEq, ::prost::Oneof)] + #[derive(Clone, PartialEq, Eq, ::prost::Oneof)] pub enum Proof { #[prost(message, tag = "1")] Exist(super::ExistenceProof), @@ -79,7 +79,7 @@ pub mod commitment_proof { /// /// Then combine the bytes, and hash it /// output = hash(prefix || length(hkey) || hkey || length(hvalue) || hvalue) -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct LeafOp { #[prost(enumeration = "HashOp", tag = "1")] pub hash: i32, @@ -110,7 +110,7 @@ pub struct LeafOp { /// Any special data, like prepending child with the length, or prepending the entire operation with /// some value to differentiate from leaf nodes, should be included in prefix and suffix. /// If either of prefix or suffix is empty, we just treat it as an empty string -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct InnerOp { #[prost(enumeration = "HashOp", tag = "1")] pub hash: i32, @@ -130,7 +130,7 @@ pub struct InnerOp { /// generate a given hash (by interpretting the preimage differently). /// We need this for proper security, requires client knows a priori what /// tree format server uses. But not in code, rather a configuration object. -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct ProofSpec { /// any field in the ExistenceProof must be the same as in this spec. /// except Prefix, which is just the first bytes of prefix (spec can be longer) @@ -154,7 +154,7 @@ pub struct ProofSpec { /// isLeftMost(spec: InnerSpec, op: InnerOp) /// isRightMost(spec: InnerSpec, op: InnerOp) /// isLeftNeighbor(spec: InnerSpec, left: InnerOp, right: InnerOp) -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct InnerSpec { /// Child order is the ordering of the children node, must count from 0 /// iavl tree is [0, 1] (left then right) @@ -176,20 +176,20 @@ pub struct InnerSpec { } /// /// BatchProof is a group of multiple proof types than can be compressed -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct BatchProof { #[prost(message, repeated, tag = "1")] pub entries: ::prost::alloc::vec::Vec, } /// Use BatchEntry not CommitmentProof, to avoid recursion -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct BatchEntry { #[prost(oneof = "batch_entry::Proof", tags = "1, 2")] pub proof: ::core::option::Option, } /// Nested message and enum types in `BatchEntry`. pub mod batch_entry { - #[derive(Clone, PartialEq, ::prost::Oneof)] + #[derive(Clone, PartialEq, Eq, ::prost::Oneof)] pub enum Proof { #[prost(message, tag = "1")] Exist(super::ExistenceProof), @@ -199,7 +199,7 @@ pub mod batch_entry { } // ***** all items here are compressed forms ****** -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct CompressedBatchProof { #[prost(message, repeated, tag = "1")] pub entries: ::prost::alloc::vec::Vec, @@ -207,14 +207,14 @@ pub struct CompressedBatchProof { pub lookup_inners: ::prost::alloc::vec::Vec, } /// Use BatchEntry not CommitmentProof, to avoid recursion -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct CompressedBatchEntry { #[prost(oneof = "compressed_batch_entry::Proof", tags = "1, 2")] pub proof: ::core::option::Option, } /// Nested message and enum types in `CompressedBatchEntry`. pub mod compressed_batch_entry { - #[derive(Clone, PartialEq, ::prost::Oneof)] + #[derive(Clone, PartialEq, Eq, ::prost::Oneof)] pub enum Proof { #[prost(message, tag = "1")] Exist(super::CompressedExistenceProof), @@ -222,7 +222,7 @@ pub mod compressed_batch_entry { Nonexist(super::CompressedNonExistenceProof), } } -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct CompressedExistenceProof { #[prost(bytes = "vec", tag = "1")] pub key: ::prost::alloc::vec::Vec, @@ -234,7 +234,7 @@ pub struct CompressedExistenceProof { #[prost(int32, repeated, tag = "4")] pub path: ::prost::alloc::vec::Vec, } -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, PartialEq, Eq, ::prost::Message)] pub struct CompressedNonExistenceProof { /// TODO: remove this as unnecessary??? we prove a range #[prost(bytes = "vec", tag = "1")]