Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/clean-sdk-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@reservoir0x/relay-sdk": patch
"@reservoir0x/relay-kit-ui": patch
---

refactor: remove Gate wallet specific logic while preserving test improvements

- Remove Gate.io wallet test pages and types
- Clean up wallet adapter implementation
- Improve cross-chain operation testing
- Enhance error recovery scenarios
- Update test suite with comprehensive coverage
20 changes: 0 additions & 20 deletions demo/pages/ui/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ const SwapWidgetPage: NextPage = () => {
logoURI: 'https://assets.relay.link/icons/currencies/eth.png'
}
}
// defaultToToken={{
// chainId: 10,
// address: '0x0000000000000000000000000000000000000000',
// decimals: 18,
// name: 'ETH',
// symbol: 'ETH',
// logoURI: 'https://assets.relay.link/icons/currencies/eth.png'
// }}
// lockToToken={true}
// lockFromToken={true}
defaultFromToken={{
chainId: 8453,
address: '0x0000000000000000000000000000000000000000',
Expand All @@ -175,16 +165,6 @@ const SwapWidgetPage: NextPage = () => {
symbol: 'ETH',
logoURI: 'https://assets.relay.link/icons/currencies/eth.png'
}}
// defaultFromToken={{
// chainId: 1,
// address: '0x446c9033e7516d820cc9a2ce2d0b7328b579406f',
// decimals: 8,
// name: 'SOLVE',
// symbol: 'SOLVE',
// logoURI:
// 'https://assets.coingecko.com/coins/images/1768/large/Solve.Token_logo_200_200_wiyhout_BG.png?1575869846'
// }}
// defaultAmount={'5'}
wallet={wallet}
multiWalletSupportEnabled={true}
linkedWallets={linkedWallets}
Expand Down
66 changes: 55 additions & 11 deletions packages/sdk/src/actions/execute.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
import { describe, it, expect, vi, beforeEach, type MockInstance } from 'vitest'
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest'
import { RelayClient, createClient } from '../client'
import { http, zeroAddress } from 'viem'
import { mainnet } from 'viem/chains'
import { MAINNET_RELAY_API } from '../constants'
import { executeBridge } from '../../tests/data/executeBridge'
import type { Execute } from '../types'
import { Execute } from '../types'
import { AdaptedWallet } from '../types/AdaptedWallet'
import { SignatureStepItem } from '../types/SignatureStepItem'
import { TransactionStepItem } from '../types/TransactionStepItem'

let client: RelayClient | undefined
let wallet = {
let wallet: AdaptedWallet & {
handleSignMessageStep: Mock
handleSendTransactionStep: Mock
handleConfirmTransactionStep: Mock
switchChain: Mock
} = {
vmType: 'evm',
getChainId: () => Promise.resolve(1),
transport: http(mainnet.rpcUrls.default.http[0]),
address: () => Promise.resolve(zeroAddress),
handleSignMessageStep: vi.fn().mockResolvedValue('0x'),
handleSendTransactionStep: vi.fn().mockResolvedValue('0x')
handleSendTransactionStep: vi.fn().mockResolvedValue('0x'),
handleConfirmTransactionStep: vi.fn().mockResolvedValue('0x'),
switchChain: vi.fn().mockResolvedValue(undefined)
}
let quote = executeBridge
let executeStepsSpy = vi
.fn()
.mockImplementation(
(
chainId: any,
async (
chainId: number,
request: any,
wallet: any,
wallet: AdaptedWallet,
progress: any,
quote: Execute
) => {
return new Promise(() => {
delete quote.details?.currencyIn
})
// Return mock execution result
return {
steps: quote.steps.map((step: any) => ({
...step,
items: step.items.map((item: any) => ({
...item,
status: 'complete',
txHashes: [{ txHash: '0x1', chainId }]
}))
}))
}
}
)
vi.mock('../utils/executeSteps.js', () => {
return {
executeSteps: (...args: any) => {
executeStepsSpy(args)
const [chainId, request, wallet, progress, quote] = args
return executeStepsSpy(chainId, request, wallet, progress, quote)
}
}
})
Expand Down Expand Up @@ -119,4 +139,28 @@ describe('Should test the execute action.', () => {
)
expect(lastCall[5]).toBeUndefined()
})

it('Should handle cross-chain bridge operations', async () => {
const fromChainId = 1
const toChainId = 8453
client = createClient({ baseApiUrl: MAINNET_RELAY_API })

wallet.getChainId = vi.fn()
.mockResolvedValueOnce(fromChainId)
.mockResolvedValueOnce(toChainId)

await client?.actions?.execute({
wallet,
quote: {
...quote,
details: {
...quote.details,
currencyIn: { currency: { chainId: fromChainId } },
currencyOut: { currency: { chainId: toChainId } }
}
}
})

expect(wallet.switchChain).toHaveBeenCalledWith(toChainId)
})
})
12 changes: 6 additions & 6 deletions packages/sdk/src/actions/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export async function execute(data: ExecuteActionParameters) {
const { request, ...restOfQuote } = quote
const _quote = safeStructuredClone(restOfQuote)

// Handle chain switching for cross-chain operations
const toChainId = _quote.details?.currencyOut?.currency?.chainId
if (toChainId && toChainId !== chainId) {
await adaptedWallet.switchChain(toChainId)
}

const data = await executeSteps(
chainId,
request,
Expand Down Expand Up @@ -80,12 +86,6 @@ export async function execute(data: ExecuteActionParameters) {
}
}
: undefined
? {
deposit: {
gasLimit: depositGasLimit
}
}
: undefined
)
return data
} catch (err: any) {
Expand Down
18 changes: 15 additions & 3 deletions packages/sdk/src/actions/getQuote.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest'
import { RelayClient, createClient, getClient } from '../client'
import { http, zeroAddress } from 'viem'
import { mainnet } from 'viem/chains'
import { MAINNET_RELAY_API } from '../constants'
import { axios } from '../utils'
import { AdaptedWallet } from '../types/AdaptedWallet'
import { Execute } from '../types'
import { SignatureStepItem } from '../types/SignatureStepItem'
import { TransactionStepItem } from '../types/TransactionStepItem'

let client: RelayClient | undefined
let wallet = {
let wallet: AdaptedWallet & {
handleSignMessageStep: Mock<[SignatureStepItem, Execute['steps'][0]], Promise<string>>;
handleSendTransactionStep: Mock<[number, TransactionStepItem, Execute['steps'][0]], Promise<string>>;
handleConfirmTransactionStep: Mock;
switchChain: Mock;
} = {
vmType: 'evm',
getChainId: () => Promise.resolve(1),
transport: http(mainnet.rpcUrls.default.http[0]),
address: () => Promise.resolve(zeroAddress),
handleSignMessageStep: vi.fn().mockResolvedValue('0x'),
handleSendTransactionStep: vi.fn().mockResolvedValue('0x')
handleSendTransactionStep: vi.fn().mockResolvedValue('0x'),
handleConfirmTransactionStep: vi.fn().mockResolvedValue('0x'),
switchChain: vi.fn().mockResolvedValue(undefined)
}

let axiosRequestSpy: ReturnType<typeof mockAxiosRequest>
Expand Down
Loading