From e5457d25ad31ee1a66f3ef6e7354e284ce06705d Mon Sep 17 00:00:00 2001 From: neokry Date: Tue, 5 Sep 2023 09:57:03 +0900 Subject: [PATCH] wip fix tests --- .../SuccessfulProposalActions.test.tsx | 2 + apps/web/src/services/abiService.test.ts | 8 +-- .../src/services/simulationService.test.ts | 55 +++++++++++-------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/apps/web/src/modules/proposal/components/ProposalActions/SuccessfulProposalActions.test.tsx b/apps/web/src/modules/proposal/components/ProposalActions/SuccessfulProposalActions.test.tsx index dca5bd33..79e50b55 100644 --- a/apps/web/src/modules/proposal/components/ProposalActions/SuccessfulProposalActions.test.tsx +++ b/apps/web/src/modules/proposal/components/ProposalActions/SuccessfulProposalActions.test.tsx @@ -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) diff --git a/apps/web/src/services/abiService.test.ts b/apps/web/src/services/abiService.test.ts index 93cef5f7..cd44d84a 100644 --- a/apps/web/src/services/abiService.test.ts +++ b/apps/web/src/services/abiService.test.ts @@ -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 () => { diff --git a/apps/web/src/services/simulationService.test.ts b/apps/web/src/services/simulationService.test.ts index fafb83e2..76d2dd64 100644 --- a/apps/web/src/services/simulationService.test.ts +++ b/apps/web/src/services/simulationService.test.ts @@ -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' @@ -20,11 +27,11 @@ vi.mock('axios', () => { } }) -vi.mock('viem', () => { +vi.mock('viem', async () => { + const actual = await vi.importActual('viem') return { - default: { - createPublicClient: vi.fn(), - }, + ...actual, + createPublicClient: vi.fn(), } }) @@ -37,7 +44,7 @@ describe('simulationService', () => { const treasuryAddress: Address = '0xbcdfd67cce7bf4f49c0631ddd14eadff4d5ca15d' const request = { treasuryAddress, - chainId: CHAIN_ID.ETHEREUM, + chainId: CHAIN_ID.FOUNDRY, targets: [ '0x7d8ba3e0745079b292f68e421d292c05da2d0721', '0xa7c8f84ec8cbed6e8fb793904cd1ec9ddfc9c35d', @@ -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'], @@ -77,7 +84,7 @@ describe('simulationService', () => { expect(() => simulate({ treasuryAddress, - chainId: CHAIN_ID.ETHEREUM, + chainId: CHAIN_ID.FOUNDRY, targets: ['t1'], calldatas: ['c1'], values: ['v1, v2'], @@ -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'], @@ -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, @@ -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({ @@ -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({