From 5f681826ed710207cf1a33ec0a98677d86d8bf6a Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Tue, 29 Oct 2024 21:19:07 +0000 Subject: [PATCH] fix issues --- Cargo.lock | 2 + crates/quote/src/js_api/impls.rs | 20 ++---- crates/quote/src/js_api/mod.rs | 12 ++-- crates/subgraph/Cargo.toml | 2 + crates/subgraph/src/types/common.rs | 70 +++++++++++++++---- crates/subgraph/src/types/impls.rs | 31 +++++++++ crates/subgraph/src/types/mod.rs | 1 + tauri-app/src-tauri/Cargo.lock | 2 + test-js/quote/test.test.ts | 104 +++++++++++++++++----------- 9 files changed, 169 insertions(+), 75 deletions(-) create mode 100644 crates/subgraph/src/types/impls.rs diff --git a/Cargo.lock b/Cargo.lock index 9c0749016..d69c5c1ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6459,9 +6459,11 @@ dependencies = [ "cynic-introspection", "httpmock", "insta", + "js-sys", "rain_orderbook_bindings", "reqwest 0.12.5", "serde", + "serde-wasm-bindgen 0.6.5", "serde_json", "thiserror", "tokio", diff --git a/crates/quote/src/js_api/impls.rs b/crates/quote/src/js_api/impls.rs index d6abd1e0c..516075ac7 100644 --- a/crates/quote/src/js_api/impls.rs +++ b/crates/quote/src/js_api/impls.rs @@ -128,9 +128,12 @@ impl From for MainPair { impl From for BatchOrderQuotesResponse { fn from(value: MainBatchOrderQuotesResponse) -> Self { + let mut block_number_error = "block number, ".to_string(); BatchOrderQuotesResponse { pair: value.pair.into(), - block_number: encode_prefixed(value.block_number.to_be_bytes_vec()), + block_number: u64::try_from(value.block_number) + .inspect_err(|e| block_number_error.push_str(&e.to_string())) + .expect_throw(&block_number_error), data: value.data.map(OrderQuoteValue::from), success: value.success, error: value.error, @@ -139,14 +142,11 @@ impl From for BatchOrderQuotesResponse { } impl From for MainBatchOrderQuotesResponse { fn from(value: BatchOrderQuotesResponse) -> Self { - let mut block_number_error = "block number, ".to_string(); let mut max_output_error = "max output, ".to_string(); let mut ratio_error = "ratio, ".to_string(); MainBatchOrderQuotesResponse { pair: value.pair.into(), - block_number: U256::from_str(&value.block_number) - .inspect_err(|e| block_number_error.push_str(&e.to_string())) - .expect_throw(&block_number_error), + block_number: U256::from(value.block_number), data: value.data.map(|e| MainOrderQuoteValue { max_output: U256::from_str(&e.max_output) .inspect_err(|e| max_output_error.push_str(&e.to_string())) @@ -252,16 +252,6 @@ mod tests { assert_eq!(batch_order_quotes_response, expected); } - #[wasm_bindgen_test] - #[should_panic] - fn test_batch_order_quotes_response_unhappy() { - let main_batch_order_quotes_response = MainBatchOrderQuotesResponse::default(); - let mut batch_order_quotes_response = - BatchOrderQuotesResponse::from(main_batch_order_quotes_response); - batch_order_quotes_response.block_number = "abcd".to_string(); - let _ = MainBatchOrderQuotesResponse::from(batch_order_quotes_response); - } - #[wasm_bindgen_test] fn test_pair_roundtrip() { let main_pair = MainPair::default(); diff --git a/crates/quote/src/js_api/mod.rs b/crates/quote/src/js_api/mod.rs index 539a23730..b128b0fb1 100644 --- a/crates/quote/src/js_api/mod.rs +++ b/crates/quote/src/js_api/mod.rs @@ -192,7 +192,7 @@ pub struct Pair { #[tsify(into_wasm_abi, from_wasm_abi)] pub struct BatchOrderQuotesResponse { pub pair: Pair, - pub block_number: String, + pub block_number: u64, pub data: Option, pub success: bool, pub error: Option, @@ -202,12 +202,16 @@ pub struct BatchOrderQuotesResponse { /// Resolves with a BatchOrderQuotesResponse object #[wasm_bindgen(js_name = "getOrderQuote")] pub async fn get_order_quote( - order: Order, + order: Vec, rpc_url: &str, block_number: Option, ) -> Result { - match get_order_quotes(vec![order], block_number, rpc_url.to_string()).await { + match get_order_quotes(order, block_number, rpc_url.to_string()).await { Err(e) => Err(e), - Ok(v) => Ok(to_value(&BatchOrderQuotesResponse::from(v[0].clone()))?), + Ok(v) => Ok(to_value( + &v.into_iter() + .map(|v| BatchOrderQuotesResponse::from(v)) + .collect::>(), + )?), } } diff --git a/crates/subgraph/Cargo.toml b/crates/subgraph/Cargo.toml index 2fd658063..fa652dc7a 100644 --- a/crates/subgraph/Cargo.toml +++ b/crates/subgraph/Cargo.toml @@ -21,6 +21,8 @@ chrono = { workspace = true } cynic-introspection = "3.7.3" tsify = { version = "0.4.5", default-features = false, features = ["js", "wasm-bindgen"] } wasm-bindgen = { version = "0.2.92" } +js-sys = { version = "0.3.69" } +serde-wasm-bindgen = { version = "0.6.5" } [dev-dependencies] insta = { workspace = true } diff --git a/crates/subgraph/src/types/common.rs b/crates/subgraph/src/types/common.rs index 880a44178..fbf287e21 100644 --- a/crates/subgraph/src/types/common.rs +++ b/crates/subgraph/src/types/common.rs @@ -63,8 +63,9 @@ pub struct PaginationWithTimestampQueryVariables { pub timestamp_lte: Option, } -#[derive(cynic::QueryFragment, Debug, Serialize, Clone)] +#[derive(cynic::QueryFragment, Debug, Serialize, Clone, Tsify)] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct Orderbook { pub id: Bytes, } @@ -76,6 +77,7 @@ pub type RainMetaV1 = Bytes; #[typeshare] #[serde(rename_all = "camelCase")] #[tsify(into_wasm_abi, from_wasm_abi)] +// #[cfg_attr(target_family = "wasm", serde(rename(serialize = "SgOrder")))] pub struct Order { pub id: Bytes, pub order_bytes: Bytes, @@ -85,6 +87,7 @@ pub struct Order { pub inputs: Vec, pub orderbook: Orderbook, pub active: bool, + #[tsify(type = "SgBigInt")] pub timestamp_added: BigInt, pub meta: Option, pub add_events: Vec, @@ -100,10 +103,11 @@ pub struct TradeStructPartialOrder { pub order_hash: Bytes, } -#[derive(cynic::QueryFragment, Debug, Serialize, Clone)] +#[derive(cynic::QueryFragment, Debug, Serialize, Clone, Tsify)] #[cynic(graphql_type = "Order")] #[serde(rename_all = "camelCase")] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct OrderAsIO { pub id: Bytes, pub order_hash: Bytes, @@ -136,13 +140,16 @@ pub struct VaultsListQueryVariables { pub filters: Option, } -#[derive(cynic::QueryFragment, Debug, Serialize, Clone)] +#[derive(cynic::QueryFragment, Debug, Serialize, Clone, Tsify)] #[typeshare] #[serde(rename_all = "camelCase")] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct Vault { pub id: Bytes, pub owner: Bytes, + #[tsify(type = "SgBigInt")] pub vault_id: BigInt, + #[tsify(type = "SgBigInt")] pub balance: BigInt, pub token: Erc20, pub orderbook: Orderbook, @@ -155,11 +162,13 @@ pub struct Vault { pub balance_changes: Vec, } -#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize, Tsify)] #[cynic(graphql_type = "Vault")] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct VaultBalanceChangeVault { pub id: Bytes, + #[tsify(type = "SgBigInt")] pub vault_id: BigInt, pub token: Erc20, } @@ -179,10 +188,11 @@ pub struct VaultBalanceChangeUnwrapped { pub orderbook: Orderbook, } -#[derive(cynic::InlineFragments, Debug, Clone, Serialize)] +#[derive(cynic::InlineFragments, Debug, Clone, Serialize, Tsify)] #[serde(tag = "__typename", content = "data")] #[serde(rename_all = "camelCase")] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub enum VaultBalanceChange { Withdrawal(Withdrawal), TradeVaultBalanceChange(TradeVaultBalanceChange), @@ -192,61 +202,81 @@ pub enum VaultBalanceChange { Unknown, } -#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize, Tsify)] #[typeshare] #[serde(rename_all = "camelCase")] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct Deposit { pub id: Bytes, pub __typename: String, + #[tsify(type = "SgBigInt")] pub amount: BigInt, + #[tsify(type = "SgBigInt")] pub new_vault_balance: BigInt, + #[tsify(type = "SgBigInt")] pub old_vault_balance: BigInt, pub vault: VaultBalanceChangeVault, + #[tsify(type = "SgBigInt")] pub timestamp: BigInt, pub transaction: Transaction, pub orderbook: Orderbook, } -#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize, Tsify)] #[typeshare] #[serde(rename_all = "camelCase")] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct Withdrawal { pub id: Bytes, pub __typename: String, + #[tsify(type = "SgBigInt")] pub amount: BigInt, + #[tsify(type = "SgBigInt")] pub new_vault_balance: BigInt, + #[tsify(type = "SgBigInt")] pub old_vault_balance: BigInt, pub vault: VaultBalanceChangeVault, + #[tsify(type = "SgBigInt")] pub timestamp: BigInt, pub transaction: Transaction, pub orderbook: Orderbook, } -#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize, Tsify)] #[typeshare] #[serde(rename_all = "camelCase")] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct TradeVaultBalanceChange { pub id: Bytes, pub __typename: String, + #[tsify(type = "SgBigInt")] pub amount: BigInt, + #[tsify(type = "SgBigInt")] pub new_vault_balance: BigInt, + #[tsify(type = "SgBigInt")] pub old_vault_balance: BigInt, pub vault: VaultBalanceChangeVault, + #[tsify(type = "SgBigInt")] pub timestamp: BigInt, pub transaction: Transaction, pub orderbook: Orderbook, } -#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize, Tsify)] #[typeshare] #[serde(rename_all = "camelCase")] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct ClearBounty { pub id: Bytes, pub __typename: String, + #[tsify(type = "SgBigInt")] pub amount: BigInt, + #[tsify(type = "SgBigInt")] pub new_vault_balance: BigInt, + #[tsify(type = "SgBigInt")] pub old_vault_balance: BigInt, pub vault: VaultBalanceChangeVault, + #[tsify(type = "SgBigInt")] pub timestamp: BigInt, pub transaction: Transaction, pub orderbook: Orderbook, @@ -273,46 +303,56 @@ pub struct Trade { pub orderbook: Orderbook, } -#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize, Tsify)] #[cynic(graphql_type = "Trade")] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct OrderStructPartialTrade { pub id: Bytes, } -#[derive(cynic::QueryFragment, Debug, Serialize, Clone, PartialEq)] +#[derive(cynic::QueryFragment, Debug, Serialize, Clone, PartialEq, Tsify)] #[cynic(graphql_type = "ERC20")] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct Erc20 { pub id: Bytes, pub address: Bytes, pub name: Option, pub symbol: Option, + #[tsify(type = "SgBigInt")] pub decimals: Option, } -#[derive(cynic::QueryFragment, Debug, Serialize, Clone)] +#[derive(cynic::QueryFragment, Debug, Serialize, Clone, Tsify)] #[typeshare] #[serde(rename_all = "camelCase")] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct Transaction { pub id: Bytes, pub from: Bytes, + #[tsify(type = "SgBigInt")] pub block_number: BigInt, + #[tsify(type = "SgBigInt")] pub timestamp: BigInt, } -#[derive(cynic::QueryFragment, Debug, Serialize, Clone)] +#[derive(cynic::QueryFragment, Debug, Serialize, Clone, Tsify)] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct AddOrder { pub transaction: Transaction, } -#[derive(cynic::Scalar, Debug, Clone, PartialEq)] +#[derive(cynic::Scalar, Debug, Clone, PartialEq, Tsify)] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] +#[serde(rename = "SgBigInt")] pub struct BigInt(pub String); -#[derive(cynic::Scalar, Debug, Clone, PartialEq)] +#[derive(cynic::Scalar, Debug, Clone, PartialEq, Tsify)] #[typeshare] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct Bytes(pub String); #[derive(cynic::Enum, Clone, Copy, Debug)] diff --git a/crates/subgraph/src/types/impls.rs b/crates/subgraph/src/types/impls.rs new file mode 100644 index 000000000..d801d4619 --- /dev/null +++ b/crates/subgraph/src/types/impls.rs @@ -0,0 +1,31 @@ +#[cfg(target_family = "wasm")] +mod js_api { + use super::super::common::{ + AddOrder, BigInt, Bytes, ClearBounty, Deposit, Erc20, Order, OrderAsIO, + OrderStructPartialTrade, TradeVaultBalanceChange, Transaction, Vault, VaultBalanceChange, + VaultBalanceChangeVault, Withdrawal, + }; + use rain_orderbook_bindings::impl_wasm_traits; + use serde_wasm_bindgen::{from_value, to_value}; + use wasm_bindgen::{convert::*, describe::WasmDescribe}; + use wasm_bindgen::{ + describe::{inform, WasmDescribeVector, VECTOR}, + JsValue, UnwrapThrowExt, + }; + + impl_wasm_traits!(Order); + impl_wasm_traits!(Vault); + impl_wasm_traits!(AddOrder); + impl_wasm_traits!(OrderAsIO); + impl_wasm_traits!(VaultBalanceChangeVault); + impl_wasm_traits!(VaultBalanceChange); + impl_wasm_traits!(Withdrawal); + impl_wasm_traits!(TradeVaultBalanceChange); + impl_wasm_traits!(Deposit); + impl_wasm_traits!(ClearBounty); + impl_wasm_traits!(OrderStructPartialTrade); + impl_wasm_traits!(Erc20); + impl_wasm_traits!(Transaction); + impl_wasm_traits!(BigInt); + impl_wasm_traits!(Bytes); +} diff --git a/crates/subgraph/src/types/mod.rs b/crates/subgraph/src/types/mod.rs index 88b092954..b653da9b9 100644 --- a/crates/subgraph/src/types/mod.rs +++ b/crates/subgraph/src/types/mod.rs @@ -1,4 +1,5 @@ pub mod common; +mod impls; pub mod order; pub mod order_detail_traits; pub mod order_trade; diff --git a/tauri-app/src-tauri/Cargo.lock b/tauri-app/src-tauri/Cargo.lock index d90a96fb5..49665c07d 100644 --- a/tauri-app/src-tauri/Cargo.lock +++ b/tauri-app/src-tauri/Cargo.lock @@ -8371,9 +8371,11 @@ dependencies = [ "cynic", "cynic-codegen", "cynic-introspection", + "js-sys", "rain_orderbook_bindings", "reqwest 0.12.5", "serde", + "serde-wasm-bindgen 0.6.5", "serde_json", "thiserror", "tsify", diff --git a/test-js/quote/test.test.ts b/test-js/quote/test.test.ts index 177bf2460..515788982 100644 --- a/test-js/quote/test.test.ts +++ b/test-js/quote/test.test.ts @@ -1,34 +1,34 @@ -import assert from "assert" -import { getLocal } from "mockttp" -import { describe, it, beforeEach, afterEach } from "vitest" +import assert from "assert"; +import { getLocal } from "mockttp"; +import { describe, it, beforeEach, afterEach } from "vitest"; import { QuoteSpec, QuoteTarget, OrderQuoteValue, BatchOrderQuotesResponse, Order, -} from "../../dist/types/quote" +} from "../../dist/types/quote"; import { getId, doQuoteTargets, getQuoteTargetFromSubgraph, getOrderQuote, -} from "../../dist/cjs/quote" +} from "../../dist/cjs/quote"; describe("Rain Orderbook Quote Package Bindgen Tests", async function () { - const mockServer = getLocal() - beforeEach(() => mockServer.start(8081)) - afterEach(() => mockServer.stop()) + const mockServer = getLocal(); + beforeEach(() => mockServer.start(8081)); + afterEach(() => mockServer.stop()); it("should get correct id", async () => { - const orderbook = "0xF14E09601A47552De6aBd3A0B165607FaFd2B5Ba" + const orderbook = "0xF14E09601A47552De6aBd3A0B165607FaFd2B5Ba"; const orderHash = - "0xf4058d50e798f18a048097265fe67fe2e8619f337b9377a7620bb87fc2f52721" - const result = getId(orderbook, orderHash) + "0xf4058d50e798f18a048097265fe67fe2e8619f337b9377a7620bb87fc2f52721"; + const result = getId(orderbook, orderHash); const expected = - "0xca228cb816102ef9f8e0f9a87bb34e06c49c4d4ddf5a2a0ec229ab671475c235" - assert.equal(result, expected) - }) + "0xca228cb816102ef9f8e0f9a87bb34e06c49c4d4ddf5a2a0ec229ab671475c235"; + assert.equal(result, expected); + }); it("should get correct quote targets from subgraph", async () => { await mockServer.forPost("/sg-url").thenReply( @@ -106,7 +106,7 @@ describe("Rain Orderbook Quote Package Bindgen Tests", async function () { ], }, }) - ) + ); const quoteSpec: QuoteSpec = { orderbook: "0x713180d188e1ff758f508d9f2e1d350d650fea5e", @@ -115,12 +115,12 @@ describe("Rain Orderbook Quote Package Bindgen Tests", async function () { outputIOIndex: 0, inputIOIndex: 0, signedContext: [], - } + }; try { const result = await getQuoteTargetFromSubgraph( [quoteSpec], mockServer.url + "/sg-url" - ) + ); const expected: QuoteTarget = { quoteConfig: { order: { @@ -154,20 +154,20 @@ describe("Rain Orderbook Quote Package Bindgen Tests", async function () { signedContext: [], }, orderbook: "0x713180d188e1ff758f508d9f2e1d350d650fea5e", - } - assert.deepEqual(result[0], expected) + }; + assert.deepEqual(result[0], expected); } catch (error) { - console.log(error) - assert.fail("expected to resolve, but failed") + console.log(error); + assert.fail("expected to resolve, but failed"); } - }) + }); it("should quote targets", async () => { await mockServer .forPost("/rpc-url") .thenSendJsonRpcResult( "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002" - ) + ); const target: QuoteTarget = { orderbook: "0xc6768d9e1cdd2f2058c92185364a3a5d2e1e47de", quoteConfig: { @@ -201,37 +201,44 @@ describe("Rain Orderbook Quote Package Bindgen Tests", async function () { outputIOIndex: 0, signedContext: [], }, - } + }; try { - const result = await doQuoteTargets([target], mockServer.url + "/rpc-url") + const result = await doQuoteTargets( + [target], + mockServer.url + "/rpc-url" + ); const expected: OrderQuoteValue = { maxOutput: "0x0000000000000000000000000000000000000000000000000000000000000001", ratio: "0x0000000000000000000000000000000000000000000000000000000000000002", - } - assert.deepEqual(result[0], expected) + }; + assert.deepEqual(result[0], expected); } catch (error) { - console.log(error) - assert.fail("expected to resolve, but failed") + console.log(error); + assert.fail("expected to resolve, but failed"); } - }) + }); it("should get order quote", async () => { - await mockServer.forPost("/rpc-url").once().thenSendJsonRpcResult("0x1") - await mockServer.forPost("/rpc-url").once().thenSendJsonRpcResult("0x2") + await mockServer.forPost("/rpc-url").once().thenSendJsonRpcResult("0x01"); + await mockServer + .forPost("/rpc-url") + .thenSendJsonRpcResult( + "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002" + ); const order: Order = { id: "0x46891c626a8a188610b902ee4a0ce8a7e81915e1b922584f8168d14525899dfb", orderBytes: - "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000222222222222222222222222222222222222222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", orderHash: - "0x8a3fbb9caf53f18f1f78d90c48dbe4612bcd93285ed0fc033009b4a96ea2aaed", + "0x283508c8f56f4de2f21ee91749d64ec3948c16bc6b4bfe4f8d11e4e67d76f4e0", owner: "0x0000000000000000000000000000000000000000", outputs: [ { id: "0x0000000000000000000000000000000000000000", token: { id: "0x0000000000000000000000000000000000000000", - address: "0x0000000000000000000000000000000000000000", + address: "0x2222222222222222222222222222222222222222", name: "T1", symbol: "T1", decimals: "0", @@ -252,7 +259,7 @@ describe("Rain Orderbook Quote Package Bindgen Tests", async function () { id: "0x0000000000000000000000000000000000000000", token: { id: "0x0000000000000000000000000000000000000000", - address: "0x0000000000000000000000000000000000000000", + address: "0x1111111111111111111111111111111111111111", name: "T2", symbol: "T2", decimals: "0", @@ -285,8 +292,23 @@ describe("Rain Orderbook Quote Package Bindgen Tests", async function () { id: "0x0000000000000000000000000000000000000000", }, trades: [], - } - const result = await getOrderQuote(order, mockServer.url + "/rpc-url") - console.log(result) - }) -}) + }; + const result = await getOrderQuote([order], mockServer.url + "/rpc-url"); + const expected: BatchOrderQuotesResponse[] = [ + { + pair: { pairName: "T2/T1", inputIndex: 0, outputIndex: 0 }, + blockNumber: 1, + data: { + maxOutput: + "0x0000000000000000000000000000000000000000000000000000000000000001", + ratio: + "0x0000000000000000000000000000000000000000000000000000000000000002", + }, + success: true, + error: undefined, + }, + ]; + + assert.deepEqual(result, expected); + }); +});