Removing daily limit from addSafe action

This commit is contained in:
apanizo 2018-10-15 13:33:44 +02:00
parent 451f3505a2
commit d97e61993c
8 changed files with 9 additions and 125 deletions

View File

@ -2,7 +2,6 @@
export const FIELD_NAME: string = 'name' export const FIELD_NAME: string = 'name'
export const FIELD_CONFIRMATIONS: string = 'confirmations' export const FIELD_CONFIRMATIONS: string = 'confirmations'
export const FIELD_OWNERS: string = 'owners' export const FIELD_OWNERS: string = 'owners'
export const FIELD_DAILY_LIMIT: string = 'limit'
export const getOwnerNameBy = (index: number) => `owner${index}Name` export const getOwnerNameBy = (index: number) => `owner${index}Name`
export const getOwnerAddressBy = (index: number) => `owner${index}Address` export const getOwnerAddressBy = (index: number) => `owner${index}Address`

View File

@ -37,7 +37,7 @@ export const createSafe = async (values: Object, userAccount: string, addSafe: A
const param = safe.logs[0].args.proxy const param = safe.logs[0].args.proxy
const safeContract = GnosisSafe.at(param) const safeContract = GnosisSafe.at(param)
addSafe(name, safeContract.address, numConfirmations, 0, owners, accounts) addSafe(name, safeContract.address, numConfirmations, owners, accounts)
if (stillInOpeningView()) { if (stillInOpeningView()) {
const url = { const url = {

View File

@ -15,8 +15,7 @@ export const buildOwnersFrom = (names: string[], addresses: string[]) => {
const addSafe = createAction( const addSafe = createAction(
ADD_SAFE, ADD_SAFE,
( (
name: string, address: string, name: string, address: string, threshold: number,
threshold: number, limit: number,
ownersName: string[], ownersAddress: string[], ownersName: string[], ownersAddress: string[],
): SafeProps => { ): SafeProps => {
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress) const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)

View File

@ -1,109 +0,0 @@
// @flow
import * as React from 'react'
import { type Store } from 'redux'
import TestUtils from 'react-dom/test-utils'
import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux'
import { DEPLOYED_COMPONENT_ID } from '~/routes/open/components/FormConfirmation'
import Open from '~/routes/open/container/Open'
import { history, type GlobalState } from '~/store'
import { sleep } from '~/utils/timer'
import { getProviderInfo, getWeb3 } from '~/logic/wallets/getWeb3'
import addProvider from '~/logic/wallets/store/actions/addProvider'
import { makeProvider } from '~/logic/wallets/store/model/provider'
import { promisify } from '~/utils/promisify'
import { type Safe } from '~/routes/safe/store/model/safe'
import { DESTINATION_PARAM, VALUE_PARAM } from '~/routes/safe/component/Withdraw/WithdrawForm'
import { withdraw } from '~/logic/safe/safeFrontendOperations'
export const renderSafe = async (localStore: Store<GlobalState>) => {
const provider = await getProviderInfo()
const walletRecord = makeProvider(provider)
localStore.dispatch(addProvider(walletRecord))
return (
TestUtils.renderIntoDocument((
<Provider store={localStore}>
<ConnectedRouter history={history}>
<Open />
</ConnectedRouter>
</Provider>
))
)
}
const deploySafe = async (safe: React$Component<{}>, dailyLimit: string, threshold: number, numOwners: number) => {
expect(threshold).toBeLessThanOrEqual(numOwners)
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(safe, 'input')
const fieldName = inputs[0]
const fieldOwners = inputs[1]
const fieldConfirmations = inputs[2]
const fieldDailyLimit = inputs[3]
const web3 = getWeb3()
const accounts = await promisify(cb => web3.eth.getAccounts(cb))
TestUtils.Simulate.change(fieldOwners, { target: { value: `${numOwners}` } })
await sleep(800)
const inputsExpanded = TestUtils.scryRenderedDOMComponentsWithTag(safe, 'input')
expect(inputsExpanded.length).toBe((numOwners * 2) + 4) // 2 per owner + name, dailyLimit, confirmations, numOwners
for (let i = 0; i < numOwners; i += 1) {
const nameIndex = (i * 2) + 2
const addressIndex = (i * 2) + 3
const ownerName = inputsExpanded[nameIndex]
const account = inputsExpanded[addressIndex]
TestUtils.Simulate.change(ownerName, { target: { value: `Adolfo ${i + 1} Eth Account` } })
TestUtils.Simulate.change(account, { target: { value: accounts[i] } })
}
TestUtils.Simulate.change(fieldName, { target: { value: 'Adolfo Safe' } })
TestUtils.Simulate.change(fieldConfirmations, { target: { value: `${threshold}` } })
TestUtils.Simulate.change(fieldDailyLimit, { target: { value: dailyLimit } })
const form = TestUtils.findRenderedDOMComponentWithTag(safe, 'form')
TestUtils.Simulate.submit(form) // fill the form
TestUtils.Simulate.submit(form) // confirming data
TestUtils.Simulate.submit(form) // Executing transaction
// giving some time to the component for updating its state with safe
// before destroying its context
await sleep(12000)
// THEN
const deployed = TestUtils.findRenderedDOMComponentWithClass(safe, DEPLOYED_COMPONENT_ID)
if (!deployed) {
throw new Error()
}
const transactionHash = JSON.parse(deployed.getElementsByTagName('pre')[0].innerHTML)
delete transactionHash.receipt.logsBloom
return transactionHash
}
export const aDeployedSafe = async (
specificStore: Store<GlobalState>,
dailyLimit?: number = 0.5,
threshold?: number = 1,
numOwners?: number = 1,
) => {
const safe: React$Component<{}> = await renderSafe(specificStore)
const deployedSafe = await deploySafe(safe, `${dailyLimit}`, threshold, numOwners)
return deployedSafe.logs[1].args.proxy
}
export const executeWithdrawOn = async (safe: Safe, value: number) => {
const providerInfo = await getProviderInfo()
const userAddress = providerInfo.account
const values = {
[DESTINATION_PARAM]: userAddress,
[VALUE_PARAM]: `${value}`,
}
return withdraw(values, safe, userAddress)
}

View File

@ -32,7 +32,6 @@ const providerReducerTests = () => {
[SafeFields.FIELD_NAME]: 'Adol ICO Safe', [SafeFields.FIELD_NAME]: 'Adol ICO Safe',
[SafeFields.FIELD_CONFIRMATIONS]: 1, [SafeFields.FIELD_CONFIRMATIONS]: 1,
[SafeFields.FIELD_OWNERS]: 1, [SafeFields.FIELD_OWNERS]: 1,
[SafeFields.FIELD_DAILY_LIMIT]: 10,
[SafeFields.getOwnerAddressBy(0)]: '0x03db1a8b26d08df23337e9276a36b474510f0023', [SafeFields.getOwnerAddressBy(0)]: '0x03db1a8b26d08df23337e9276a36b474510f0023',
[SafeFields.getOwnerNameBy(0)]: 'Adol Metamask', [SafeFields.getOwnerNameBy(0)]: 'Adol Metamask',
address, address,
@ -47,7 +46,6 @@ const providerReducerTests = () => {
formValues[SafeFields.FIELD_NAME], formValues[SafeFields.FIELD_NAME],
formValues.address, formValues.address,
formValues[SafeFields.FIELD_CONFIRMATIONS], formValues[SafeFields.FIELD_CONFIRMATIONS],
formValues[SafeFields.FIELD_DAILY_LIMIT],
getNamesFrom(formValues), getNamesFrom(formValues),
getAccountsFrom(formValues), getAccountsFrom(formValues),
)) ))

View File

@ -25,12 +25,11 @@ export const filterMoveButtonsFrom = (buttons: Element[]) =>
export const renderSafeInDom = async ( export const renderSafeInDom = async (
owners: number = 1, owners: number = 1,
threshold: number = 1, threshold: number = 1,
dailyLimit: number = 0.5,
): Promise<DomSafe> => { ): Promise<DomSafe> => {
// create store // create store
const store = aNewStore() const store = aNewStore()
// deploy safe updating store // deploy safe updating store
const address = await aMinedSafe(store, owners, threshold, dailyLimit) const address = await aMinedSafe(store, owners, threshold)
// have available accounts // have available accounts
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
// navigate to SAFE route // navigate to SAFE route

View File

@ -1,7 +1,7 @@
// @flow // @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe' import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import { buildOwnersFrom } from '~/routes/safe/store/actions' import { buildOwnersFrom } from '~/routes/safe/store/actions'
import { FIELD_NAME, FIELD_CONFIRMATIONS, FIELD_OWNERS, getOwnerNameBy, getOwnerAddressBy, FIELD_DAILY_LIMIT } from '~/routes/open/components/fields' import { FIELD_NAME, FIELD_CONFIRMATIONS, FIELD_OWNERS, getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields'
import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3' import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify' import { promisify } from '~/utils/promisify'
import addSafe from '~/routes/safe/store/actions/addSafe' import addSafe from '~/routes/safe/store/actions/addSafe'
@ -68,7 +68,6 @@ export const aMinedSafe = async (
store: Store<GlobalState>, store: Store<GlobalState>,
owners: number = 1, owners: number = 1,
threshold: number = 1, threshold: number = 1,
dailyLimit: number = 0.5,
): Promise<string> => { ): Promise<string> => {
const provider = await getProviderInfo() const provider = await getProviderInfo()
const walletRecord = makeProvider(provider) const walletRecord = makeProvider(provider)
@ -79,7 +78,6 @@ export const aMinedSafe = async (
[FIELD_NAME]: 'Safe Name', [FIELD_NAME]: 'Safe Name',
[FIELD_CONFIRMATIONS]: `${threshold}`, [FIELD_CONFIRMATIONS]: `${threshold}`,
[FIELD_OWNERS]: `${owners}`, [FIELD_OWNERS]: `${owners}`,
[FIELD_DAILY_LIMIT]: `${dailyLimit}`,
} }
for (let i = 0; i < owners; i += 1) { for (let i = 0; i < owners; i += 1) {

View File

@ -102,7 +102,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const numOwners = 2 const numOwners = 2
const threshold = 1 const threshold = 1
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold, 10) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
@ -131,7 +131,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const numOwners = 2 const numOwners = 2
const threshold = 1 const threshold = 1
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold, 10) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
@ -163,7 +163,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const numOwners = 2 const numOwners = 2
const threshold = 2 const threshold = 2
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold, 10) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
@ -189,7 +189,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const numOwners = 3 const numOwners = 3
const threshold = 2 const threshold = 2
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold, 10) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)
@ -214,7 +214,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
const numOwners = 3 const numOwners = 3
const threshold = 2 const threshold = 2
const store = aNewStore() const store = aNewStore()
const address = await aMinedSafe(store, numOwners, threshold, 10) const address = await aMinedSafe(store, numOwners, threshold)
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
const gnosisSafe = await getGnosisSafeInstanceAt(address) const gnosisSafe = await getGnosisSafeInstanceAt(address)