1
1
import { assert , describe , it , expect } from "@effect/vitest"
2
+ // TODO: fix mocking instancing
3
+ import { vi } from "vitest"
2
4
import { type Context , Effect , Exit , Layer } from "effect"
3
5
import { ViemPublicClientSource , ViemPublicClientDestination } from "../../src/evm/client.js"
4
6
import { CosmWasmClientSource , CosmWasmClientDestination } from "../../src/cosmos/client.js"
@@ -11,6 +13,14 @@ import {
11
13
createCosmosToCosmosFungibleAssetOrder
12
14
} from "../../src/ucs03/fungible-asset-order.js"
13
15
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
+ } )
14
24
15
25
// Mock data for tests
16
26
const mockErc20Meta = {
@@ -84,19 +94,23 @@ const mockCosmWasmClientDestination = {
84
94
85
95
// Test data
86
96
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" ,
90
100
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 ,
92
104
} as const
93
105
94
106
const cosmosIntent = {
95
- sender : "cosmos1sender " ,
107
+ sender : "0x123 " ,
96
108
receiver : "0x123" ,
97
- baseToken : "cosmos1basetoken " ,
109
+ baseToken : "0x123 " ,
98
110
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 ,
100
114
} as const
101
115
102
116
const EvmToEvm = Layer . mergeAll (
@@ -160,9 +174,7 @@ const CosmosToCosmosError = Layer.mergeAll(
160
174
Layer . succeed ( CosmWasmClientSource , {
161
175
client : {
162
176
// biome-ignore lint/suspicious/useAwait: reason
163
- queryContractSmart : async ( ) => {
164
- throw new Error ( "Mock error" )
165
- }
177
+ queryContractSmart : ( ) => Promise . reject ( { } )
166
178
}
167
179
} as unknown as Context . Tag . Service < CosmWasmClientSource > )
168
180
)
@@ -227,9 +239,9 @@ describe("Fungible Asset Order Tests", () => {
227
239
opcode : 3 ,
228
240
version : 1 ,
229
241
operand : [
230
- toHex ( cosmosIntent . sender ) ,
242
+ cosmosIntent . sender ,
231
243
"0x123" ,
232
- toHex ( cosmosIntent . baseToken ) ,
244
+ ensureHex ( cosmosIntent . baseToken ) ,
233
245
cosmosIntent . baseAmount ,
234
246
mockCw20TokenInfo . symbol ,
235
247
mockCw20TokenInfo . name ,
@@ -252,9 +264,9 @@ describe("Fungible Asset Order Tests", () => {
252
264
opcode : 3 ,
253
265
version : 1 ,
254
266
operand : [
255
- toHex ( cosmosIntent . sender ) ,
256
- toHex ( cosmosIntent . receiver ) ,
257
- toHex ( cosmosIntent . baseToken ) ,
267
+ cosmosIntent . sender ,
268
+ cosmosIntent . receiver ,
269
+ cosmosIntent . baseToken ,
258
270
cosmosIntent . baseAmount ,
259
271
mockCw20TokenInfo . symbol ,
260
272
mockCw20TokenInfo . name ,
@@ -270,21 +282,25 @@ describe("Fungible Asset Order Tests", () => {
270
282
271
283
describe ( "Error handling" , ( ) => {
272
284
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 " , ( ) =>
274
286
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 ) )
276
291
assert . isTrue ( Exit . isFailure ( result ) )
277
292
} )
278
293
)
279
294
} )
280
295
281
296
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
+ // )
288
304
} )
289
305
} )
290
306
} )
0 commit comments