From c97a400d7176bfa3575c8265f8652e5ddf42e099 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 1 Oct 2024 10:22:13 -0700 Subject: [PATCH 1/5] updates --- .../vectors/TbdexTestVectorsProtocolTest.kt | 19 ++++---- bound/typescript/tests/test-vectors.test.ts | 22 ++++----- crates/tbdex/src/messages/quote.rs | 46 +++++++++---------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt b/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt index 1011a278..1d0c87e4 100644 --- a/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt +++ b/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt @@ -70,16 +70,15 @@ class TbdexTestVectorsProtocolTest { ) } - // TODO: uncomment when quote test vector is updated -// @Test -// fun parse_quote() { -// testVector( -// "parse-quote.json", -// Quote.Companion::fromJsonString, -// { it.toJsonString() }, -// { it.verify() } -// ) -// } + @Test + fun parse_quote() { + testVector( + "parse-quote.json", + Quote.Companion::fromJsonString, + { it.toJsonString() }, + { it.verify() } + ) + } @Test fun parse_close() { diff --git a/bound/typescript/tests/test-vectors.test.ts b/bound/typescript/tests/test-vectors.test.ts index d82cdfd8..432c99a5 100644 --- a/bound/typescript/tests/test-vectors.test.ts +++ b/bound/typescript/tests/test-vectors.test.ts @@ -146,17 +146,17 @@ describe("test vectors", () => { describe("quote", () => { it("should parse", () => { // TODO test vector needs updating, needs the `paymentInstruction`'s on the payin & payout removed - // const input = QuoteVector.input; - // const quote = Quote.fromJSONString(input); - // expect(quote.metadata).to.deep.equal(QuoteVector.output.metadata); - // expect(quote.data).to.deep.equal(QuoteVector.output.data); - // expect(quote.signature).to.equal(QuoteVector.output.signature); - // - // const quoteJSONString = quote.toJSONString(); - // const quoteJSON = JSON.parse(quoteJSONString); - // expect(quoteJSON).to.deep.equal(QuoteVector.output); - // - // quote.verify(); + const input = QuoteVector.input; + const quote = Quote.fromJSONString(input); + expect(quote.metadata).to.deep.equal(QuoteVector.output.metadata); + expect(quote.data).to.deep.equal(QuoteVector.output.data); + expect(quote.signature).to.equal(QuoteVector.output.signature); + + const quoteJSONString = quote.toJSONString(); + const quoteJSON = JSON.parse(quoteJSONString); + expect(quoteJSON).to.deep.equal(QuoteVector.output); + + quote.verify(); }); it("should create, sign, and verify", () => { diff --git a/crates/tbdex/src/messages/quote.rs b/crates/tbdex/src/messages/quote.rs index 0d11f1e2..8c470da7 100644 --- a/crates/tbdex/src/messages/quote.rs +++ b/crates/tbdex/src/messages/quote.rs @@ -155,26 +155,26 @@ pub struct QuoteDetails { } // TODO: Uncomment when we have parse_quote.json vector updated with no payment instructions -// #[cfg(test)] -// mod tbdex_test_vectors_protocol { -// use super::*; -// use std::fs; -// -// #[derive(Debug, serde::Deserialize)] -// pub struct TestVector { -// pub input: String, -// pub output: Quote, -// } -// -// -// #[test] -// fn parse_quote() { -// let path = "../../tbdex/hosted/test-vectors/protocol/vectors/parse-quote.json"; -// let test_vector_json: String = fs::read_to_string(path).unwrap(); -// -// let test_vector: TestVector = serde_json::from_str(&test_vector_json).unwrap(); -// let parsed_quote: Quote = Quote::from_json_string(&test_vector.input).unwrap(); -// -// assert_eq!(test_vector.output, parsed_quote); -// } -// } +#[cfg(test)] +mod tbdex_test_vectors_protocol { + use super::*; + use std::fs; + + #[derive(Debug, serde::Deserialize)] + pub struct TestVector { + pub input: String, + pub output: Quote, + } + + + #[test] + fn parse_quote() { + let path = "../../tbdex/hosted/test-vectors/protocol/vectors/parse-quote.json"; + let test_vector_json: String = fs::read_to_string(path).unwrap(); + + let test_vector: TestVector = serde_json::from_str(&test_vector_json).unwrap(); + let parsed_quote: Quote = Quote::from_json_string(&test_vector.input).unwrap(); + + assert_eq!(test_vector.output, parsed_quote); + } +} From fc7ac816e27db761a16838b7f53b16b61bb2f595 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 1 Oct 2024 10:37:03 -0700 Subject: [PATCH 2/5] add order instruction to kt --- .../tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt b/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt index 1d0c87e4..8ecceed8 100644 --- a/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt +++ b/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TbdexTestVectorsProtocolTest.kt @@ -32,6 +32,16 @@ class TbdexTestVectorsProtocolTest { ) } + @Test + fun parse_orderinstructions() { + testVector( + "parse-orderinstructions.json", + OrderInstructions.Companion::fromJsonString, + { it.toJsonString() }, + { it.verify() } + ) + } + @Test fun parse_rfq() { testVector("parse-rfq.json", { input -> From fb8da2809792e509f65425bdf99f6b8def0ed8d4 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 1 Oct 2024 10:41:27 -0700 Subject: [PATCH 3/5] order instruction to ts --- bound/typescript/tests/test-vectors.test.ts | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bound/typescript/tests/test-vectors.test.ts b/bound/typescript/tests/test-vectors.test.ts index 74d23918..34b6ed20 100644 --- a/bound/typescript/tests/test-vectors.test.ts +++ b/bound/typescript/tests/test-vectors.test.ts @@ -4,6 +4,7 @@ import BalanceVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/p import RfqVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/parse-rfq.json" assert { type: "json" }; import RfqOmitPrivateDataVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/parse-rfq-omit-private-data.json" assert { type: "json" }; import QuoteVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/parse-quote.json" assert { type: "json" }; +import OrderInstructionsVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/parse-orderinstructions.json" assert { type: "json" }; import OrderVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/parse-order.json" assert { type: "json" }; import CancelVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/parse-cancel.json" assert { type: "json" }; import OrderStatusVector from "../../../tbdex/hosted/test-vectors/protocol/vectors/parse-orderstatus.json" assert { type: "json" }; @@ -19,6 +20,7 @@ import { Order } from "../src/messages/order"; import { Cancel } from "../src/messages/cancel"; import { OrderStatus } from "../src/messages/order-status"; import { Close } from "../src/messages/close"; +import { OrderInstructions } from "../src/messages/order-instructions"; describe("test vectors", () => { let bearerDID: BearerDid; @@ -172,6 +174,35 @@ describe("test vectors", () => { }); }); + describe("order instructions", () => { + it("should parse", async () => { + const input = OrderInstructionsVector.input; + const orderInstructions = OrderInstructions.fromJSONString(input); + expect(orderInstructions.metadata).to.deep.equal(OrderInstructionsVector.output.metadata); + expect(orderInstructions.data).to.deep.equal(OrderInstructionsVector.output.data); + expect(orderInstructions.signature).to.equal(OrderInstructionsVector.output.signature); + + const orderInstructionsJSONString = orderInstructions.toJSONString(); + const orderInstructionsJSON = JSON.parse(orderInstructionsJSONString); + expect(orderInstructionsJSON).to.deep.equal(OrderInstructionsVector.output); + + await orderInstructions.verify(); + }); + + it("should create, sign, and verify", async () => { + const orderInstructions = OrderInstructions.create( + OrderInstructionsVector.output.metadata.to, + OrderInstructionsVector.output.metadata.from, + OrderInstructionsVector.output.metadata.exchangeId, + OrderInstructionsVector.output.data, + OrderInstructionsVector.output.metadata.protocol + ); + + orderInstructions.sign(bearerDID); + await orderInstructions.verify(); + }); + }); + describe("order", () => { it("should parse", async () => { const input = OrderVector.input; From 330550de70e7bde67f217e944ec2e5f36aa5560e Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 1 Oct 2024 10:48:26 -0700 Subject: [PATCH 4/5] update rust --- .../tbdex/src/messages/order_instructions.rs | 23 +++++++++++++++++++ crates/tbdex/src/messages/quote.rs | 1 - 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/tbdex/src/messages/order_instructions.rs b/crates/tbdex/src/messages/order_instructions.rs index 0f703c93..6cea4e6a 100644 --- a/crates/tbdex/src/messages/order_instructions.rs +++ b/crates/tbdex/src/messages/order_instructions.rs @@ -142,3 +142,26 @@ pub struct PaymentInstruction { #[serde(skip_serializing_if = "Option::is_none")] pub instruction: Option, } +#[cfg(test)] +mod tbdex_test_vectors_protocol { + use super::*; + use std::fs; + + #[derive(Debug, serde::Deserialize)] + pub struct OrderInstructionsTestVector { + pub input: String, + pub output: OrderInstructions, + } + + #[test] + fn parse_order_instructions() { + print!("~~RUNNING"); + let path = "../../tbdex/hosted/test-vectors/protocol/vectors/parse-orderinstructions.json"; + let test_vector_json: String = fs::read_to_string(path).unwrap(); + + let test_vector: OrderInstructionsTestVector = serde_json::from_str(&test_vector_json).unwrap(); + let parsed_order_instructions: OrderInstructions = OrderInstructions::from_json_string(&test_vector.input).unwrap(); + + assert_eq!(test_vector.output, parsed_order_instructions); + } +} \ No newline at end of file diff --git a/crates/tbdex/src/messages/quote.rs b/crates/tbdex/src/messages/quote.rs index dcba449b..9a25d034 100644 --- a/crates/tbdex/src/messages/quote.rs +++ b/crates/tbdex/src/messages/quote.rs @@ -155,7 +155,6 @@ pub struct QuoteDetails { pub fee: Option, } -// TODO: Uncomment when we have parse_quote.json vector updated with no payment instructions #[cfg(test)] mod tbdex_test_vectors_protocol { use super::*; From e75148a18fbdbe961d81d79b2fbe65791d886f47 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 1 Oct 2024 11:03:38 -0700 Subject: [PATCH 5/5] fix kt --- bound/kt/src/test/kotlin/tbdex/sdk/vectors/TestVectors.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TestVectors.kt b/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TestVectors.kt index dbbae6a7..cd7f208b 100644 --- a/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TestVectors.kt +++ b/bound/kt/src/test/kotlin/tbdex/sdk/vectors/TestVectors.kt @@ -15,6 +15,7 @@ object TestVectors { "parse-cancel.json", "parse-offering.json", "parse-order.json", + "parse-orderinstructions.json", "parse-orderstatus.json", "parse-quote.json", "parse-rfq.json",