-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(multicall): add unit tests and fix a bug (#845)
* start with the migrate page * Add a bunch of tests and bump up the call size * Show a link to the old portal, disable the WIP page * Fix lint error
- Loading branch information
1 parent
320b2e3
commit 83554f4
Showing
7 changed files
with
406 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { JSBI, Token } from '@uniswap/sdk' | ||
import React, { useMemo } from 'react' | ||
import { RouteComponentProps } from 'react-router' | ||
import { useAllV1ExchangeAddresses } from '../../data/V1' | ||
import { useActiveWeb3React } from '../../hooks' | ||
import { useTokenBalances } from '../../state/wallet/hooks' | ||
|
||
const PLACEHOLDER_ACCOUNT = ( | ||
<div> | ||
<h1>You must connect a wallet to use this tool.</h1> | ||
</div> | ||
) | ||
|
||
/** | ||
* Page component for migrating liquidity from V1 | ||
*/ | ||
export default function MigrateV1({}: RouteComponentProps) { | ||
const { account, chainId } = useActiveWeb3React() | ||
const v1ExchangeAddresses = useAllV1ExchangeAddresses() | ||
|
||
const v1ExchangeTokens: Token[] = useMemo(() => { | ||
return v1ExchangeAddresses.map(exchangeAddress => new Token(chainId, exchangeAddress, 18)) | ||
}, [chainId, v1ExchangeAddresses]) | ||
|
||
const tokenBalances = useTokenBalances(account, v1ExchangeTokens) | ||
|
||
const unmigratedExchangeAddresses = useMemo( | ||
() => | ||
Object.keys(tokenBalances).filter(tokenAddress => | ||
tokenBalances[tokenAddress] ? JSBI.greaterThan(tokenBalances[tokenAddress]?.raw, JSBI.BigInt(0)) : false | ||
), | ||
[tokenBalances] | ||
) | ||
|
||
if (!account) { | ||
return PLACEHOLDER_ACCOUNT | ||
} | ||
|
||
return <div>{unmigratedExchangeAddresses?.join('\n')}</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { addMulticallListeners, removeMulticallListeners } from './actions' | ||
import reducer, { MulticallState } from './reducer' | ||
import { Store, createStore } from '@reduxjs/toolkit' | ||
|
||
describe('multicall reducer', () => { | ||
let store: Store<MulticallState> | ||
beforeEach(() => { | ||
store = createStore(reducer) | ||
}) | ||
|
||
it('has correct initial state', () => { | ||
expect(store.getState().callResults).toEqual({}) | ||
expect(store.getState().callListeners).toEqual(undefined) | ||
}) | ||
|
||
describe('addMulticallListeners', () => { | ||
it('adds listeners', () => { | ||
store.dispatch( | ||
addMulticallListeners({ | ||
chainId: 1, | ||
calls: [ | ||
{ | ||
address: '0x', | ||
callData: '0x' | ||
} | ||
] | ||
}) | ||
) | ||
expect(store.getState()).toEqual({ | ||
callListeners: { | ||
[1]: { | ||
'0x-0x': { | ||
[1]: 1 | ||
} | ||
} | ||
}, | ||
callResults: {} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('removeMulticallListeners', () => { | ||
it('noop', () => { | ||
store.dispatch( | ||
removeMulticallListeners({ | ||
calls: [ | ||
{ | ||
address: '0x', | ||
callData: '0x' | ||
} | ||
], | ||
chainId: 1 | ||
}) | ||
) | ||
expect(store.getState()).toEqual({ callResults: {}, callListeners: {} }) | ||
}) | ||
it('removes listeners', () => { | ||
store.dispatch( | ||
addMulticallListeners({ | ||
chainId: 1, | ||
calls: [ | ||
{ | ||
address: '0x', | ||
callData: '0x' | ||
} | ||
] | ||
}) | ||
) | ||
store.dispatch( | ||
removeMulticallListeners({ | ||
calls: [ | ||
{ | ||
address: '0x', | ||
callData: '0x' | ||
} | ||
], | ||
chainId: 1 | ||
}) | ||
) | ||
expect(store.getState()).toEqual({ callResults: {}, callListeners: { [1]: { '0x-0x': {} } } }) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.