Skip to content

Commit

Permalink
wip fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Sep 5, 2023
1 parent 48efb80 commit e5457d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { render } from 'src/test/utils'

import { SuccessfulProposalActions } from './SuccessfulProposalActions'

vi.mock('next/router', () => ({ useRouter: vi.fn() }))

describe('proposal status', () => {
const date = new Date(2022, 1, 1)

Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/services/abiService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ describe('abiService', () => {
} catch (err) {}

expect(spy).toHaveBeenCalledOnce()
expect(spy).toHaveBeenCalledWith(
'0x9444390c01Dd5b7249E53FAc31290F7dFF53450D',
'0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
)
expect(spy).toHaveBeenCalledWith({
address: '0x9444390c01Dd5b7249E53FAc31290F7dFF53450D',
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc',
})
})

it('skips redis check and checks original contract with etherscan', async () => {
Expand Down
55 changes: 33 additions & 22 deletions apps/web/src/services/simulationService.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import axios from 'axios'
import { Address, TransactionReceipt, createPublicClient, http, parseEther } from 'viem'
import {
Address,
TransactionReceipt,
createTestClient,
http,
parseEther,
publicActions,
} from 'viem'
import { vi } from 'vitest'
import { foundry } from 'wagmi/chains'

import { PUBLIC_ALL_CHAINS } from 'src/constants/defaultChains'
import { CHAIN_ID } from 'src/typings'

import { InvalidRequestError } from './errors'
Expand All @@ -20,11 +27,11 @@ vi.mock('axios', () => {
}
})

vi.mock('viem', () => {
vi.mock('viem', async () => {
const actual = await vi.importActual<any>('viem')
return {
default: {
createPublicClient: vi.fn(),
},
...actual,
createPublicClient: vi.fn(),
}
})

Expand All @@ -37,7 +44,7 @@ describe('simulationService', () => {
const treasuryAddress: Address = '0xbcdfd67cce7bf4f49c0631ddd14eadff4d5ca15d'
const request = {
treasuryAddress,
chainId: CHAIN_ID.ETHEREUM,
chainId: CHAIN_ID.FOUNDRY,
targets: [
'0x7d8ba3e0745079b292f68e421d292c05da2d0721',
'0xa7c8f84ec8cbed6e8fb793904cd1ec9ddfc9c35d',
Expand Down Expand Up @@ -67,7 +74,7 @@ describe('simulationService', () => {
expect(() =>
simulate({
treasuryAddress,
chainId: CHAIN_ID.ETHEREUM,
chainId: CHAIN_ID.FOUNDRY,
targets: ['t1', 't2', 't3'],
calldatas: ['c1', 'c2'],
values: ['v1, v2'],
Expand All @@ -77,7 +84,7 @@ describe('simulationService', () => {
expect(() =>
simulate({
treasuryAddress,
chainId: CHAIN_ID.ETHEREUM,
chainId: CHAIN_ID.FOUNDRY,
targets: ['t1'],
calldatas: ['c1'],
values: ['v1, v2'],
Expand All @@ -87,7 +94,7 @@ describe('simulationService', () => {
expect(() =>
simulate({
treasuryAddress,
chainId: CHAIN_ID.ETHEREUM,
chainId: CHAIN_ID.FOUNDRY,
targets: ['t1'],
calldatas: ['c1', 'c2'],
values: ['v1, v2'],
Expand Down Expand Up @@ -117,10 +124,12 @@ describe('simulationService', () => {
const forkId = 'forkId'
const simulationId = 'simulationId'

const forkProvider = createPublicClient({
chain: PUBLIC_ALL_CHAINS.find((x) => x.id === CHAIN_ID.ETHEREUM),
transport: http(`https://rpc.tenderly.co/fork/${forkId}`),
})
const forkProvider = createTestClient({
chain: foundry,
mode: 'anvil',
transport: http(`https://rpc.tenderly.co/fork/forkId`),
}).extend(publicActions)

vi.mocked(forkProvider.getBalance).mockResolvedValueOnce(parseEther('105')) // mock tenderly_addBalance
vi.mocked(axios.post).mockResolvedValueOnce({
status: 200,
Expand Down Expand Up @@ -178,10 +187,11 @@ describe('simulationService', () => {
const forkId = 'forkId'
const simulationId = 'simulationId'

const forkProvider = createPublicClient({
chain: PUBLIC_ALL_CHAINS.find((x) => x.id === CHAIN_ID.ETHEREUM),
transport: http(`https://rpc.tenderly.co/fork/${forkId}`),
})
const forkProvider = createTestClient({
chain: foundry,
mode: 'anvil',
transport: http(`https://rpc.tenderly.co/fork/forkId`),
}).extend(publicActions)

vi.mocked(forkProvider.getBalance).mockResolvedValueOnce(parseEther('105')) // mock tenderly_addBalance
vi.mocked(axios.post).mockResolvedValueOnce({
Expand Down Expand Up @@ -242,10 +252,11 @@ describe('simulationService', () => {
const forkId = 'forkId'
const simulationId = 'simulationId'

const forkProvider = createPublicClient({
chain: PUBLIC_ALL_CHAINS.find((x) => x.id === CHAIN_ID.ETHEREUM),
transport: http(`https://rpc.tenderly.co/fork/${forkId}`),
})
const forkProvider = createTestClient({
chain: foundry,
mode: 'anvil',
transport: http(`https://rpc.tenderly.co/fork/forkId`),
}).extend(publicActions)

vi.mocked(forkProvider.getBalance).mockResolvedValueOnce(parseEther('105')) // mock tenderly_addBalance
vi.mocked(axios.post).mockResolvedValueOnce({
Expand Down

0 comments on commit e5457d2

Please sign in to comment.