diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..3a16a018 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Justfile b/Justfile index 569590b6..e33f1f5e 100644 --- a/Justfile +++ b/Justfile @@ -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 \ No newline at end of file diff --git a/crates/protocol/src/message/close.rs b/crates/protocol/src/message/close.rs index 2a44bff5..d1494e61 100644 --- a/crates/protocol/src/message/close.rs +++ b/crates/protocol/src/message/close.rs @@ -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(), }; diff --git a/crates/protocol/src/message/order.rs b/crates/protocol/src/message/order.rs index 527e3836..40c59c02 100644 --- a/crates/protocol/src/message/order.rs +++ b/crates/protocol/src/message/order.rs @@ -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, @@ -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"); diff --git a/crates/protocol/src/message/order_status.rs b/crates/protocol/src/message/order_status.rs index e5c2827f..ac49888b 100644 --- a/crates/protocol/src/message/order_status.rs +++ b/crates/protocol/src/message/order_status.rs @@ -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, @@ -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)] @@ -52,29 +50,30 @@ mod tests { #[test] fn can_create() { - let order_status: Message = 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 = 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 = - 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 = + serde_json::from_str(&json).expect("failed to deserialize OrderStatus"); + assert_eq!(order_status, parsed_order_status); } } diff --git a/crates/protocol/src/message/quote.rs b/crates/protocol/src/message/quote.rs index 8ca193f3..6cbaa00c 100644 --- a/crates/protocol/src/message/quote.rs +++ b/crates/protocol/src/message/quote.rs @@ -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. diff --git a/crates/protocol/src/resource/offering.rs b/crates/protocol/src/resource/offering.rs index 0c9c7b23..11704bbd 100644 --- a/crates/protocol/src/resource/offering.rs +++ b/crates/protocol/src/resource/offering.rs @@ -82,15 +82,12 @@ pub struct PaymentMethod { impl PaymentMethod { pub fn required_payment_details_schema(&self) -> Option { - 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() + }) } } diff --git a/crates/protocol/src/test_data.rs b/crates/protocol/src/test_data.rs index c2c2c94d..2acc15e8 100644 --- a/crates/protocol/src/test_data.rs +++ b/crates/protocol/src/test_data.rs @@ -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;