From b8c8bc5b87c724586b2c3bf490516fa0a6ff039e Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 28 May 2025 21:48:21 -0400 Subject: [PATCH] feat(cli): add basic tests and CI workflow --- .github/workflows/ci.yml | 18 ++++++++++++++++++ README.md | 7 ++++++- src/main.rs | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..db0a1d1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Cargo test + run: cargo test --locked --all diff --git a/README.md b/README.md index 75a4690..39ca955 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,12 @@ cargo build --release sudo install -m755 target/release/private_proof_of_reserve_cli /usr/local/bin/por ``` ---- +## Running tests + +```bash +cargo test +``` + \## Running a local Bitcoin node diff --git a/src/main.rs b/src/main.rs index dd8ce51..c96c8df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![forbid(unsafe_code)] //! Prototype CLI for a lower-bound Bitcoin proof-of-reserve. //! SECURITY: demo code only. @@ -158,3 +159,27 @@ fn verify_proof(pf: &Proof, rpc_url: &str, rpc_user: &str, rpc_pass: &str) -> Re let _ = RangeProof::from_bytes(&base64::decode(&pf.range_proof)?)?; Ok(()) } + +// ── tests ─────────────────────────────────────────────────── + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn merkle_root_single_leaf() { + let leaf = [42u8; 32]; + assert_eq!(merkle_root(vec![leaf]), leaf); + } + + #[test] + fn merkle_root_two_leaves() { + let a = [1u8; 32]; + let b = [2u8; 32]; + let mut h = Sha256::new(); + h.update(a); + h.update(b); + let expected: [u8; 32] = h.finalize().into(); + assert_eq!(merkle_root(vec![a, b]), expected); + } +}