Skip to content

Commit eb7c7d2

Browse files
committed
fix(ts-sdk): fao test cases
Signed-off-by: Eric Hegnes <[email protected]>
1 parent a889214 commit eb7c7d2

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

ts-sdk/test/evm/fungible-asset-order.test.ts

+39-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { assert, describe, it, expect } from "@effect/vitest"
2+
// TODO: fix mocking instancing
3+
import { vi } from "vitest"
24
import { type Context, Effect, Exit, Layer } from "effect"
35
import { ViemPublicClientSource, ViemPublicClientDestination } from "../../src/evm/client.js"
46
import { CosmWasmClientSource, CosmWasmClientDestination } from "../../src/cosmos/client.js"
@@ -11,6 +13,14 @@ import {
1113
createCosmosToCosmosFungibleAssetOrder
1214
} from "../../src/ucs03/fungible-asset-order.js"
1315
import { toHex } from "viem"
16+
import { ensureHex } from "@unionlabs/sdk/utils/index"
17+
18+
vi.mock('../../src/graphql/unwrapped-quote-token.js', async (importOriginal) => {
19+
return {
20+
...await importOriginal<typeof import('../../src/graphql/unwrapped-quote-token.js')>(),
21+
graphqlQuoteTokenUnwrapQuery: () => Effect.succeed("0x12345")
22+
}
23+
})
1424

1525
// Mock data for tests
1626
const mockErc20Meta = {
@@ -84,19 +94,23 @@ const mockCosmWasmClientDestination = {
8494

8595
// Test data
8696
const evmIntent = {
87-
sender: "0x123" as const,
88-
receiver: "0x123" as const,
89-
baseToken: "0x123" as const,
97+
sender: "0x123",
98+
receiver: "0x123",
99+
baseToken: "0x123",
90100
baseAmount: 1000000000000000000n, // 1 token with 18 decimals
91-
quoteAmount: 500000000000000000n // 0.5 token with 18 decimals
101+
quoteAmount: 500000000000000000n, // 0.5 token with 18 decimals
102+
sourceChainId: "chainId",
103+
sourceChannelId: 999,
92104
} as const
93105

94106
const cosmosIntent = {
95-
sender: "cosmos1sender",
107+
sender: "0x123",
96108
receiver: "0x123",
97-
baseToken: "cosmos1basetoken",
109+
baseToken: "0x123",
98110
baseAmount: BigInt(1000000), // 1 token with 6 decimals
99-
quoteAmount: BigInt(500000) // 0.5 token with 6 decimals
111+
quoteAmount: BigInt(500000), // 0.5 token with 6 decimals
112+
sourceChainId: "chainId",
113+
sourceChannelId: 999,
100114
} as const
101115

102116
const EvmToEvm = Layer.mergeAll(
@@ -160,9 +174,7 @@ const CosmosToCosmosError = Layer.mergeAll(
160174
Layer.succeed(CosmWasmClientSource, {
161175
client: {
162176
// biome-ignore lint/suspicious/useAwait: reason
163-
queryContractSmart: async () => {
164-
throw new Error("Mock error")
165-
}
177+
queryContractSmart: () => Promise.reject({})
166178
}
167179
} as unknown as Context.Tag.Service<CosmWasmClientSource>)
168180
)
@@ -227,9 +239,9 @@ describe("Fungible Asset Order Tests", () => {
227239
opcode: 3,
228240
version: 1,
229241
operand: [
230-
toHex(cosmosIntent.sender),
242+
cosmosIntent.sender,
231243
"0x123",
232-
toHex(cosmosIntent.baseToken),
244+
ensureHex(cosmosIntent.baseToken),
233245
cosmosIntent.baseAmount,
234246
mockCw20TokenInfo.symbol,
235247
mockCw20TokenInfo.name,
@@ -252,9 +264,9 @@ describe("Fungible Asset Order Tests", () => {
252264
opcode: 3,
253265
version: 1,
254266
operand: [
255-
toHex(cosmosIntent.sender),
256-
toHex(cosmosIntent.receiver),
257-
toHex(cosmosIntent.baseToken),
267+
cosmosIntent.sender,
268+
cosmosIntent.receiver,
269+
cosmosIntent.baseToken,
258270
cosmosIntent.baseAmount,
259271
mockCw20TokenInfo.symbol,
260272
mockCw20TokenInfo.name,
@@ -270,21 +282,25 @@ describe("Fungible Asset Order Tests", () => {
270282

271283
describe("Error handling", () => {
272284
it.layer(EvmToEvmError)(it => {
273-
it.effect("should handle errors when creating EVM to EVM fungible asset order", () =>
285+
it.effect("should handle errors when creating EVM to EVM fungible asset order with invalid input", () =>
274286
Effect.gen(function* () {
275-
const result = yield* Effect.exit(createEvmToEvmFungibleAssetOrder(evmIntent))
287+
const result = yield* Effect.exit(createEvmToEvmFungibleAssetOrder({
288+
...evmIntent,
289+
sender: "nonHexSender"
290+
} as unknown as any))
276291
assert.isTrue(Exit.isFailure(result))
277292
})
278293
)
279294
})
280295

281296
it.layer(CosmosToCosmosError)(it => {
282-
it.effect("should handle errors when creating Cosmos to Cosmos fungible asset order", () =>
283-
Effect.gen(function* () {
284-
const result = yield* Effect.exit(createCosmosToCosmosFungibleAssetOrder(cosmosIntent))
285-
expect(Exit.isFailure(result)).toBe(true)
286-
})
287-
)
297+
/** This is no longer applicable. There is a default handling applied on contract read error. */
298+
// it.effect("should handle errors when creating Cosmos to Cosmos fungible asset order when contract query fails", () =>
299+
// Effect.gen(function* () {
300+
// const result = yield* Effect.exit(createCosmosToCosmosFungibleAssetOrder(cosmosIntent))
301+
// expect(Exit.isFailure(result)).toBe(true)
302+
// })
303+
// )
288304
})
289305
})
290306
})

0 commit comments

Comments
 (0)