From ded50a7c25e6c004f2f3381450f5cca57656f363 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Fri, 8 Oct 2021 10:14:16 +0300 Subject: [PATCH 1/2] feat: add a GitHub action to run tests on PRs --- .github/workflows/test.yml | 21 +++++++++++++++++++++ src/merkle_proof.rs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..43569a7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,21 @@ +name: Build and test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust Toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + - name: Build and test + run: cargo test diff --git a/src/merkle_proof.rs b/src/merkle_proof.rs index d90648e..6b5083f 100644 --- a/src/merkle_proof.rs +++ b/src/merkle_proof.rs @@ -87,7 +87,7 @@ impl MerkleProof { let proof_indices_by_layers = utils::indices::proof_indices_by_layers(leaf_indices, total_leaves_count); // The next lines copy hashes from proof hashes and group them by layer index - let mut proof_layers: Vec> = Vec::with_capacity(tree_depth); + let mut proof_layers: Vec> = Vec::with_capacity(tree_depth + 1); let mut proof_copy = self.proof_hashes.clone(); for proof_indices in proof_indices_by_layers { let proof_hashes = proof_copy.splice(0..proof_indices.len(), []); From 708d9e1a5094b215957c097489663737d032871e Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Fri, 8 Oct 2021 10:27:07 +0300 Subject: [PATCH 2/2] add publish on tags job --- .github/workflows/publish.yml | 24 ++++++++++++++++++++++++ .github/workflows/test.yml | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..fef2dab --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,24 @@ +name: Publish + +on: + push: + tags: + - v* + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + - name: Run tests + run: cargo test + - shell: bash + env: + CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }} + run: cargo login "$CARGO_TOKEN" && cargo publish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43569a7..d0ed4f0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Install Rust Toolchain + - name: Setup Rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - - name: Build and test + - name: Run tests run: cargo test