Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Fix: rename getMinMax to getZrxMinMax; rename getSendMaxAmount to get…
Browse files Browse the repository at this point in the history
…ZrxSendMaxAmount
  • Loading branch information
DaoDev44 committed Nov 23, 2021
1 parent c330a6a commit 2ca7be0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
20 changes: 10 additions & 10 deletions packages/swapper/src/swappers/zrx/ZrxSwapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { ZrxBuildQuoteTx } from '../zrx/ZrxBuildQuoteTx/ZrxBuildQuoteTx'
import { ZrxExecuteQuote } from './ZrxExecuteQuote/ZrxExecuteQuote'
import { ZrxApprovalNeeded } from './ZrxApprovalNeeded/ZrxApprovalNeeded'
import { ZrxApproveInfinite } from './ZrxApproveInfinite/ZrxApproveInfinite'
import { getMinMax } from './getMinMax/getMinMax'
import { getZrxMinMax } from './getZrxMinMax/getZrxMinMax'
import { getZrxQuote } from './getZrxQuote/getZrxQuote'
import { getSendMaxAmount } from './getSendMaxAmount/getSendMaxAmount'
import { getZrxSendMaxAmount } from './getZrxSendMaxAmount/getZrxSendMaxAmount'
import { getUsdRate } from './utils/helpers/helpers'
import { BTC, FOX, WETH } from './utils/test-data/assets'
import { setupQuote } from './utils/test-data/setupSwapQuote'
Expand All @@ -29,8 +29,8 @@ jest.mock('./getZrxQuote/getZrxQuote', () => ({
getZrxQuote: jest.fn()
}))

jest.mock('./getMinMax/getMinMax', () => ({
getMinMax: jest.fn()
jest.mock('./getZrxMinMax/getZrxMinMax', () => ({
getZrxMinMax: jest.fn()
}))

jest.mock('./ZrxApprovalNeeded/ZrxApprovalNeeded', () => ({
Expand All @@ -41,8 +41,8 @@ jest.mock('./ZrxApproveInfinite/ZrxApproveInfinite', () => ({
ZrxApproveInfinite: jest.fn()
}))

jest.mock('./getSendMaxAmount/getSendMaxAmount', () => ({
getSendMaxAmount: jest.fn()
jest.mock('./getZrxSendMaxAmount/getZrxSendMaxAmount', () => ({
getZrxSendMaxAmount: jest.fn()
}))

describe('ZrxSwapper', () => {
Expand Down Expand Up @@ -109,11 +109,11 @@ describe('ZrxSwapper', () => {
await swapper.getUsdRate(FOX)
expect(getUsdRate).toHaveBeenCalled()
})
it('calls getMinMax on swapper.getMinMax', async () => {
it('calls getZrxMinMax on swapper.getMinMax', async () => {
const swapper = new ZrxSwapper(zrxSwapperDeps)
const { quoteInput } = setupQuote()
await swapper.getMinMax(quoteInput)
expect(getMinMax).toHaveBeenCalled()
expect(getZrxMinMax).toHaveBeenCalled()
})

it('calls ZrxApprovalNeeded on swapper.approvalNeeded', async () => {
Expand All @@ -131,7 +131,7 @@ describe('ZrxSwapper', () => {
expect(ZrxApproveInfinite).toHaveBeenCalled()
})

it('calls getSendMaxAmount on swapper.getSendMaxAmount', async () => {
it('calls getZrxSendMaxAmount on swapper.getSendMaxAmount', async () => {
const swapper = new ZrxSwapper(zrxSwapperDeps)
const args = {
quote,
Expand All @@ -140,6 +140,6 @@ describe('ZrxSwapper', () => {
feeEstimateKey: chainAdapters.FeeDataKey.Average
}
await swapper.getSendMaxAmount(args)
expect(getSendMaxAmount).toHaveBeenCalled()
expect(getZrxSendMaxAmount).toHaveBeenCalled()
})
})
8 changes: 4 additions & 4 deletions packages/swapper/src/swappers/zrx/ZrxSwapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { ZrxApprovalNeeded } from './ZrxApprovalNeeded/ZrxApprovalNeeded'
import { ZrxApproveInfinite } from './ZrxApproveInfinite/ZrxApproveInfinite'
import { ZrxBuildQuoteTx } from './ZrxBuildQuoteTx/ZrxBuildQuoteTx'
import { ZrxExecuteQuote } from './ZrxExecuteQuote/ZrxExecuteQuote'
import { getMinMax } from './getMinMax/getMinMax'
import { getZrxMinMax } from './getZrxMinMax/getZrxMinMax'
import { getZrxQuote } from './getZrxQuote/getZrxQuote'
import { getSendMaxAmount } from './getSendMaxAmount/getSendMaxAmount'
import { getZrxSendMaxAmount } from './getZrxSendMaxAmount/getZrxSendMaxAmount'
import { getUsdRate } from './utils/helpers/helpers'
export type ZrxSwapperDeps = {
adapterManager: ChainAdapterManager
Expand Down Expand Up @@ -62,7 +62,7 @@ export class ZrxSwapper implements Swapper {
}

async getMinMax(input: GetQuoteInput): Promise<MinMaxOutput> {
return getMinMax(input)
return getZrxMinMax(input)
}

getAvailableAssets(assets: Asset[]): Asset[] {
Expand Down Expand Up @@ -95,6 +95,6 @@ export class ZrxSwapper implements Swapper {
}

async getSendMaxAmount(args: SendMaxAmountInput): Promise<string> {
return getSendMaxAmount(this.deps, args)
return getZrxSendMaxAmount(this.deps, args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jest.mock('../utils/helpers/helpers')
import { MAX_ZRX_TRADE } from '../utils/constants'
import { BTC, FOX, WETH } from '../utils/test-data/assets'
import { zrxService as mockZrxService } from '../utils/zrxService'
import { getMinMax } from './getMinMax'
import { getZrxMinMax } from './getZrxMinMax'
;(<jest.Mock<unknown>>mockZrxService.get).mockImplementation(() => ({
data: { price: '100' }
}))
Expand All @@ -13,16 +13,16 @@ jest.mock('../utils/helpers/helpers', () => ({
normalizeAmount: () => '1'
}))

describe('getMinMax', () => {
describe('getZrxMinMax', () => {
it('returns minimum, maximum, and minimumPrice', async () => {
const minMax = await getMinMax({ sellAsset: FOX, buyAsset: WETH })
const minMax = await getZrxMinMax({ sellAsset: FOX, buyAsset: WETH })
expect(minMax.minimum).toBe('1')
expect(minMax.maximum).toBe(MAX_ZRX_TRADE)
expect(minMax.minimumPrice).toBe('100')
})
it('fails on non eth asset', async () => {
await expect(getMinMax({ sellAsset: BTC, buyAsset: WETH })).rejects.toThrow(
'ZrxError:getMinMax - must be eth assets'
await expect(getZrxMinMax({ sellAsset: BTC, buyAsset: WETH })).rejects.toThrow(
'ZrxError:getZrxMinMax - must be eth assets'
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { getUsdRate, normalizeAmount } from '../utils/helpers/helpers'
import { zrxService } from '../utils/zrxService'
import { ZrxError } from '../ZrxSwapper'

export const getMinMax = async (
export const getZrxMinMax = async (
input: Pick<GetQuoteInput, 'sellAsset' | 'buyAsset'>
): Promise<MinMaxOutput> => {
const { sellAsset, buyAsset } = input

if (sellAsset.chain !== ChainTypes.Ethereum || buyAsset.chain !== ChainTypes.Ethereum) {
throw new ZrxError('getMinMax - must be eth assets')
throw new ZrxError('getZrxMinMax - must be eth assets')
}
const buyToken = buyAsset.tokenId || buyAsset.symbol
const sellToken = sellAsset.tokenId || sellAsset.symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import BigNumber from 'bignumber.js'
import { ETH_FEE_ESTIMATE_PADDING } from '../utils/constants'
import { setupQuote } from '../utils/test-data/setupSwapQuote'
import { chainAdapterMockFuncs, setupZrxDeps } from '../utils/test-data/setupZrxDeps'
import { getSendMaxAmount } from './getSendMaxAmount'
import { getZrxSendMaxAmount } from './getZrxSendMaxAmount'

const createPaddedFee = (value: string) => {
return new BigNumber(value).times(ETH_FEE_ESTIMATE_PADDING).toString()
}

describe('getSendMaxAmount', () => {
describe('getZrxSendMaxAmount', () => {
const { web3Instance, adapterManager } = setupZrxDeps()
const { quoteInput: quote } = setupQuote()
const deps = { web3: web3Instance, adapterManager }
Expand All @@ -34,7 +34,7 @@ describe('getSendMaxAmount', () => {
})
})

await expect(getSendMaxAmount(deps, args)).rejects.toThrow(
await expect(getZrxSendMaxAmount(deps, args)).rejects.toThrow(
`No balance found for ${quote.sellAsset.symbol}`
)
})
Expand All @@ -52,7 +52,7 @@ describe('getSendMaxAmount', () => {
})
})

await expect(getSendMaxAmount(deps, args)).rejects.toThrow(`No balance found for ETH`)
await expect(getZrxSendMaxAmount(deps, args)).rejects.toThrow(`No balance found for ETH`)
})

it('should throw an error if ETH balance is less than the estimated fee', async () => {
Expand All @@ -73,7 +73,7 @@ describe('getSendMaxAmount', () => {
})
})

await expect(getSendMaxAmount(deps, args)).rejects.toThrow(
await expect(getZrxSendMaxAmount(deps, args)).rejects.toThrow(
'ETH balance is less than estimated fee'
)
})
Expand All @@ -96,7 +96,7 @@ describe('getSendMaxAmount', () => {
})
})

await expect(getSendMaxAmount(deps, args)).rejects.toThrow(
await expect(getZrxSendMaxAmount(deps, args)).rejects.toThrow(
'quote.txData is required to get correct fee estimate'
)
})
Expand All @@ -115,7 +115,7 @@ describe('getSendMaxAmount', () => {
})
})

expect(await getSendMaxAmount(deps, args)).toEqual(erc20Balance)
expect(await getZrxSendMaxAmount(deps, args)).toEqual(erc20Balance)
})

it('should return max ETH balance in wei (balance minus txFee)', async () => {
Expand All @@ -137,7 +137,7 @@ describe('getSendMaxAmount', () => {
})
})

expect(await getSendMaxAmount(deps, args)).toEqual(
expect(await getZrxSendMaxAmount(deps, args)).toEqual(
new BigNumber(ethBalance).minus(paddedFee).toString()
)
})
Expand All @@ -162,7 +162,7 @@ describe('getSendMaxAmount', () => {
})
})

expect(await getSendMaxAmount(deps, args)).toEqual(
expect(await getZrxSendMaxAmount(deps, args)).toEqual(
new BigNumber(ethBalance).minus(paddedFee).toString()
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { bnOrZero } from '../utils/bignumber'
import { ETH_FEE_ESTIMATE_PADDING } from '../utils/constants'
import { ZrxSwapperDeps } from '../ZrxSwapper'

export async function getSendMaxAmount(
export async function getZrxSendMaxAmount(
{ adapterManager }: ZrxSwapperDeps,
{
wallet,
Expand Down

0 comments on commit 2ca7be0

Please sign in to comment.