From bd80d2f882102208600f8a3d9d652442dc4d42a9 Mon Sep 17 00:00:00 2001 From: apanizo Date: Wed, 14 Nov 2018 17:13:22 +0100 Subject: [PATCH] Added DOM test for loading safe #75 --- src/logic/contracts/safeContracts.js | 6 ++++++ .../load/components/DetailsForm/index.jsx | 5 ++--- src/routes/load/container/Load.jsx | 6 +++--- src/test/builder/safe.dom.utils.js | 20 ++++++++++++++++++ src/test/safe.dom.create.test.js | 21 +------------------ src/test/safe.dom.load.test.js | 10 ++++----- 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/logic/contracts/safeContracts.js b/src/logic/contracts/safeContracts.js index c1cd1c9c..af120c89 100644 --- a/src/logic/contracts/safeContracts.js +++ b/src/logic/contracts/safeContracts.js @@ -54,6 +54,12 @@ const createMasterCopies = async () => { export const initContracts = ensureOnce(process.env.NODE_ENV === 'test' ? createMasterCopies : instanciateMasterCopies) +export const getSafeMasterContract = async () => { + await initContracts() + + return safeMaster +} + export const deploySafeContract = async ( safeAccounts: string[], numConfirmations: number, diff --git a/src/routes/load/components/DetailsForm/index.jsx b/src/routes/load/components/DetailsForm/index.jsx index 28e0ba04..a8f849d3 100644 --- a/src/routes/load/components/DetailsForm/index.jsx +++ b/src/routes/load/components/DetailsForm/index.jsx @@ -14,7 +14,7 @@ import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS } from '~/routes/load/components/fi import { getWeb3 } from '~/logic/wallets/getWeb3' import { promisify } from '~/utils/promisify' import SafeProxy from '#/Proxy.json' -import { getGnosisSafeContract } from '~/logic/contracts/safeContracts' +import { getSafeMasterContract } from '~/logic/contracts/safeContracts' type Props = { classes: Object, @@ -66,8 +66,7 @@ export const safeFieldsValidation = async (values: Object) => { const proxyInstance = proxy.at(safeAddress) const proxyImplementation = await proxyInstance.implementation() - const GnosisSafe = getGnosisSafeContract(web3) - const safeMaster = await GnosisSafe.deployed() + const safeMaster = await getSafeMasterContract() const masterCopy = safeMaster.address const sameMasterCopy = proxyImplementation === masterCopy diff --git a/src/routes/load/container/Load.jsx b/src/routes/load/container/Load.jsx index 27f3e96e..9fe41921 100644 --- a/src/routes/load/container/Load.jsx +++ b/src/routes/load/container/Load.jsx @@ -24,14 +24,14 @@ export const loadSafe = async (safeName: string, safeAddress: string, updateSafe saveSafes(storedSafes) } -class Open extends React.Component { +class Load extends React.Component { onLoadSafeSubmit = async (values: Object) => { try { const { updateSafe } = this.props const safeName = values[FIELD_LOAD_NAME] const safeAddress = values[FIELD_LOAD_ADDRESS] - loadSafe(safeName, safeAddress, updateSafe) + await loadSafe(safeName, safeAddress, updateSafe) const url = `${SAFELIST_ADDRESS}/${safeAddress}` history.push(url) } catch (error) { @@ -58,4 +58,4 @@ class Open extends React.Component { } } -export default connect(selector, actions)(Open) +export default connect(selector, actions)(Load) diff --git a/src/test/builder/safe.dom.utils.js b/src/test/builder/safe.dom.utils.js index a1ee690c..c0bb6dbe 100644 --- a/src/test/builder/safe.dom.utils.js +++ b/src/test/builder/safe.dom.utils.js @@ -115,3 +115,23 @@ export const travelToTokens = (store: Store, address: string): React$Component<{ return createDom(store) } + +const INTERVAL = 500 +const MAX_TIMES_EXECUTED = 30 +export const whenSafeDeployed = (): Promise => new Promise((resolve, reject) => { + let times = 0 + const interval = setInterval(() => { + if (times >= MAX_TIMES_EXECUTED) { + clearInterval(interval) + reject() + } + + const url = `${window.location}` + const regex = /.*safes\/(0x[a-f0-9A-F]*)/ + const safeAddress = url.match(regex) + if (safeAddress) { + resolve(safeAddress[1]) + } + times += 1 + }, INTERVAL) +}) diff --git a/src/test/safe.dom.create.test.js b/src/test/safe.dom.create.test.js index 913b46c4..61abdbd2 100644 --- a/src/test/safe.dom.create.test.js +++ b/src/test/safe.dom.create.test.js @@ -14,6 +14,7 @@ import addProvider from '~/logic/wallets/store/actions/addProvider' import { makeProvider } from '~/logic/wallets/store/model/provider' import { promisify } from '~/utils/promisify' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' +import { whenSafeDeployed } from './builder/safe.dom.utils' const fillOpenSafeForm = async (localStore: Store) => { const provider = await getProviderInfo() @@ -31,26 +32,6 @@ const fillOpenSafeForm = async (localStore: Store) => { ) } -const INTERVAL = 500 -const MAX_TIMES_EXECUTED = 30 -export const whenSafeDeployed = (): Promise => new Promise((resolve, reject) => { - let times = 0 - const interval = setInterval(() => { - if (times >= MAX_TIMES_EXECUTED) { - clearInterval(interval) - reject() - } - - const url = `${window.location}` - const regex = /.*safes\/(0x[a-f0-9A-F]*)/ - const safeAddress = url.match(regex) - if (safeAddress) { - resolve(safeAddress[1]) - } - times += 1 - }, INTERVAL) -}) - const deploySafe = async (safe: React$Component<{}>, threshold: number, numOwners: number) => { const web3 = getWeb3() const accounts = await promisify(cb => web3.eth.getAccounts(cb)) diff --git a/src/test/safe.dom.load.test.js b/src/test/safe.dom.load.test.js index 5a68f214..f74057b4 100644 --- a/src/test/safe.dom.load.test.js +++ b/src/test/safe.dom.load.test.js @@ -11,7 +11,7 @@ import { getProviderInfo } from '~/logic/wallets/getWeb3' import addProvider from '~/logic/wallets/store/actions/addProvider' import { makeProvider } from '~/logic/wallets/store/model/provider' import { aMinedSafe } from './builder/safe.redux.builder' -import { whenSafeDeployed } from './safe.dom.create.test' +import { whenSafeDeployed } from './builder/safe.dom.utils' const travelToLoadRoute = async (localStore: Store) => { const provider = await getProviderInfo() @@ -41,12 +41,11 @@ describe('DOM > Feature > LOAD a safe', () => { // Fill Safe's name const fieldName = inputs[0] TestUtils.Simulate.change(fieldName, { target: { value: 'Adolfo Safe' } }) - TestUtils.Simulate.submit(form) - await sleep(400) - - // Fill Safe's name const fieldAddress = inputs[1] TestUtils.Simulate.change(fieldAddress, { target: { value: address } }) + await sleep(400) + + // Click next TestUtils.Simulate.submit(form) await sleep(400) @@ -54,6 +53,7 @@ describe('DOM > Feature > LOAD a safe', () => { TestUtils.Simulate.submit(form) await sleep(400) + const deployedAddress = await whenSafeDeployed() expect(deployedAddress).toBe(address) })