Skip to content

Commit

Permalink
fix: many tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Feb 19, 2024
1 parent e0e9d61 commit f2820ca
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
2 changes: 0 additions & 2 deletions __mocks__/ethers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import ethers from 'ethers'
import { vi } from 'vitest'

const ethersMock = {
...ethers,
JsonRpcProvider: vi.fn(),
Contract: vi.fn().mockImplementation(address => ({
decimals: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ethAssetId, ethChainId } from '@shapeshiftoss/caip'
import type { evm } from '@shapeshiftoss/common-api'
import type ethers from 'ethers'
import { beforeAll, describe, expect, it, vi } from 'vitest'

import type { Trade } from '../../../../types'
Expand Down Expand Up @@ -86,6 +87,98 @@ import zrxTradeEthToMatic from './mockData/zrxTradeEthToMatic'
import zrxTradeTetherToKishu from './mockData/zrxTradeTetherToKishu'
import zrxTradeTribeToEth from './mockData/zrxTradeTribeToEth'

vi.mock('ethers', async importActual => {
const actual: typeof ethers = await importActual()
return {
...actual,
Contract: vi.fn().mockImplementation(address => ({
decimals: () => {
switch (address as string) {
case '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48':
return 6
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 18
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 18
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 18
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
name: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'Uniswap V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'Wrapped Ether'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
symbol: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'UNI-V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'WETH'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
})),

JsonRpcProvider: vi.fn(),
default: {
...actual,
Contract: vi.fn().mockImplementation(address => ({
decimals: () => {
switch (address as string) {
case '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48':
return 6
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 18
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 18
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 18
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
name: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'Uniswap V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'Wrapped Ether'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
symbol: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'UNI-V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'WETH'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
})),
},
}
})

const mocks = vi.hoisted(() => {
const tokenMetadata: evm.TokenMetadata = {
name: 'Foxy',
Expand Down
4 changes: 3 additions & 1 deletion packages/unchained-client/src/evm/parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AssetId, ChainId } from '@shapeshiftoss/caip'
import { ASSET_NAMESPACE, ASSET_REFERENCE, ethChainId, toAssetId } from '@shapeshiftoss/caip'
import { BigNumber } from 'bignumber.js'
import { getAddress, JsonRpcProvider } from 'ethers'
import ethers, { getAddress, JsonRpcProvider } from 'ethers'

import type { Token, TxStatus } from '../../types'
import { TransferType } from '../../types'
Expand All @@ -11,6 +11,8 @@ import type { Api } from '..'
import type { ParsedTx, SubParser, Tx, TxSpecific } from './types'
import { getTxStatus } from './utils'

console.log({ ethers, JsonRpcProvider })

export * from './types'
export * from './utils'

Expand Down

0 comments on commit f2820ca

Please sign in to comment.