Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI #12

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Tests

on:
pull_request:

jobs:
check_formatting:
name: Check Formatting
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3

- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-${{ runner.os }}-formatting-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-formatting
cargo-${{ runner.os }}-

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
profile: minimal

- name: Check formatting
run: |
cargo fmt -- --check

- name: Check docs
run: cargo doc

wasm:
name: Build WASM binary
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-10-24
target: wasm32-unknown-unknown
override: true
profile: minimal

- uses: jetli/[email protected]
with:
version: 'v0.12.1'

- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-${{ runner.os }}-wasn-tests-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-wasn-tests-
cargo-${{ runner.os }}-

- name: Build wasm package
env:
RUSTUP_TOOLCHAIN: nightly-2023-10-24
run: wasm-pack build ./kormir-wasm --release --target web

wasm_checks:
name: Rust Wasm Checks
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-10-24
components: clippy
target: wasm32-unknown-unknown
override: true
profile: minimal

- name: Setup trunk
uses: jetli/[email protected]
with:
version: 'latest'

- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-${{ runner.os }}-rust-wasm-checks-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-rust-wasm-checks-
cargo-${{ runner.os }}-

- name: Check clippy kormir-wasm
run: cargo clippy --all-features --tests --package kormir-wasm -- -D warnings

core_tests:
name: Core Tests on Linux
timeout-minutes: 60
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: clippy

- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-${{ runner.os }}-core-tests-linux-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-core-tests-linux-
cargo-${{ runner.os }}-

- name: Run cargo clippy
run: cargo clippy --all-features --tests -- -D warnings

- name: Run cargo test
run: cargo test

- name: Run cargo build
run: cargo build --all-features
10 changes: 5 additions & 5 deletions kormir-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::models::oracle_metadata::OracleMetadata;
use crate::models::{PostgresStorage, MIGRATIONS};
use crate::routes::*;
use axum::http::{StatusCode, Uri};
use axum::routing::{get, post};
use axum::{Extension, Router};
Expand All @@ -6,11 +9,8 @@ use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
use diesel_migrations::MigrationHarness;
use kormir::Oracle;
use nostr_sdk::Client;
use nostr::Keys;
use crate::models::oracle_metadata::OracleMetadata;
use crate::models::{PostgresStorage, MIGRATIONS};
use crate::routes::*;
use nostr_sdk::Client;

mod models;
mod routes;
Expand Down Expand Up @@ -83,7 +83,7 @@ async fn main() -> anyhow::Result<()> {
.map(|s| s.to_string())
.collect::<Vec<_>>();

let client = Client::new(&oracle.nostr_keys());
let client = Client::new(oracle.nostr_keys());
client.add_relays(relays).await?;
client.connect().await;

Expand Down
5 changes: 3 additions & 2 deletions kormir-server/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use diesel::r2d2::{ConnectionManager, Pool};
use diesel_migrations::{embed_migrations, EmbeddedMigrations};
use dlc_messages::oracle_msgs::{EventDescriptor, OracleAnnouncement};
use kormir::error::Error;
use kormir::storage::{OracleEventData, Storage};
use kormir::lightning::util::ser::Writeable;
use kormir::storage::{OracleEventData, Storage};
use nostr::EventId;
use std::collections::HashMap;
use std::sync::atomic::{AtomicU32, Ordering};
Expand Down Expand Up @@ -65,7 +65,8 @@ impl PostgresStorage {
.flat_map(|nonce| nonce.outcome_and_sig())
.collect();

let announcement_event_id = event.announcement_event_id().map(|ann| ann.to_string());
let announcement_event_id =
event.announcement_event_id().map(|ann| ann.to_string());
let attestation_event_id = event.attestation_event_id().map(|att| att.to_string());

let data = OracleEventData {
Expand Down
6 changes: 1 addition & 5 deletions kormir-server/src/models/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,4 @@ diesel::table! {

diesel::joinable!(event_nonces -> events (event_id));

diesel::allow_tables_to_appear_in_same_query!(
event_nonces,
events,
oracle_metadata,
);
diesel::allow_tables_to_appear_in_same_query!(event_nonces, events, oracle_metadata,);
2 changes: 1 addition & 1 deletion kormir-server/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub fn get_oracle_attestation_impl(
let (outcomes, signatures): (Vec<String>, Vec<Signature>) = event
.signatures
.iter()
.map(|(outcome, signature)| (outcome.clone(), signature.clone()))
.map(|(outcome, signature)| (outcome.clone(), signature))
.unzip();

Ok(OracleAttestation {
Expand Down
6 changes: 2 additions & 4 deletions kormir-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Kormir {

let oracle = Oracle::from_signing_key(storage.clone(), nsec)?;

let client = Client::new(&oracle.nostr_keys());
let client = Client::new(oracle.nostr_keys());
client.add_relays(relays.iter().map(|r| r.as_str())).await?;
client.connect().await;

Expand All @@ -71,9 +71,7 @@ impl Kormir {
storage
.save_to_indexed_db(
NSEC_KEY,
hex::encode(nsec.secret_key()
.expect("just imported")
.secret_bytes()),
hex::encode(nsec.secret_key().expect("just imported").secret_bytes()),
)
.await?;

Expand Down
6 changes: 5 additions & 1 deletion kormir-wasm/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ impl From<OracleAttestation> for Attestation {
fn from(value: OracleAttestation) -> Self {
Self {
oracle_public_key: hex::encode(value.oracle_public_key.serialize()),
signatures: value.signatures.iter().map(|x| hex::encode(x.encode())).collect(),
signatures: value
.signatures
.iter()
.map(|x| hex::encode(x.encode()))
.collect(),
outcomes: value.outcomes,
}
}
Expand Down
14 changes: 5 additions & 9 deletions kormir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub mod storage;

use crate::error::Error;
use crate::storage::Storage;
use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv};
use bitcoin::hashes::{sha256, Hash};
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::{All, Message, Secp256k1, SecretKey};
use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv};
use bitcoin::Network;
use bitcoin::key::XOnlyPublicKey;
use secp256k1_zkp::Keypair;
use std::collections::HashMap;
use std::str::FromStr;
Expand Down Expand Up @@ -59,8 +59,8 @@ impl<S: Storage> Oracle<S> {
let secp = Secp256k1::new();

let xpriv_bytes = sha256::Hash::hash(&signing_key.secret_bytes()).to_byte_array();
let nonce_xpriv = Xpriv::new_master(Network::Bitcoin, &xpriv_bytes)
.map_err(|_| Error::Internal)?;
let nonce_xpriv =
Xpriv::new_master(Network::Bitcoin, &xpriv_bytes).map_err(|_| Error::Internal)?;

Ok(Self {
storage,
Expand Down Expand Up @@ -198,10 +198,7 @@ impl<S: Storage> Oracle<S> {
}
}

pub fn derive_signing_key(
secp: &Secp256k1<All>,
xpriv: Xpriv,
) -> Result<SecretKey, Error> {
pub fn derive_signing_key(secp: &Secp256k1<All>, xpriv: Xpriv) -> Result<SecretKey, Error> {
let signing_key = xpriv
.derive_priv(
secp,
Expand All @@ -217,7 +214,6 @@ mod test {
use super::*;
use crate::storage::MemoryStorage;
use bitcoin::secp256k1::rand::{thread_rng, Rng};
use bitcoin::Network;

fn create_oracle() -> Oracle<MemoryStorage> {
let mut seed: [u8; 64] = [0; 64];
Expand Down
2 changes: 0 additions & 2 deletions kormir/src/nostr_events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "nostr")]

use dlc_messages::oracle_msgs::{OracleAnnouncement, OracleAttestation};
use lightning::util::ser::Writeable;
use nostr::event::builder::Error;
Expand Down
Loading