Commit 01a3aa1c authored by lynn's avatar lynn Committed by GitHub

chore: add constants for testing (#6367)

* init

* use constants

* change address

* move noop

* add eslint rule

* return null in noop

* fixes
parent 7121b4aa
import { fireEvent, render, screen } from 'test-utils/render' import { fireEvent, render, screen } from 'test-utils/render'
import noop from 'utils/noop'
import { ResizingTextArea, TextInput } from './' import { ResizingTextArea, TextInput } from './'
...@@ -8,7 +9,7 @@ describe('TextInput', () => { ...@@ -8,7 +9,7 @@ describe('TextInput', () => {
<TextInput <TextInput
className="testing" className="testing"
value="My test input" value="My test input"
onUserInput={() => null} onUserInput={noop}
placeholder="Test Placeholder" placeholder="Test Placeholder"
fontSize="12" fontSize="12"
/> />
...@@ -41,7 +42,7 @@ describe('ResizableTextArea', () => { ...@@ -41,7 +42,7 @@ describe('ResizableTextArea', () => {
<ResizingTextArea <ResizingTextArea
className="testing" className="testing"
value="My test input" value="My test input"
onUserInput={() => null} onUserInput={noop}
placeholder="Test Placeholder" placeholder="Test Placeholder"
fontSize="12" fontSize="12"
/> />
......
import { transparentize } from 'polished' import { transparentize } from 'polished'
import { ReactNode, useEffect, useState } from 'react' import { ReactNode, useEffect, useState } from 'react'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import noop from 'utils/noop'
import Popover, { PopoverProps } from '../Popover' import Popover, { PopoverProps } from '../Popover'
// TODO(WEB-3163): migrate noops throughout web to a shared util file.
const noop = () => null
export const TooltipContainer = styled.div` export const TooltipContainer = styled.div`
max-width: 256px; max-width: 256px;
cursor: default; cursor: default;
......
import noop from 'utils/noop'
import { Box } from '../Box' import { Box } from '../Box'
import * as styles from './Overlay.css' import * as styles from './Overlay.css'
...@@ -10,6 +12,6 @@ export const stopPropagation = (event: React.SyntheticEvent<HTMLElement>) => { ...@@ -10,6 +12,6 @@ export const stopPropagation = (event: React.SyntheticEvent<HTMLElement>) => {
event.nativeEvent.stopImmediatePropagation() event.nativeEvent.stopImmediatePropagation()
} }
export const Overlay = ({ onClick = () => null }: OverlayProps) => { export const Overlay = ({ onClick = noop }: OverlayProps) => {
return <Box className={styles.overlay} onClick={onClick} /> return <Box className={styles.overlay} onClick={onClick} />
} }
...@@ -28,6 +28,7 @@ import InfiniteLoader from 'react-window-infinite-loader' ...@@ -28,6 +28,7 @@ import InfiniteLoader from 'react-window-infinite-loader'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { ThemedText } from 'theme' import { ThemedText } from 'theme'
import { TRANSITION_DURATIONS } from 'theme/styles' import { TRANSITION_DURATIONS } from 'theme/styles'
import noop from 'utils/noop'
import { WALLET_COLLECTIONS_PAGINATION_LIMIT } from './ProfilePage' import { WALLET_COLLECTIONS_PAGINATION_LIMIT } from './ProfilePage'
import * as styles from './ProfilePage.css' import * as styles from './ProfilePage.css'
...@@ -190,7 +191,7 @@ const CollectionSelect = ({ ...@@ -190,7 +191,7 @@ const CollectionSelect = ({
// Only load 1 page of items at a time. // Only load 1 page of items at a time.
// Pass an empty callback to InfiniteLoader in case it asks us to load more than once. // Pass an empty callback to InfiniteLoader in case it asks us to load more than once.
const loadMoreItems = isFetchingNextPage ? () => null : fetchNextPage const loadMoreItems = isFetchingNextPage ? noop : fetchNextPage
// Every row is loaded except for our loading indicator row. // Every row is loaded except for our loading indicator row.
const isItemLoaded = useCallback( const isItemLoaded = useCallback(
......
import * as Sentry from '@sentry/react' import * as Sentry from '@sentry/react'
import noop from 'utils/noop'
import { AppState } from './types' import { AppState } from './types'
...@@ -17,7 +18,7 @@ export const sentryEnhancer = Sentry.createReduxEnhancer({ ...@@ -17,7 +18,7 @@ export const sentryEnhancer = Sentry.createReduxEnhancer({
/** /**
* We don't want to store actions as breadcrumbs in Sentry, so we return null to disable the default behavior. * We don't want to store actions as breadcrumbs in Sentry, so we return null to disable the default behavior.
*/ */
actionTransformer: () => null, actionTransformer: noop,
/** /**
* We only want to store a subset of the state in Sentry, containing only the relevant parts for debugging. * We only want to store a subset of the state in Sentry, containing only the relevant parts for debugging.
* Note: This function runs on every state update, so we're keeping it as fast as possible by avoiding any function * Note: This function runs on every state update, so we're keeping it as fast as possible by avoiding any function
......
import { parse } from 'qs' import { parse } from 'qs'
import { TEST_RECIPIENT_ADDRESS } from 'test-utils/constants'
import { Field } from './actions' import { Field } from './actions'
import { queryParametersToSwapState } from './hooks' import { queryParametersToSwapState } from './hooks'
...@@ -65,7 +66,7 @@ describe('hooks', () => { ...@@ -65,7 +66,7 @@ describe('hooks', () => {
test('valid recipient', () => { test('valid recipient', () => {
expect( expect(
queryParametersToSwapState( queryParametersToSwapState(
parse('?outputCurrency=eth&exactAmount=20.5&recipient=0x0fF2D1eFd7A57B7562b2bf27F3f37899dB27F4a5', { parse(`?outputCurrency=eth&exactAmount=20.5&recipient=${TEST_RECIPIENT_ADDRESS}`, {
parseArrays: false, parseArrays: false,
ignoreQueryPrefix: true, ignoreQueryPrefix: true,
}) })
...@@ -75,7 +76,7 @@ describe('hooks', () => { ...@@ -75,7 +76,7 @@ describe('hooks', () => {
[Field.INPUT]: { currencyId: null }, [Field.INPUT]: { currencyId: null },
typedValue: '20.5', typedValue: '20.5',
independentField: Field.INPUT, independentField: Field.INPUT,
recipient: '0x0fF2D1eFd7A57B7562b2bf27F3f37899dB27F4a5', recipient: TEST_RECIPIENT_ADDRESS,
}) })
}) })
test('accepts any recipient', () => { test('accepts any recipient', () => {
......
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { FeeAmount, Pool } from '@uniswap/v3-sdk'
import JSBI from 'jsbi'
export const TEST_TOKEN_1 = new Token(1, '0x0000000000000000000000000000000000000001', 18, 'ABC', 'Abc')
export const TEST_TOKEN_2 = new Token(1, '0x0000000000000000000000000000000000000002', 18, 'DEF', 'Def')
export const TEST_TOKEN_3 = new Token(1, '0x0000000000000000000000000000000000000003', 18, 'GHI', 'Ghi')
export const TEST_RECIPIENT_ADDRESS = '0x0000000000000000000000000000000000000004'
export const TEST_POOL_12 = new Pool(
TEST_TOKEN_1,
TEST_TOKEN_2,
FeeAmount.HIGH,
'2437312313659959819381354528',
'10272714736694327408',
-69633
)
export const TEST_POOL_13 = new Pool(
TEST_TOKEN_1,
TEST_TOKEN_3,
FeeAmount.MEDIUM,
'2437312313659959819381354528',
'10272714736694327408',
-69633
)
export const toCurrencyAmount = (token: Token, amount: number) =>
CurrencyAmount.fromRawAmount(token, JSBI.BigInt(amount))
/** No-op function. Returns `null` to satisfy most React typings. */
export default function noop() {
return null
}
import { Trade } from '@uniswap/router-sdk' import { Trade } from '@uniswap/router-sdk'
import { CurrencyAmount, Percent, Token, TradeType } from '@uniswap/sdk-core' import { CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core'
import { Pair, Route as V2Route } from '@uniswap/v2-sdk' import { Pair, Route as V2Route } from '@uniswap/v2-sdk'
import { FeeAmount, Pool, Route as V3Route } from '@uniswap/v3-sdk' import { Route as V3Route } from '@uniswap/v3-sdk'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import {
TEST_POOL_12,
TEST_POOL_13,
TEST_TOKEN_1,
TEST_TOKEN_2,
TEST_TOKEN_3,
toCurrencyAmount,
} from 'test-utils/constants'
import { computeRealizedLPFeeAmount, warningSeverity } from './prices' import { computeRealizedLPFeeAmount, warningSeverity } from './prices'
const token1 = new Token(1, '0x0000000000000000000000000000000000000001', 18)
const token2 = new Token(1, '0x0000000000000000000000000000000000000002', 18)
const token3 = new Token(1, '0x0000000000000000000000000000000000000003', 18)
const pair12 = new Pair( const pair12 = new Pair(
CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(10000)), CurrencyAmount.fromRawAmount(TEST_TOKEN_1, JSBI.BigInt(10000)),
CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(20000)) CurrencyAmount.fromRawAmount(TEST_TOKEN_2, JSBI.BigInt(20000))
) )
const pair23 = new Pair( const pair23 = new Pair(
CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(20000)), CurrencyAmount.fromRawAmount(TEST_TOKEN_2, JSBI.BigInt(20000)),
CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(30000)) CurrencyAmount.fromRawAmount(TEST_TOKEN_3, JSBI.BigInt(30000))
)
const pool12 = new Pool(token1, token2, FeeAmount.HIGH, '2437312313659959819381354528', '10272714736694327408', -69633)
const pool13 = new Pool(
token1,
token3,
FeeAmount.MEDIUM,
'2437312313659959819381354528',
'10272714736694327408',
-69633
) )
const currencyAmount = (token: Token, amount: number) => CurrencyAmount.fromRawAmount(token, JSBI.BigInt(amount))
describe('prices', () => { describe('prices', () => {
describe('#computeRealizedLPFeeAmount', () => { describe('#computeRealizedLPFeeAmount', () => {
it('returns undefined for undefined', () => { it('returns undefined for undefined', () => {
...@@ -44,16 +36,16 @@ describe('prices', () => { ...@@ -44,16 +36,16 @@ describe('prices', () => {
new Trade({ new Trade({
v2Routes: [ v2Routes: [
{ {
routev2: new V2Route([pair12], token1, token2), routev2: new V2Route([pair12], TEST_TOKEN_1, TEST_TOKEN_2),
inputAmount: currencyAmount(token1, 1000), inputAmount: toCurrencyAmount(TEST_TOKEN_1, 1000),
outputAmount: currencyAmount(token2, 1000), outputAmount: toCurrencyAmount(TEST_TOKEN_2, 1000),
}, },
], ],
v3Routes: [], v3Routes: [],
tradeType: TradeType.EXACT_INPUT, tradeType: TradeType.EXACT_INPUT,
}) })
) )
).toEqual(currencyAmount(token1, 3)) // 3% realized fee ).toEqual(toCurrencyAmount(TEST_TOKEN_1, 3)) // 3% realized fee
}) })
it('correct realized lp fee for single hop on v3', () => { it('correct realized lp fee for single hop on v3', () => {
...@@ -63,16 +55,16 @@ describe('prices', () => { ...@@ -63,16 +55,16 @@ describe('prices', () => {
new Trade({ new Trade({
v3Routes: [ v3Routes: [
{ {
routev3: new V3Route([pool12], token1, token2), routev3: new V3Route([TEST_POOL_12], TEST_TOKEN_1, TEST_TOKEN_2),
inputAmount: currencyAmount(token1, 1000), inputAmount: toCurrencyAmount(TEST_TOKEN_1, 1000),
outputAmount: currencyAmount(token2, 1000), outputAmount: toCurrencyAmount(TEST_TOKEN_2, 1000),
}, },
], ],
v2Routes: [], v2Routes: [],
tradeType: TradeType.EXACT_INPUT, tradeType: TradeType.EXACT_INPUT,
}) })
) )
).toEqual(currencyAmount(token1, 10)) // 3% realized fee ).toEqual(toCurrencyAmount(TEST_TOKEN_1, 10)) // 3% realized fee
}) })
it('correct realized lp fee for double hop', () => { it('correct realized lp fee for double hop', () => {
...@@ -81,16 +73,16 @@ describe('prices', () => { ...@@ -81,16 +73,16 @@ describe('prices', () => {
new Trade({ new Trade({
v2Routes: [ v2Routes: [
{ {
routev2: new V2Route([pair12, pair23], token1, token3), routev2: new V2Route([pair12, pair23], TEST_TOKEN_1, TEST_TOKEN_3),
inputAmount: currencyAmount(token1, 1000), inputAmount: toCurrencyAmount(TEST_TOKEN_1, 1000),
outputAmount: currencyAmount(token3, 1000), outputAmount: toCurrencyAmount(TEST_TOKEN_3, 1000),
}, },
], ],
v3Routes: [], v3Routes: [],
tradeType: TradeType.EXACT_INPUT, tradeType: TradeType.EXACT_INPUT,
}) })
) )
).toEqual(currencyAmount(token1, 5)) ).toEqual(toCurrencyAmount(TEST_TOKEN_1, 5))
}) })
it('correct realized lp fee for multi route v2+v3', () => { it('correct realized lp fee for multi route v2+v3', () => {
...@@ -99,22 +91,22 @@ describe('prices', () => { ...@@ -99,22 +91,22 @@ describe('prices', () => {
new Trade({ new Trade({
v2Routes: [ v2Routes: [
{ {
routev2: new V2Route([pair12, pair23], token1, token3), routev2: new V2Route([pair12, pair23], TEST_TOKEN_1, TEST_TOKEN_3),
inputAmount: currencyAmount(token1, 1000), inputAmount: toCurrencyAmount(TEST_TOKEN_1, 1000),
outputAmount: currencyAmount(token3, 1000), outputAmount: toCurrencyAmount(TEST_TOKEN_3, 1000),
}, },
], ],
v3Routes: [ v3Routes: [
{ {
routev3: new V3Route([pool13], token1, token3), routev3: new V3Route([TEST_POOL_13], TEST_TOKEN_1, TEST_TOKEN_3),
inputAmount: currencyAmount(token1, 1000), inputAmount: toCurrencyAmount(TEST_TOKEN_1, 1000),
outputAmount: currencyAmount(token3, 1000), outputAmount: toCurrencyAmount(TEST_TOKEN_3, 1000),
}, },
], ],
tradeType: TradeType.EXACT_INPUT, tradeType: TradeType.EXACT_INPUT,
}) })
) )
).toEqual(currencyAmount(token1, 8)) ).toEqual(toCurrencyAmount(TEST_TOKEN_1, 8))
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment