Skip to content

Commit

Permalink
Merge pull request #2 from pool2win/bring-back-tests
Browse files Browse the repository at this point in the history
Bring back tests
  • Loading branch information
pool2win authored Jun 12, 2024
2 parents 5ebb975 + 088b721 commit 4163794
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 261 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
on: [push, pull_request]

name: Rust CI

jobs:
check:
name: Check
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path Cargo.toml

test:
name: Test Suite
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path Cargo.toml

fmt:
name: Rustfmt
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path Cargo.toml --all -- --check

coverage:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
env:
RUST_LOG: debug
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: lcov.info
fail_ci_if_error: true
verbose: true


# clippy:
# name: Clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
# - run: rustup component add clippy
# - uses: actions-rs/cargo@v1
# with:
# command: clippy
# args: -- -D warnings
69 changes: 0 additions & 69 deletions src/node/connection_reader.rs

This file was deleted.

53 changes: 0 additions & 53 deletions src/node/connection_writer.rs

This file was deleted.

37 changes: 35 additions & 2 deletions src/node/noise_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ use tokio_util::{
//
// We use 25519 instead of LN's choice of secp256k1 as
// rust Noise implementation doesn't yet support secp256k1
// noise_params: "Noise_XX_25519_ChaChaPoly_SHA256".parse().unwrap(),

// static PATTERN: &str = "Noise_NN_25519_ChaChaPoly_BLAKE2s";
static PATTERN: &str = "Noise_XX_25519_ChaChaPoly_SHA256";
const NOISE_MAX_MSG_LENGTH: usize = 65535;

Expand Down Expand Up @@ -197,3 +195,38 @@ impl NoiseHandler {
(reader, writer)
}
}

#[cfg(test)]
mod tests {

use super::NoiseHandler;
use tokio_util::bytes::Bytes;

static TEST_KEY: &str = "
-----BEGIN PRIVATE KEY-----
MFECAQEwBQYDK2VwBCIEIJ7pILqR7yBPsVuysfGyofjOEm19skmtqcJYWiVwjKH1
gSEA68zeZuy7PMMQC9ECPmWqDl5AOFj5bi243F823ZVWtXY=
-----END PRIVATE KEY-----
";

#[test]
fn it_builds_noise_handler() {
let handler = NoiseHandler::new(true, TEST_KEY.to_string());
assert!(handler.initiator);
assert!(handler.handshake_state.is_some());
assert!(handler.transport_state.is_none());
}

#[test]
fn it_builds_initiator_noise_handler() {
let mut handler = NoiseHandler::new(true, TEST_KEY.to_string());
let noise_message: Bytes = handler.build_handshake_message(b"test bytes");
let len = noise_message.len();
assert_eq!(&noise_message[(len - 10)..], b"test bytes");

let mut responder = NoiseHandler::new(false, TEST_KEY.to_string());
let read_message: Bytes = responder.read_handshake_message(noise_message);
let len = read_message.len();
assert_eq!(&read_message[(len - 10)..], b"test bytes");
}
}
Loading

0 comments on commit 4163794

Please sign in to comment.