-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d7150c
commit 3c9e79d
Showing
6 changed files
with
146 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { connect, disconnect } from '@wagmi/core' | ||
import { baseAddresses } from 'op-viem/chains' | ||
import { base } from 'viem/chains' | ||
import { expect, test } from 'vitest' | ||
import { config } from '../../_test/config.js' | ||
import { accounts } from '../../_test/constants.js' | ||
import { renderHook, waitFor } from '../../_test/react.js' | ||
import { useWriteDepositERC20 } from './useWriteDepositERC20.js' | ||
|
||
const connector = config.connectors[0]! | ||
|
||
test(useWriteDepositERC20.name, async () => { | ||
await connect(config, { connector }) | ||
|
||
const { result } = renderHook(() => | ||
useWriteDepositERC20({ | ||
l2ChainId: base.id, | ||
Check failure on line 17 in src/hooks/L1/useWriteDepositERC20.test.ts GitHub Actions / Typecheck
|
||
args: { | ||
l1Token: '0xTokenAddressL1', | ||
l2Token: '0xTokenAddressL2', | ||
to: accounts[0], | ||
amount: 100n, // Assuming amount is in BigInt format | ||
minGasLimit: 21000, | ||
extraData: '0x', | ||
}, | ||
...baseAddresses, | ||
}) | ||
) | ||
|
||
expect(result.current.writeDepositERC20).toBeDefined() | ||
expect(result.current.writeDepositERC20Async).toBeDefined() | ||
expect(result.current.data).toBeUndefined() | ||
expect(result.current.isIdle).toBe(true) | ||
|
||
result.current.writeDepositERC20() | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBeTruthy()) | ||
|
||
expect(result.current).toMatchInlineSnapshot() | ||
|
||
await disconnect(config, { connector }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { baseAddresses } from 'op-viem/chains' | ||
import { base } from 'viem/chains' | ||
import { expect, test } from 'vitest' | ||
import { accounts } from '../../_test/constants.js' | ||
import { renderHook, waitFor } from '../../_test/react.js' | ||
import { useWriteDepositETH } from './useWriteDepositETH.js' | ||
|
||
test(useWriteDepositETH.name, async () => { | ||
const { result } = renderHook(() => | ||
useWriteDepositETH({ | ||
l2ChainId: base.id, | ||
Check failure on line 11 in src/hooks/L1/useWriteDepositETH.test.ts GitHub Actions / Typecheck
|
||
args: { | ||
to: accounts[0], | ||
gasLimit: 21000, | ||
data: '0x', | ||
// typescript wasn't compiling for me for some reason | ||
...{ amount: 1n }, | ||
}, | ||
...baseAddresses, | ||
}) | ||
) | ||
|
||
// write contract lazily writes | ||
// these are low value checks we are testing wagmi here | ||
expect(result.current.writeDepositETH).toBeDefined() | ||
expect(result.current.writeDepositETHAsync).toBeDefined() | ||
expect(result.current.data).toBeUndefined() | ||
expect(result.current.isIdle).toBe(true) | ||
|
||
// go ahead and trigger the write | ||
result.current.writeDepositETH() | ||
|
||
// since we didn't use the async wait for it to succeed | ||
await waitFor(() => { | ||
// check for error first so if one happens we can see it in the test failure | ||
expect(result.current.error).toBeUndefined() | ||
expect(result.current.isSuccess).toBeTruthy() | ||
}) | ||
|
||
// now assert the result is what we expect | ||
expect(result.current).toMatchInlineSnapshot() | ||
}) |