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..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 -> @@ -70,16 +80,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/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", diff --git a/bound/typescript/tests/test-vectors.test.ts b/bound/typescript/tests/test-vectors.test.ts index b86a392e..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; @@ -145,18 +147,17 @@ describe("test vectors", () => { describe("quote", () => { it("should parse", async () => { - // 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); - // - // await 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", async () => { @@ -173,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; 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 ee10dc52..9a25d034 100644 --- a/crates/tbdex/src/messages/quote.rs +++ b/crates/tbdex/src/messages/quote.rs @@ -155,27 +155,26 @@ 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::*; -// 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); + } +}