-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(sdk): further setup for integration tests #3282
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { act, render, waitFor } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { expect, test } from 'vitest' | ||
import { useConnect } from 'wagmi' | ||
|
||
import { | ||
type Quote, | ||
useOrder, | ||
useQuote, | ||
useValidateOrder, | ||
} from '../src/index.js' | ||
|
||
import { | ||
ContextProvider, | ||
ETHER, | ||
MOCK_L1_ID, | ||
MOCK_L2_ID, | ||
ZERO_ADDRESS, | ||
accounts, | ||
createRenderHook, | ||
createWagmiConfig, | ||
testConnector, | ||
} from './test-utils.js' | ||
|
||
test('successfully processes order from quote to filled', async () => { | ||
const wagmiConfig = createWagmiConfig() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see |
||
const renderHook = createRenderHook({ wagmiConfig }) | ||
|
||
const quoteHook = renderHook(() => { | ||
return useQuote({ | ||
enabled: true, | ||
mode: 'expense', | ||
srcChainId: MOCK_L1_ID, | ||
destChainId: MOCK_L2_ID, | ||
deposit: { | ||
amount: 2n * ETHER, | ||
isNative: true, | ||
}, | ||
expense: { | ||
amount: 1n * ETHER, | ||
isNative: true, | ||
}, | ||
}) | ||
}) | ||
await waitFor(() => expect(quoteHook.result.current.isSuccess).toBe(true)) | ||
|
||
const quote = quoteHook.result.current.query.data as Quote | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious, why do you need this type cast? |
||
expect(quote).toEqual({ | ||
deposit: { token: ZERO_ADDRESS, amount: 2n * ETHER }, | ||
expense: { token: ZERO_ADDRESS, amount: 1994017946161515453n }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the expense values are driven by the response from the solver api, so this assertion is unstable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could instead assert the value exists, and is less than or equal to the deposit amount maybe? |
||
}) | ||
|
||
const orderParams = { | ||
deposit: { token: ZERO_ADDRESS, amount: 2n * ETHER }, | ||
expense: { token: ZERO_ADDRESS, amount: 1n * ETHER }, | ||
calls: [{ target: accounts[0], value: 1n * ETHER }], | ||
srcChainId: MOCK_L1_ID, | ||
destChainId: MOCK_L2_ID, | ||
validateEnabled: false, | ||
} | ||
|
||
const validateHook = renderHook(() => { | ||
return useValidateOrder({ enabled: true, order: orderParams }) | ||
}) | ||
await waitFor(() => { | ||
return expect(validateHook.result.current.status === 'accepted').toBe(true) | ||
}) | ||
|
||
const connectRef = createRef() | ||
const orderRef = createRef() | ||
|
||
// useOrder() can only be used with a connected account, so we need to render it conditionally | ||
function TestOrder() { | ||
orderRef.current = useOrder(orderParams) | ||
return null | ||
} | ||
|
||
// Wrap TestOrder to only render if connected | ||
function TestConnectAndOrder() { | ||
const connectReturn = useConnect() | ||
connectRef.current = connectReturn | ||
return connectReturn.data ? <TestOrder /> : null | ||
} | ||
|
||
render(<TestConnectAndOrder />, { wrapper: ContextProvider }) | ||
act(() => { | ||
connectRef.current?.connect({ connector: testConnector }) | ||
}) | ||
|
||
await waitFor(() => expect(orderRef.current).toBeDefined()) | ||
act(() => { | ||
orderRef.current?.open() | ||
}) | ||
await waitFor(() => expect(orderRef.current?.txHash).toBeDefined()) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you planning to create more specific test modules? would be good to decouple a bit
aka test quote and order in isolation, and together