Test fixes, pass window.web3 to getProviderInfo in test utils, fix creating safe contracts in test env, dep bump

This commit is contained in:
Mikhail Mikheev 2019-11-06 17:28:16 +04:00
parent db54ad812e
commit ede2ebbbe1
9 changed files with 431 additions and 323 deletions

View File

@ -3,6 +3,7 @@ import contract from 'truffle-contract'
import ProxyFactorySol from '@gnosis.pm/safe-contracts/build/contracts/ProxyFactory.json' import ProxyFactorySol from '@gnosis.pm/safe-contracts/build/contracts/ProxyFactory.json'
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json' import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json'
import SafeProxy from '@gnosis.pm/safe-contracts/build/contracts/Proxy.json' import SafeProxy from '@gnosis.pm/safe-contracts/build/contracts/Proxy.json'
import { ensureOnce } from '~/utils/singleton'
import { simpleMemoize } from '~/components/forms/validator' import { simpleMemoize } from '~/components/forms/validator'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { calculateGasOf, calculateGasPrice } from '~/logic/wallets/ethTransactions' import { calculateGasOf, calculateGasPrice } from '~/logic/wallets/ethTransactions'
@ -30,7 +31,7 @@ const createProxyFactoryContract = (web3: any) => {
export const getGnosisSafeContract = simpleMemoize(createGnosisSafeContract) export const getGnosisSafeContract = simpleMemoize(createGnosisSafeContract)
const getCreateProxyFactoryContract = simpleMemoize(createProxyFactoryContract) const getCreateProxyFactoryContract = simpleMemoize(createProxyFactoryContract)
const instanciateMasterCopies = async () => { const instantiateMasterCopies = async () => {
const web3 = getWeb3() const web3 = getWeb3()
// Create ProxyFactory Master Copy // Create ProxyFactory Master Copy
@ -55,7 +56,7 @@ const createMasterCopies = async () => {
safeMaster = await GnosisSafe.new({ from: userAccount, gas: '7000000' }) safeMaster = await GnosisSafe.new({ from: userAccount, gas: '7000000' })
} }
export const initContracts = process.env.NODE_ENV === 'test' ? createMasterCopies : instanciateMasterCopies export const initContracts = process.env.NODE_ENV === 'test' ? ensureOnce(createMasterCopies) : instantiateMasterCopies
export const getSafeMasterContract = async () => { export const getSafeMasterContract = async () => {
await initContracts() await initContracts()

View File

@ -15,7 +15,7 @@ import { type SelectorProps } from '~/routes/load/container/selector'
const getSteps = () => ['Name and address', 'Owners', 'Review'] const getSteps = () => ['Name and address', 'Owners', 'Review']
type Props = SelectorProps & { export type LayoutProps = SelectorProps & {
onLoadSafeSubmit: (values: Object) => Promise<void>, onLoadSafeSubmit: (values: Object) => Promise<void>,
} }

View File

@ -18,6 +18,7 @@ import { shortVersionOf } from '~/logic/wallets/ethAddresses'
import { getAccountsFrom } from '~/routes/open/utils/safeDataExtractor' import { getAccountsFrom } from '~/routes/open/utils/safeDataExtractor'
import { getOwnerNameBy, getOwnerAddressBy, getNumOwnersFrom } from '~/routes/open/components/fields' import { getOwnerNameBy, getOwnerAddressBy, getNumOwnersFrom } from '~/routes/open/components/fields'
import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS, THRESHOLD } from '~/routes/load/components/fields' import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS, THRESHOLD } from '~/routes/load/components/fields'
import type { LayoutProps } from '../Layout'
const styles = () => ({ const styles = () => ({
root: { root: {

View File

@ -115,7 +115,7 @@ export const whenSafeDeployed = (): Promise<string> => new Promise((resolve, rej
const interval = setInterval(() => { const interval = setInterval(() => {
if (times >= MAX_TIMES_EXECUTED) { if (times >= MAX_TIMES_EXECUTED) {
clearInterval(interval) clearInterval(interval)
reject() reject(new Error('Didn\'t load the safe'))
} }
const url = `${window.location}` const url = `${window.location}`
console.log(url) console.log(url)

View File

@ -31,7 +31,7 @@ afterAll(() => {
}) })
const renderOpenSafeForm = async (localStore: Store<GlobalState>) => { const renderOpenSafeForm = async (localStore: Store<GlobalState>) => {
const provider = await getProviderInfo() const provider = await getProviderInfo(window.web3.currentProvider)
const walletRecord = makeProvider(provider) const walletRecord = makeProvider(provider)
localStore.dispatch(addProvider(walletRecord)) localStore.dispatch(addProvider(walletRecord))

View File

@ -38,7 +38,7 @@ describe('DOM > Feature > Sending Funds', () => {
// WHEN // WHEN
const SafeDom = renderSafeView(store, safeAddress) const SafeDom = renderSafeView(store, safeAddress)
await sleep(3500) await sleep(1300)
// Open send funds modal // Open send funds modal
const balanceRows = SafeDom.getAllByTestId(BALANCE_ROW_TEST_ID) const balanceRows = SafeDom.getAllByTestId(BALANCE_ROW_TEST_ID)

View File

@ -2,7 +2,7 @@
import * as React from 'react' import * as React from 'react'
import { type Store } from 'redux' import { type Store } from 'redux'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { render, fireEvent } from '@testing-library/react' import { render, fireEvent, act } from '@testing-library/react'
import { ConnectedRouter } from 'connected-react-router' import { ConnectedRouter } from 'connected-react-router'
import Load from '~/routes/load/container/Load' import Load from '~/routes/load/container/Load'
import { aNewStore, history, type GlobalState } from '~/store' import { aNewStore, history, type GlobalState } from '~/store'
@ -29,7 +29,7 @@ afterAll(() => {
}) })
const renderLoadSafe = async (localStore: Store<GlobalState>) => { const renderLoadSafe = async (localStore: Store<GlobalState>) => {
const provider = await getProviderInfo() const provider = await getProviderInfo(window.web3.currentProvider)
const walletRecord = makeProvider(provider) const walletRecord = makeProvider(provider)
localStore.dispatch(addProvider(walletRecord)) localStore.dispatch(addProvider(walletRecord))
@ -52,19 +52,18 @@ describe('DOM > Feature > LOAD a Safe', () => {
const safeAddressInput = LoadSafePage.getByPlaceholderText('Safe Address*') const safeAddressInput = LoadSafePage.getByPlaceholderText('Safe Address*')
// Fill Safe's name // Fill Safe's name
await act(async () => {
fireEvent.change(safeNameInput, { target: { value: 'A Safe To Load' } }) fireEvent.change(safeNameInput, { target: { value: 'A Safe To Load' } })
fireEvent.change(safeAddressInput, { target: { value: address } }) fireEvent.change(safeAddressInput, { target: { value: address } })
await sleep(400)
// Click next
fireEvent.submit(form) fireEvent.submit(form)
await sleep(400)
// submit form with owners names await sleep(500)
fireEvent.submit(form) fireEvent.submit(form)
await sleep(400)
// Submit await sleep(500)
fireEvent.submit(form) fireEvent.submit(form)
})
const deployedAddress = await whenSafeDeployed() const deployedAddress = await whenSafeDeployed()
expect(deployedAddress).toBe(address) expect(deployedAddress).toBe(address)
}) })

View File

@ -4,7 +4,7 @@ import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { renderSafeView } from '~/test/builder/safe.dom.utils' import { renderSafeView } from '~/test/builder/safe.dom.utils'
import '@testing-library/jest-dom/extend-expect' import '@testing-library/jest-dom/extend-expect'
import { TOGGLE_SIDEBAR_BTN_TESTID } from '~/components/Header/component/SafeListHeader' import { TOGGLE_SIDEBAR_BTN_TESTID } from '~/components/Header/components/SafeListHeader'
import { SIDEBAR_SAFELIST_ROW_TESTID } from '~/components/Sidebar/SafeList' import { SIDEBAR_SAFELIST_ROW_TESTID } from '~/components/Sidebar/SafeList'
import { sleep } from '~/utils/timer' import { sleep } from '~/utils/timer'

713
yarn.lock

File diff suppressed because it is too large Load Diff