tests fix wip commit

This commit is contained in:
mmv 2019-03-14 19:36:09 +04:00
parent 122be46934
commit 92772834b9
14 changed files with 104 additions and 65 deletions

1
.env
View File

@ -1 +0,0 @@
REACT_APP_RELAY_API_URL=https://safe-relay.dev.gnosisdev.com/api/v1

View File

@ -3,12 +3,14 @@ import {
TX_SERVICE_HOST,
ENABLED_TX_SERVICE_REMOVAL_SENDER,
SIGNATURES_VIA_METAMASK,
RELAY_API_URL,
} from '~/config/names'
const devConfig = {
[TX_SERVICE_HOST]: 'http://localhost:8000/api/v1/',
[ENABLED_TX_SERVICE_REMOVAL_SENDER]: false,
[SIGNATURES_VIA_METAMASK]: false,
[RELAY_API_URL]: 'https://safe-relay.staging.gnosisdev.com/api/v1/',
}
export default devConfig

View File

@ -4,6 +4,7 @@ import {
TX_SERVICE_HOST,
ENABLED_TX_SERVICE_REMOVAL_SENDER,
SIGNATURES_VIA_METAMASK,
RELAY_API_URL,
} from '~/config/names'
import devConfig from './development'
import testConfig from './testing'
@ -31,6 +32,8 @@ export const getTxServiceHost = () => {
export const getTxServiceUriFrom = (safeAddress: string) => `safes/${safeAddress}/transactions/`
export const getRelayUrl = () => getConfig()[RELAY_API_URL]
export const allowedRemoveSenderInTxHistoryService = () => {
const config = getConfig()

View File

@ -3,3 +3,4 @@
export const TX_SERVICE_HOST = 'tsh'
export const ENABLED_TX_SERVICE_REMOVAL_SENDER = 'trs'
export const SIGNATURES_VIA_METAMASK = 'svm'
export const RELAY_API_URL = 'rau'

View File

@ -3,12 +3,14 @@ import {
TX_SERVICE_HOST,
ENABLED_TX_SERVICE_REMOVAL_SENDER,
SIGNATURES_VIA_METAMASK,
RELAY_API_URL,
} from '~/config/names'
const prodConfig = {
[TX_SERVICE_HOST]: 'https://safe-transaction-history.dev.gnosisdev.com/api/v1/',
[ENABLED_TX_SERVICE_REMOVAL_SENDER]: false,
[SIGNATURES_VIA_METAMASK]: false,
[RELAY_API_URL]: 'https://safe-relay.staging.gnosisdev.com/api/v1/',
}
export default prodConfig

View File

@ -3,12 +3,14 @@ import {
TX_SERVICE_HOST,
ENABLED_TX_SERVICE_REMOVAL_SENDER,
SIGNATURES_VIA_METAMASK,
RELAY_API_URL,
} from '~/config/names'
const testConfig = {
[TX_SERVICE_HOST]: 'http://localhost:8000/api/v1/',
[ENABLED_TX_SERVICE_REMOVAL_SENDER]: false,
[SIGNATURES_VIA_METAMASK]: false,
[RELAY_API_URL]: 'https://safe-relay.staging.gnosisdev.com/api/v1/',
}
export default testConfig

View File

@ -5,5 +5,5 @@ import { BigNumber } from 'bignumber.js'
export const toNative = async (amt: string | number | BigNumber, decimal: number): Promise<BigNumber> => {
const web3 = getWeb3()
return web3.utils.BN(amt).mul(10 ** decimal)
return web3.utils.toBN(amt).mul(10 ** decimal)
}

View File

@ -12,6 +12,7 @@ import { getActiveTokenAddresses, getTokens } from '~/utils/localStorage/tokens'
import { getSafeEthToken } from '~/utils/tokens'
import { enhancedFetch } from '~/utils/fetch'
import addTokens from './addTokens'
import { getRelayUrl } from '~/config/index'
const createStandardTokenContract = async () => {
const web3 = getWeb3()
@ -34,15 +35,23 @@ export const getStandardTokenContract = ensureOnce(createStandardTokenContract)
export const calculateBalanceOf = async (tokenAddress: string, address: string, decimals: number) => {
const erc20Token = await getStandardTokenContract()
const web3 = getWeb3()
let balance = 0
return erc20Token
.at(tokenAddress)
.then(instance => instance.balanceOf(address).then(funds => funds.div(10 ** decimals).toString()))
.catch(() => '0')
try {
const token = await erc20Token.at(tokenAddress)
balance = await token.balanceOf(address)
} catch (err) {
console.error('Failed to fetch token balances: ', err)
}
console.log(balance)
return web3.utils.toBN(balance).div(10 ** decimals).toString()
}
export const fetchTokensData = async () => {
const url = `${process.env.REACT_APP_RELAY_API_URL}/tokens`
const apiUrl = getRelayUrl()
const url = `${apiUrl}/tokens`
const errMsg = 'Error querying safe balances'
return enhancedFetch(url, errMsg)
}
@ -62,7 +71,7 @@ export const fetchTokens = (safeAddress: string) => async (dispatch: ReduxDispat
return makeToken({ ...item, status, funds })
}),
)
console.log('fetched tokens from relay')
const customTokenRecords = await Promise.all(
customTokens.map(async (item: TokenProps) => {
const status = tokens.includes(item.address)
@ -71,7 +80,7 @@ export const fetchTokens = (safeAddress: string) => async (dispatch: ReduxDispat
return makeToken({ ...item, status, funds })
}),
)
console.log('fetched tokens from localstorage')
const balances: Map<string, Token> = Map().withMutations((map) => {
balancesRecords.forEach(record => map.set(record.get('address'), record))
customTokenRecords.forEach(record => map.set(record.get('address'), record))
@ -79,10 +88,12 @@ export const fetchTokens = (safeAddress: string) => async (dispatch: ReduxDispat
map.set(ethBalance.get('address'), ethBalance)
})
console.log('fetched balances for tokens')
return dispatch(addTokens(safeAddress, balances))
} catch (err) {
// eslint-disable-next-line
console.log('Error fetching token balances... ' + err)
console.log('Error fetching tokens... ' + err)
return Promise.resolve()
}

View File

@ -26,4 +26,3 @@ export const testToken = (token: Token | typeof undefined, symbol: string, statu
expect(token.get('funds')).toBe(funds)
}
}

View File

@ -29,15 +29,17 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
// $FlowFixMe
enhancedFetchModule.enhancedFetch = jest.fn()
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve([
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
]))
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve({
results: [
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
],
}))
})
it('adds a second erc 20 token filling the form', async () => {

View File

@ -30,22 +30,24 @@ describe('DOM > Feature > Enable and disable default tokens', () => {
secondErc20Token = await getSecondTokenContract(web3, accounts[0])
// $FlowFixMe
enhancedFetchModule.enhancedFetch = jest.fn()
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve([
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
{
address: secondErc20Token.address,
name: 'Second Token Example',
symbol: 'STE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
]))
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve({
results: [
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
{
address: secondErc20Token.address,
name: 'Second Token Example',
symbol: 'STE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
],
}))
})
it('retrieves only ether as active token in first moment', async () => {

View File

@ -8,7 +8,12 @@ import { travelToTokens } from '~/test/builder/safe.dom.utils'
import * as fetchTokensModule from '~/routes/tokens/store/actions/fetchTokens'
import * as enhancedFetchModule from '~/utils/fetch'
import { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage'
import { TOKEN_NAME_PARAM, TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM } from '~/routes/tokens/component/AddToken/SecondPage'
import {
TOKEN_NAME_PARAM,
TOKEN_SYMBOL_PARAM,
TOKEN_DECIMALS_PARAM,
TOKEN_LOGO_URL_PARAM,
} from '~/routes/tokens/component/AddToken/SecondPage'
import addToken from '~/routes/tokens/store/actions/addToken'
import { addTokenFnc } from '~/routes/tokens/component/AddToken'
import { sleep } from '~/utils/timer'
@ -29,15 +34,17 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
// $FlowFixMe
enhancedFetchModule.enhancedFetch = jest.fn()
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve([
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
]))
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve({
results: [
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
],
}))
})
it('remove custom ERC 20 tokens', async () => {

View File

@ -10,7 +10,12 @@ import { testToken } from '~/test/builder/tokens.dom.utils'
import * as fetchTokensModule from '~/routes/tokens/store/actions/fetchTokens'
import * as enhancedFetchModule from '~/utils/fetch'
import { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage'
import { TOKEN_NAME_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_SYMBOL_PARAM, TOKEN_LOGO_URL_PARAM } from '~/routes/tokens/component/AddToken/SecondPage'
import {
TOKEN_NAME_PARAM,
TOKEN_DECIMALS_PARAM,
TOKEN_SYMBOL_PARAM,
TOKEN_LOGO_URL_PARAM,
} from '~/routes/tokens/component/AddToken/SecondPage'
import addToken from '~/routes/tokens/store/actions/addToken'
import { addTokenFnc } from '~/routes/tokens/component/AddToken'
import { activeTokensSelector } from '~/routes/tokens/store/selectors'
@ -29,15 +34,17 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
// $FlowFixMe
enhancedFetchModule.enhancedFetch = jest.fn()
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve([
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
]))
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve({
results: [
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
],
}))
})
it('persist added custom ERC 20 tokens as active when reloading the page', async () => {

View File

@ -37,15 +37,17 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
// $FlowFixMe
enhancedFetchModule.enhancedFetch = jest.fn()
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve([
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
]))
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve({
results: [
{
address: firstErc20Token.address,
name: 'First Token Example',
symbol: 'FTE',
decimals: 18,
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
},
],
}))
})
const checkTokensOf = (store: Store, safeAddress: string) => {