Added DOM test for loading safe #75
This commit is contained in:
parent
cafbfb38d9
commit
bd80d2f882
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -24,14 +24,14 @@ export const loadSafe = async (safeName: string, safeAddress: string, updateSafe
|
|||
saveSafes(storedSafes)
|
||||
}
|
||||
|
||||
class Open extends React.Component<Props> {
|
||||
class Load extends React.Component<Props> {
|
||||
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<Props> {
|
|||
}
|
||||
}
|
||||
|
||||
export default connect(selector, actions)(Open)
|
||||
export default connect(selector, actions)(Load)
|
||||
|
|
|
@ -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<string> => 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)
|
||||
})
|
||||
|
|
|
@ -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<GlobalState>) => {
|
||||
const provider = await getProviderInfo()
|
||||
|
@ -31,26 +32,6 @@ const fillOpenSafeForm = async (localStore: Store<GlobalState>) => {
|
|||
)
|
||||
}
|
||||
|
||||
const INTERVAL = 500
|
||||
const MAX_TIMES_EXECUTED = 30
|
||||
export const whenSafeDeployed = (): Promise<string> => 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))
|
||||
|
|
|
@ -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<GlobalState>) => {
|
||||
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)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue