Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { render, screen } from '@/tests/test-utils'
import AppFrame from '@/components/safe-apps/AppFrame'
import { initialState as initialSettingsState } from '@/store/settingsSlice'
import { TokenType } from '@safe-global/safe-gateway-typescript-sdk'

jest.mock('@/hooks/useChainId', () => jest.fn(() => '1'))

Expand Down Expand Up @@ -161,7 +162,7 @@ describe('AppFrame appearance', () => {
data: [
{
tokenInfo: {
type: 'NATIVE_TOKEN',
type: TokenType.NATIVE_TOKEN,
address: '0x0000000000000000000000000000000000000000',
decimals: 18,
symbol: 'ETH',
Expand Down
3 changes: 2 additions & 1 deletion src/components/settings/DataManagement/ImportDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAppDispatch } from '@/store'
import { useGlobalImportJsonParser } from '@/components/settings/DataManagement/useGlobalImportFileParser'
import { setCustomChains } from '@/store/customChainsSlice'
import { ImportDialog } from '@/components/settings/DataManagement/ImportDialog'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'

jest.mock('@/store', () => ({
useAppDispatch: jest.fn(),
Expand Down Expand Up @@ -38,7 +39,7 @@ describe('ImportDialog', () => {
chainName: 'Base Sepolia',
shortName: 'base-sepolia',
custom: true,
},
} as unknown as ChainInfo,
]

mockUseAppDispatch.mockReturnValue(dispatchMock)
Expand Down
8 changes: 5 additions & 3 deletions src/components/transactions/SingleTx/SingleTx.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import SingleTx from '@/pages/transactions/tx'
import * as extractTxInfo from '@/services/tx/extractTxInfo'
import * as useSafeInfo from '@/hooks/useSafeInfo'
import * as addedTxsSlice from '@/store/addedTxsSlice'
import type { SafeInfo, TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk'
import type { SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { OperationType, type SafeTransaction } from '@safe-global/safe-core-sdk-types'
import EthSafeTransaction from '@safe-global/protocol-kit/dist/src/utils/transactions/SafeTransaction'
import type { EternalSafeTransaction } from '@/store/addedTxsSlice'
import type { TransactionDetails } from '@/utils/transaction-guards'

const SAFE_ADDRESS = '0x87a57cBf742CC1Fc702D0E9BF595b1E056693e2f'

Expand All @@ -19,7 +21,7 @@ const txDetails = {
value: '0xc778417E063141139Fce010982780140Aa0cD5Ab',
},
},
} as TransactionDetails
} as unknown as TransactionDetails

jest.mock('next/router', () => ({
useRouter() {
Expand Down Expand Up @@ -47,7 +49,7 @@ jest
value: '1000000000000000000',
to: '0x1234567890123456789012345678901234567890',
operation: OperationType.Call,
})
}) as unknown as EternalSafeTransaction
})

jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const buildTxDetails = (value: string): TransactionDetails =>
value,
hexData: '0x',
},
} as TransactionDetails)
} as unknown as TransactionDetails)

describe('Summary', () => {
it('shows formatted transaction value in advanced details', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/transactions/TxSigners/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const txSummary = {
confirmationsSubmitted: 1,
missingSigners: [],
},
} as TransactionSummary
} as unknown as TransactionSummary

const txDetails = {
txId: TX_ID,
Expand Down Expand Up @@ -60,11 +60,11 @@ const txDetails = {
signers: [],
trusted: true,
},
} as TransactionDetails
} as unknown as TransactionDetails

describe('TxSigners', () => {
beforeEach(() => {
jest.spyOn(useWallet, 'default').mockReturnValue(undefined)
jest.spyOn(useWallet, 'default').mockReturnValue(null)
jest.spyOn(useIsPending, 'default').mockReturnValue(false)
jest.spyOn(useTransactionStatus, 'default').mockReturnValue('Success')
jest.spyOn(useSafeInfo, 'default').mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const ReviewSignMessageOnChain = ({ message, method, requestId }: SignMessageOnC
setSafeTx,
setSafeTxError,
signMessageAddress,
readOnlySignMessageLibContract,
])

const handleSubmit = async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/tx/DecodedTx/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('DecodedTx', () => {
nonce: 58,
safeTxGas: 0,
},
} as SafeTransaction
} as unknown as SafeTransaction
}
decodedData={{
method: 'Native token transfer',
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('DecodedTx', () => {
nonce: 58,
safeTxGas: 0,
},
} as SafeTransaction
} as unknown as SafeTransaction
}
decodedData={{
method: 'transfer',
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('DecodedTx', () => {
nonce: 58,
safeTxGas: 0,
},
} as SafeTransaction
} as unknown as SafeTransaction
}
decodedData={{
method: 'multiSend',
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('DecodedTx', () => {
nonce: 58,
safeTxGas: 0,
},
} as SafeTransaction
} as unknown as SafeTransaction
}
decodedData={{
method: 'deposit',
Expand Down
73 changes: 33 additions & 40 deletions src/hooks/__tests__/useBalances.test.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,63 @@
import { type SafeBalanceResponse, TokenType } from '@safe-global/safe-gateway-typescript-sdk'
import { TokenType } from '@safe-global/safe-gateway-typescript-sdk'
import type { TokenItem } from '@/hooks/loadables/useLoadBalances'
import * as store from '@/store'
import { renderHook } from '@/tests/test-utils'
import useBalances from '../useBalances'
import { hexZeroPad } from 'ethers/lib/utils'

describe('useBalances', () => {
test('empty balance', () => {
const balance: SafeBalanceResponse = {
fiatTotal: '0',
items: [],
}
const balance: TokenItem[] = []
jest.spyOn(store, 'useAppSelector').mockImplementation((selector) =>
selector({
balances: { data: balance, error: undefined, loading: false },
} as store.RootState),
} as unknown as store.RootState),
)

const { result } = renderHook(() => useBalances())

expect(result.current.balances.fiatTotal).toEqual('0')
expect(result.current.balances.items).toHaveLength(0)
expect(result.current.balances).toHaveLength(0)
})

test('return all balances', () => {
const tokenAddress = hexZeroPad('0x2', 20)
const balance: SafeBalanceResponse = {
fiatTotal: '100',
items: [
{
balance: '40',
fiatBalance: '40',
fiatConversion: '1',
tokenInfo: {
address: tokenAddress,
decimals: 18,
logoUri: '',
name: 'Hidden Token',
symbol: 'HT',
type: TokenType.ERC20,
},
const balance: TokenItem[] = [
{
balance: '40',
fiatBalance: '40',
fiatConversion: '1',
tokenInfo: {
address: tokenAddress,
decimals: 18,
logoUri: '',
name: 'Hidden Token',
symbol: 'HT',
type: TokenType.ERC20,
},
{
balance: '60',
fiatBalance: '60',
fiatConversion: '1',
tokenInfo: {
address: tokenAddress,
decimals: 18,
logoUri: '',
name: 'Visible Token',
symbol: 'VT',
type: TokenType.ERC20,
},
},
{
balance: '60',
fiatBalance: '60',
fiatConversion: '1',
tokenInfo: {
address: tokenAddress,
decimals: 18,
logoUri: '',
name: 'Visible Token',
symbol: 'VT',
type: TokenType.ERC20,
},
],
}
},
]

jest.spyOn(store, 'useAppSelector').mockImplementation((selector) =>
selector({
balances: { data: balance, error: undefined, loading: false },
} as store.RootState),
} as unknown as store.RootState),
)

const { result } = renderHook(() => useBalances())

expect(result.current.balances.fiatTotal).toEqual('100')
expect(result.current.balances.items).toHaveLength(2)
expect(result.current.balances).toHaveLength(2)
})
})
19 changes: 17 additions & 2 deletions src/hooks/__tests__/useBatchedTxs.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
type MultisigExecutionInfo,
type Transaction,
type TransactionDetails,
TransactionInfoType,
type TransactionListItem,
TransactionStatus,
DetailedExecutionInfoType,
} from '@safe-global/safe-gateway-typescript-sdk'
import { ConflictType, TransactionListItemType } from '@safe-global/safe-gateway-typescript-sdk'
import { getBatchableTransactions } from '@/hooks/useBatchedTxs'
import { defaultTx, getMockTx } from '@/tests/mocks/transactions'
import type { DetailedTransaction } from '@/utils/transaction-guards'
import type { DetailedTransaction, TransactionDetails } from '@/utils/transaction-guards'
import { addressEx } from '@/utils/addresses'

const mockTxDetails: TransactionDetails = {
Expand All @@ -23,6 +23,21 @@ const mockTxDetails: TransactionDetails = {
value: '0',
isCancellation: false,
},
detailedExecutionInfo: {
type: DetailedExecutionInfoType.MULTISIG,
nonce: 0,
confirmationsRequired: 1,
confirmations: [],
safeTxHash: '0x',
baseGas: '0',
gasPrice: '0',
gasToken: '0x0000000000000000000000000000000000000000',
refundReceiver: addressEx('0x'),
safeTxGas: '0',
submittedAt: 0,
signers: [],
trusted: true,
},
}

describe('getBatchableTransactions', () => {
Expand Down
8 changes: 2 additions & 6 deletions src/hooks/__tests__/usePendingActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ describe('usePendingActions hook', () => {
const mockPage = {
error: undefined,
loading: false,
page: {
next: undefined,
previous: undefined,
results: [],
},
data: [],
}
jest.spyOn(useTxQueue, 'default').mockReturnValue(mockPage)

Expand Down Expand Up @@ -96,7 +92,7 @@ describe('usePendingActions hook', () => {
const mockPage = {
error: undefined,
loading: false,
data: page,
data: page as ReturnType<typeof useTxQueue.default>['data'],
}
jest.spyOn(useTxQueue, 'default').mockReturnValue(mockPage)

Expand Down
7 changes: 4 additions & 3 deletions src/hooks/coreSDK/__tests__/useInitSafeCoreSDK.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { waitFor } from '@testing-library/react'
import type Safe from '@safe-global/protocol-kit'
import { ethers } from 'ethers'
import type { MulticallProvider } from 'ethers-multicall-provider'
import type { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'

describe('useInitSafeCoreSDK hook', () => {
const mockSafeAddress = '0x0000000000000000000000000000000000005AFE'
const mockChainId = '5'
const mockImplementation = '0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552'

let mockProvider: MulticallProvider
let mockProvider: MulticallProvider<JsonRpcProvider | Web3Provider>

beforeEach(() => {
jest.clearAllMocks()
Expand All @@ -28,7 +29,7 @@ describe('useInitSafeCoreSDK hook', () => {
getStorageAt: jest.fn().mockResolvedValue(ethers.utils.hexZeroPad(mockImplementation, 32)),
getCode: jest.fn().mockResolvedValue('0x01'),
}
})() as unknown as MulticallProvider
})() as unknown as MulticallProvider<JsonRpcProvider | Web3Provider>

jest.spyOn(web3, 'useMultiWeb3ReadOnly').mockReturnValue(mockProvider)
jest.spyOn(useSafeAddress, 'default').mockReturnValue(mockSafeAddress)
Expand Down Expand Up @@ -117,7 +118,7 @@ describe('useInitSafeCoreSDK hook', () => {
threshold: 1,
multisendAddress: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
multisendCallOnlyAddress: '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
},
} as any,
},
},
},
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/wallets/__tests__/useOnboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('useOnboard', () => {
ens: {
name: 'test.eth',
},
uns: null,
balance: {
ETH: '0.002346456767547',
},
Expand All @@ -38,11 +39,12 @@ describe('useOnboard', () => {
{
address: '0x2',
ens: null,
uns: null,
balance: null,
},
],
},
] as WalletState[]
] as unknown as WalletState[]

expect(getConnectedWallet(wallets)).toEqual({
label: 'Wallet 1',
Expand All @@ -66,11 +68,12 @@ describe('useOnboard', () => {
{
address: '0xinvalid',
ens: null,
uns: null,
balance: null,
},
],
},
] as WalletState[]
] as unknown as WalletState[]

expect(getConnectedWallet(wallets)).toBeNull()
})
Expand Down
3 changes: 2 additions & 1 deletion src/services/safe-messages/__tests__/safeMsgSender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ const mockOnboardState = {
{
address: '0x1234567890123456789012345678901234567890',
ens: null,
uns: null,
balance: null,
},
],
},
] as WalletState[],
] as unknown as WalletState[],
accountCenter: {
enabled: true,
},
Expand Down
Loading
Loading