Skip to content

Commit

Permalink
Add GitHub CI workflow (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe authored Apr 29, 2024
1 parent cfeb552 commit 72efe63
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 43 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always
# Make sure CI fails on all warnings, including Clippy lints
RUSTFLAGS: "-Dwarnings"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Setup
run: just setup
- name: Build
run: just build
test:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ] # TODO add back windows-latest https://github.com/TBD54566975/tbdex-rs/issues/44
rust: [ stable, nightly ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Setup
run: just setup
- name: Test
run: just test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Setup
run: just setup
- name: Lint
run: just lint
6 changes: 5 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ build:
test:
cargo test

# Run linting, look for warnings in the output to correct
# Run linting, look for warnings and/or diffs in the output to correct
lint:
cargo clippy --workspace
cargo fmt -- --check

# Run formatting
fmt:
cargo fmt
2 changes: 1 addition & 1 deletion crates/protocol/src/message/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Close {
to,
kind: MessageKind::Close,
id: MessageKind::Close.typesafe_id()?,
exchange_id: exchange_id,
exchange_id,
created_at: Utc::now(),
};

Expand Down
10 changes: 5 additions & 5 deletions crates/protocol/src/message/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ impl Order {
to,
kind: MessageKind::Order,
id: MessageKind::Order.typesafe_id()?,
exchange_id: exchange_id,
exchange_id,
created_at: Utc::now(),
};

let data = OrderData ;
let data = OrderData;

Ok(Message {
metadata,
Expand Down Expand Up @@ -59,9 +59,9 @@ mod tests {
#[test]
fn can_parse_order_from_json() {
let order = Order::create(
"did:example:from_1234".to_string(),
"did:example:to_1234".to_string(),
MessageKind::Rfq.typesafe_id().unwrap(),
"did:example:from_1234".to_string(),
"did:example:to_1234".to_string(),
MessageKind::Rfq.typesafe_id().unwrap(),
)
.expect("Could not create Order");
let json: String = serde_json::to_string(&order).expect("failed to serialize Order");
Expand Down
49 changes: 24 additions & 25 deletions crates/protocol/src/message/order_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ impl OrderStatus {
to,
kind: MessageKind::OrderStatus,
id: MessageKind::OrderStatus.typesafe_id()?,
exchange_id: exchange_id,
exchange_id,
created_at: Utc::now(),
};

let data = OrderStatusData {
order_status,
};
let data = OrderStatusData { order_status };

Ok(Message {
metadata,
Expand All @@ -42,8 +40,8 @@ impl OrderStatus {
#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderStatusData {
/// Current status of Order that's being executed
order_status: String,
/// Current status of Order that's being executed
order_status: String,
}

#[cfg(test)]
Expand All @@ -52,29 +50,30 @@ mod tests {

#[test]
fn can_create() {
let order_status: Message<OrderStatusData> = OrderStatus::create(
"did:example:from_1234".to_string(),
"did:example:to_1234".to_string(),
MessageKind::Rfq.typesafe_id().unwrap(),
"COMPLETED".to_string()
)
.expect("failed to create OrderStatus");
let order_status: Message<OrderStatusData> = OrderStatus::create(
"did:example:from_1234".to_string(),
"did:example:to_1234".to_string(),
MessageKind::Rfq.typesafe_id().unwrap(),
"COMPLETED".to_string(),
)
.expect("failed to create OrderStatus");

assert_eq!(order_status.metadata.id.type_prefix(), "orderstatus");
assert_eq!(order_status.metadata.id.type_prefix(), "orderstatus");
}

#[test]
fn can_parse_order_status_from_json() {
let order_status = OrderStatus::create(
"did:example:from_1234".to_string(),
"did:example:to_1234".to_string(),
MessageKind::Rfq.typesafe_id().unwrap(),
"COMPLETED".to_string()
)
.expect("Could not create OrderStatus");
let json: String = serde_json::to_string(&order_status).expect("failed to serialize OrderStatus");
let parsed_order_status: Message<OrderStatusData> =
serde_json::from_str(&json).expect("failed to deserialize OrderStatus");
assert_eq!(order_status, parsed_order_status);
let order_status = OrderStatus::create(
"did:example:from_1234".to_string(),
"did:example:to_1234".to_string(),
MessageKind::Rfq.typesafe_id().unwrap(),
"COMPLETED".to_string(),
)
.expect("Could not create OrderStatus");
let json: String =
serde_json::to_string(&order_status).expect("failed to serialize OrderStatus");
let parsed_order_status: Message<OrderStatusData> =
serde_json::from_str(&json).expect("failed to deserialize OrderStatus");
assert_eq!(order_status, parsed_order_status);
}
}
1 change: 0 additions & 1 deletion crates/protocol/src/message/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub struct PaymentInstructions {

#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[skip_serializing_none]

#[serde(rename_all = "camelCase")]
pub struct PaymentInstruction {
/// Link or Instruction describing how to pay the PFI.
Expand Down
15 changes: 6 additions & 9 deletions crates/protocol/src/resource/offering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,12 @@ pub struct PaymentMethod {

impl PaymentMethod {
pub fn required_payment_details_schema(&self) -> Option<JSONSchema> {
self.required_payment_details
.as_ref()
.map(|json| {
JSONSchema::options()
.with_draft(Draft::Draft7)
.compile(json)
.ok()
})
.flatten()
self.required_payment_details.as_ref().and_then(|json| {
JSONSchema::options()
.with_draft(Draft::Draft7)
.compile(json)
.ok()
})
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/protocol/src/test_data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::message::close::{Close, CloseData};
use crate::message::quote::{Quote, QuoteData, QuoteDetails, PaymentInstructions, PaymentInstruction};
use crate::message::quote::{
PaymentInstruction, PaymentInstructions, Quote, QuoteData, QuoteDetails,
};
use crate::message::Message;
use crate::resource::offering::{CurrencyDetails, Offering, OfferingData, PaymentMethod};
use crate::resource::Resource;
Expand Down

0 comments on commit 72efe63

Please sign in to comment.