Skip to content

Commit

Permalink
l2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrosario committed Nov 24, 2023
1 parent 0966042 commit c6f4036
Show file tree
Hide file tree
Showing 5 changed files with 1,559 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hooks/L1/useWriteDepositERC20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ test('useWriteDepositERC20', async () => {
"type": "receive",
},
],
"account": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"address": "0x3154Cf16ccdb4C6d922629664174b904d80F2C35",
"args": [
"0xbe9895146f7af43049ca1c1ae358b0541ea49704",
Expand Down
121 changes: 121 additions & 0 deletions src/hooks/L2/useSimulateWithdrawERC20.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { expect, test } from 'vitest'
import { accounts } from '../../_test/constants.js'
import { renderHook, waitFor } from '../../_test/react.js'
import { useSimulateWithdrawERC20 } from './useSimulateWithdrawERC20.js'

test('useSimulateWithdrawERC20', async () => {
const { result } = renderHook(() =>
useSimulateWithdrawERC20({
args: {
l2Token: '0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22',
to: accounts[0],
amount: 0n,
},
chainId: 8453,
dataSuffix: '0x1234',
})
)

await waitFor(() => expect(result.current.isSuccess).toBeTruthy())

expect(result.current).toMatchInlineSnapshot(`
{
"data": {
"request": {
"__mode": "prepared",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_l2Token",
"type": "address",
},
{
"internalType": "address",
"name": "_to",
"type": "address",
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256",
},
{
"internalType": "uint32",
"name": "_minGasLimit",
"type": "uint32",
},
{
"internalType": "bytes",
"name": "_extraData",
"type": "bytes",
},
],
"name": "withdrawTo",
"outputs": [],
"stateMutability": "payable",
"type": "function",
},
],
"account": {
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"type": "json-rpc",
},
"address": "0x4200000000000000000000000000000000000010",
"args": [
"0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
0n,
0,
"0x",
],
"chainId": 8453,
"dataSuffix": "0x1234",
"functionName": "withdrawTo",
},
"result": undefined,
},
"dataUpdatedAt": 1700438400000,
"error": null,
"errorUpdateCount": 0,
"errorUpdatedAt": 0,
"failureCount": 0,
"failureReason": null,
"fetchStatus": "idle",
"isError": false,
"isFetched": true,
"isFetchedAfterMount": true,
"isFetching": false,
"isInitialLoading": false,
"isLoading": false,
"isLoadingError": false,
"isPaused": false,
"isPending": false,
"isPlaceholderData": false,
"isRefetchError": false,
"isRefetching": false,
"isStale": true,
"isSuccess": true,
"queryKey": [
"simulateContract",
{
"account": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"address": "0x4200000000000000000000000000000000000010",
"args": [
"0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
0n,
0,
"0x",
],
"chainId": 8453,
"dataSuffix": "0x1234",
"functionName": "withdrawTo",
},
],
"refetch": [Function],
"status": "success",
}
`)
}, { retry: 3 })
122 changes: 122 additions & 0 deletions src/hooks/L2/useSimulateWithdrawETH.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { expect, test } from 'vitest'
import { accounts } from '../../_test/constants.js'
import { renderHook, waitFor } from '../../_test/react.js'
import { useSimulateWithdrawETH } from './useSimulateWithdrawETH.js'

test('useSimulateWithdrawETH', async () => {
const { result } = renderHook(() =>
useSimulateWithdrawETH({
args: {
to: accounts[0],
amount: 1n,
},
chainId: 8453,
dataSuffix: '0x1234',
})
)

await waitFor(() => expect(result.current.isSuccess).toBeTruthy())

expect(result.current).toMatchInlineSnapshot(`
{
"data": {
"request": {
"__mode": "prepared",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_l2Token",
"type": "address",
},
{
"internalType": "address",
"name": "_to",
"type": "address",
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256",
},
{
"internalType": "uint32",
"name": "_minGasLimit",
"type": "uint32",
},
{
"internalType": "bytes",
"name": "_extraData",
"type": "bytes",
},
],
"name": "withdrawTo",
"outputs": [],
"stateMutability": "payable",
"type": "function",
},
],
"account": {
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"type": "json-rpc",
},
"address": "0x4200000000000000000000000000000000000010",
"args": [
"0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
1n,
0,
"0x",
],
"chainId": 8453,
"dataSuffix": "0x1234",
"functionName": "withdrawTo",
"value": 1n,
},
"result": undefined,
},
"dataUpdatedAt": 1700438400000,
"error": null,
"errorUpdateCount": 0,
"errorUpdatedAt": 0,
"failureCount": 0,
"failureReason": null,
"fetchStatus": "idle",
"isError": false,
"isFetched": true,
"isFetchedAfterMount": true,
"isFetching": false,
"isInitialLoading": false,
"isLoading": false,
"isLoadingError": false,
"isPaused": false,
"isPending": false,
"isPlaceholderData": false,
"isRefetchError": false,
"isRefetching": false,
"isStale": true,
"isSuccess": true,
"queryKey": [
"simulateContract",
{
"account": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"address": "0x4200000000000000000000000000000000000010",
"args": [
"0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
1n,
0,
"0x",
],
"chainId": 8453,
"dataSuffix": "0x1234",
"functionName": "withdrawTo",
"value": 1n,
},
],
"refetch": [Function],
"status": "success",
}
`)
})
Loading

0 comments on commit c6f4036

Please sign in to comment.