WA-232 Remove old AddTransaction feature, keeping consisten move tokens feature
This commit is contained in:
parent
7859e552f0
commit
c40488493d
|
@ -1,29 +0,0 @@
|
|||
// @flow
|
||||
import { storiesOf } from '@storybook/react'
|
||||
import * as React from 'react'
|
||||
import Stepper from '~/components/Stepper'
|
||||
import styles from '~/components/layout/PageFrame/index.scss'
|
||||
import MultisigForm from './index'
|
||||
|
||||
|
||||
const FrameDecorator = story => (
|
||||
<div className={styles.frame} style={{ textAlign: 'center' }}>
|
||||
{ story() }
|
||||
</div>
|
||||
)
|
||||
|
||||
storiesOf('Components', module)
|
||||
.addDecorator(FrameDecorator)
|
||||
.add('MultisigForm', () => (
|
||||
<Stepper
|
||||
finishedTransaction={false}
|
||||
finishedButton={<Stepper.FinishButton title="SEE TXS" />}
|
||||
onSubmit={() => {}}
|
||||
steps={['Multisig TX Form', 'Review TX']}
|
||||
onReset={() => {}}
|
||||
>
|
||||
<Stepper.Page balance={10}>
|
||||
{ MultisigForm }
|
||||
</Stepper.Page>
|
||||
</Stepper>
|
||||
))
|
|
@ -1,67 +0,0 @@
|
|||
// @flow
|
||||
import * as React from 'react'
|
||||
import Field from '~/components/forms/Field'
|
||||
import TextField from '~/components/forms/TextField'
|
||||
import { composeValidators, inLimit, mustBeFloat, required, greaterThan, mustBeEthereumAddress } from '~/components/forms/validator'
|
||||
import Block from '~/components/layout/Block'
|
||||
import Heading from '~/components/layout/Heading'
|
||||
import { TX_NAME_PARAM, TX_DESTINATION_PARAM, TX_VALUE_PARAM } from '~/routes/safe/component/AddTransaction/createTransactions'
|
||||
|
||||
export const CONFIRMATIONS_ERROR = 'Number of confirmations can not be higher than the number of owners'
|
||||
|
||||
export const safeFieldsValidation = (values: Object) => {
|
||||
const errors = {}
|
||||
|
||||
if (Number.parseInt(values.owners, 10) < Number.parseInt(values.confirmations, 10)) {
|
||||
errors.confirmations = CONFIRMATIONS_ERROR
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
type Props = {
|
||||
balance: number,
|
||||
}
|
||||
|
||||
const WithdrawForm = ({ balance }: Props) => () => (
|
||||
<Block margin="md">
|
||||
<Heading tag="h2" margin="lg">
|
||||
Multisig Transaction
|
||||
</Heading>
|
||||
<Heading tag="h4" margin="lg">
|
||||
{`Available balance: ${balance} ETH`}
|
||||
</Heading>
|
||||
<Block margin="md">
|
||||
<Field
|
||||
name={TX_NAME_PARAM}
|
||||
component={TextField}
|
||||
type="text"
|
||||
validate={required}
|
||||
placeholder="Transaction name"
|
||||
text="Transaction name"
|
||||
/>
|
||||
</Block>
|
||||
<Block margin="md">
|
||||
<Field
|
||||
name={TX_DESTINATION_PARAM}
|
||||
component={TextField}
|
||||
type="text"
|
||||
validate={composeValidators(required, mustBeEthereumAddress)}
|
||||
placeholder="Destination*"
|
||||
text="Destination"
|
||||
/>
|
||||
</Block>
|
||||
<Block margin="md">
|
||||
<Field
|
||||
name={TX_VALUE_PARAM}
|
||||
component={TextField}
|
||||
type="text"
|
||||
validate={composeValidators(required, mustBeFloat, greaterThan(0), inLimit(balance, 0, 'available balance'))}
|
||||
placeholder="Amount in ETH*"
|
||||
text="Amount in ETH"
|
||||
/>
|
||||
</Block>
|
||||
</Block>
|
||||
)
|
||||
|
||||
export default WithdrawForm
|
|
@ -1,37 +0,0 @@
|
|||
// @flow
|
||||
import * as React from 'react'
|
||||
import CircularProgress from '@material-ui/core/CircularProgress'
|
||||
import Block from '~/components/layout/Block'
|
||||
import Bold from '~/components/layout/Bold'
|
||||
import Heading from '~/components/layout/Heading'
|
||||
import Paragraph from '~/components/layout/Paragraph'
|
||||
import { TX_NAME_PARAM, TX_DESTINATION_PARAM, TX_VALUE_PARAM } from '~/routes/safe/component/AddTransaction/createTransactions'
|
||||
|
||||
type FormProps = {
|
||||
values: Object,
|
||||
submitting: boolean,
|
||||
}
|
||||
|
||||
const spinnerStyle = {
|
||||
minHeight: '50px',
|
||||
}
|
||||
|
||||
const ReviewTx = () => ({ values, submitting }: FormProps) => (
|
||||
<Block>
|
||||
<Heading tag="h2">Review the Multisig Tx</Heading>
|
||||
<Paragraph align="left">
|
||||
<Bold>Transaction Name: </Bold> {values[TX_NAME_PARAM]}
|
||||
</Paragraph>
|
||||
<Paragraph align="left">
|
||||
<Bold>Destination: </Bold> {values[TX_DESTINATION_PARAM]}
|
||||
</Paragraph>
|
||||
<Paragraph align="left">
|
||||
<Bold>Amount to transfer in ETH: </Bold> {values[TX_VALUE_PARAM]}
|
||||
</Paragraph>
|
||||
<Block style={spinnerStyle}>
|
||||
{ submitting && <CircularProgress size={50} /> }
|
||||
</Block>
|
||||
</Block>
|
||||
)
|
||||
|
||||
export default ReviewTx
|
|
@ -1,10 +0,0 @@
|
|||
// @flow
|
||||
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
||||
|
||||
export type Actions = {
|
||||
fetchTransactions: typeof fetchTransactions,
|
||||
}
|
||||
|
||||
export default {
|
||||
fetchTransactions,
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
// @flow
|
||||
import { List } from 'immutable'
|
||||
import { type Owner } from '~/routes/safe/store/model/owner'
|
||||
import { load, TX_KEY } from '~/utils/localStorage'
|
||||
import { type Confirmation, makeConfirmation } from '~/routes/safe/store/model/confirmation'
|
||||
import { makeTransaction, type Transaction, type TransactionProps } from '~/routes/safe/store/model/transaction'
|
||||
import { getGnosisSafeContract } from '~/wallets/safeContracts'
|
||||
import { getWeb3 } from '~/wallets/getWeb3'
|
||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||
import { sameAddress } from '~/wallets/ethAddresses'
|
||||
import { checkReceiptStatus, calculateGasOf, calculateGasPrice, EMPTY_DATA } from '~/wallets/ethTransactions'
|
||||
|
||||
export const TX_NAME_PARAM = 'txName'
|
||||
export const TX_DESTINATION_PARAM = 'txDestination'
|
||||
export const TX_VALUE_PARAM = 'txValue'
|
||||
|
||||
export const EXECUTED_CONFIRMATION_HASH = 'EXECUTED'
|
||||
|
||||
// Exported for testing it, should not use it. Use #transactions fnc.
|
||||
export const buildConfirmationsFrom =
|
||||
(owners: List<Owner>, creator: string, confirmationHash: string): List<Confirmation> => {
|
||||
if (!owners) {
|
||||
throw new Error('This safe has no owners')
|
||||
}
|
||||
|
||||
if (!owners.find((owner: Owner) => sameAddress(owner.get('address'), creator))) {
|
||||
throw new Error('The creator of the tx is not an owner')
|
||||
}
|
||||
|
||||
return owners.map((owner: Owner) => makeConfirmation({
|
||||
owner,
|
||||
status: sameAddress(owner.get('address'), creator),
|
||||
hash: sameAddress(owner.get('address'), creator) ? confirmationHash : undefined,
|
||||
}))
|
||||
}
|
||||
|
||||
export const buildExecutedConfirmationFrom = (owners: List<Owner>, creator: string): List<Confirmation> =>
|
||||
buildConfirmationsFrom(owners, creator, EXECUTED_CONFIRMATION_HASH)
|
||||
|
||||
export const storeTransaction = (
|
||||
name: string,
|
||||
nonce: number,
|
||||
destination: string,
|
||||
value: number,
|
||||
creator: string,
|
||||
confirmations: List<Confirmation>,
|
||||
tx: string,
|
||||
safeAddress: string,
|
||||
safeThreshold: number,
|
||||
data: string,
|
||||
) => {
|
||||
const notMinedWhenOneOwnerSafe = confirmations.count() === 1 && !tx
|
||||
if (notMinedWhenOneOwnerSafe) {
|
||||
throw new Error('The tx should be mined before storing it in safes with one owner')
|
||||
}
|
||||
|
||||
const transaction: Transaction = makeTransaction({
|
||||
name, nonce, value, confirmations, destination, threshold: safeThreshold, tx, data,
|
||||
})
|
||||
|
||||
const safeTransactions = load(TX_KEY) || {}
|
||||
const transactions = safeTransactions[safeAddress]
|
||||
const txsRecord = transactions ? List(transactions) : List([])
|
||||
|
||||
if (txsRecord.find((txs: TransactionProps) => txs.nonce === nonce)) {
|
||||
throw new Error(`Transaction with same nonce: ${nonce} already created for safe: ${safeAddress}`)
|
||||
}
|
||||
|
||||
safeTransactions[safeAddress] = txsRecord.push(transaction)
|
||||
|
||||
localStorage.setItem(TX_KEY, JSON.stringify(safeTransactions))
|
||||
}
|
||||
|
||||
const hasOneOwner = (safe: Safe) => {
|
||||
const owners = safe.get('owners')
|
||||
if (!owners) {
|
||||
throw new Error('Received a Safe without owners when creating a tx')
|
||||
}
|
||||
|
||||
return owners.count() === 1
|
||||
}
|
||||
|
||||
export const getSafeEthereumInstance = async (safeAddress: string) => {
|
||||
const web3 = getWeb3()
|
||||
const GnosisSafe = await getGnosisSafeContract(web3)
|
||||
return GnosisSafe.at(safeAddress)
|
||||
}
|
||||
|
||||
export const createTransaction = async (
|
||||
safe: Safe,
|
||||
txName: string,
|
||||
txDest: string,
|
||||
txValue: number,
|
||||
nonce: number,
|
||||
user: string,
|
||||
data: string = EMPTY_DATA,
|
||||
) => {
|
||||
const web3 = getWeb3()
|
||||
const safeAddress = safe.get('address')
|
||||
const gnosisSafe = await getSafeEthereumInstance(safeAddress)
|
||||
const valueInWei = web3.toWei(txValue, 'ether')
|
||||
const CALL = 0
|
||||
const gasPrice = await calculateGasPrice()
|
||||
|
||||
const thresholdIsOne = safe.get('threshold') === 1
|
||||
if (hasOneOwner(safe) || thresholdIsOne) {
|
||||
const txConfirmationData =
|
||||
gnosisSafe.contract.execTransactionIfApproved.getData(txDest, valueInWei, data, CALL, nonce)
|
||||
const gas = await calculateGasOf(txConfirmationData, user, safeAddress)
|
||||
const txHash =
|
||||
await gnosisSafe.execTransactionIfApproved(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
|
||||
await checkReceiptStatus(txHash.tx)
|
||||
const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user)
|
||||
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash.tx, safeAddress, safe.get('threshold'), data)
|
||||
}
|
||||
|
||||
const txData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce)
|
||||
const gas = await calculateGasOf(txData, user, safeAddress)
|
||||
const txConfirmationHash = await gnosisSafe
|
||||
.approveTransactionWithParameters(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
|
||||
await checkReceiptStatus(txConfirmationHash.tx)
|
||||
|
||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash.tx)
|
||||
|
||||
return storeTransaction(txName, nonce, txDest, txValue, user, confirmations, '', safeAddress, safe.get('threshold'), data)
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
// @flow
|
||||
import * as React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import Stepper from '~/components/Stepper'
|
||||
import { sleep } from '~/utils/timer'
|
||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||
import actions, { type Actions } from './actions'
|
||||
import selector, { type SelectorProps } from './selector'
|
||||
import { createTransaction, TX_NAME_PARAM, TX_DESTINATION_PARAM, TX_VALUE_PARAM } from './createTransactions'
|
||||
import MultisigForm from './MultisigForm'
|
||||
import ReviewTx from './ReviewTx'
|
||||
|
||||
const getSteps = () => [
|
||||
'Fill Mutlisig Tx form', 'Review Tx',
|
||||
]
|
||||
|
||||
type Props = SelectorProps & Actions & {
|
||||
safe: Safe,
|
||||
balance: number,
|
||||
onReset: () => void,
|
||||
}
|
||||
|
||||
type State = {
|
||||
done: boolean,
|
||||
}
|
||||
|
||||
export const SEE_TXS_BUTTON_TEXT = 'VISIT TXS'
|
||||
|
||||
class AddTransaction extends React.Component<Props, State> {
|
||||
state = {
|
||||
done: false,
|
||||
}
|
||||
|
||||
onTransaction = async (values: Object) => {
|
||||
try {
|
||||
const { safe, userAddress } = this.props
|
||||
const nonce = Date.now()
|
||||
const destination = values[TX_DESTINATION_PARAM]
|
||||
const value = values[TX_VALUE_PARAM]
|
||||
const name = values[TX_NAME_PARAM]
|
||||
await createTransaction(safe, name, destination, value, nonce, userAddress)
|
||||
await sleep(1500)
|
||||
this.props.fetchTransactions()
|
||||
this.setState({ done: true })
|
||||
} catch (error) {
|
||||
this.setState({ done: false })
|
||||
// eslint-disable-next-line
|
||||
console.log('Error while creating multisig tx ' + error)
|
||||
}
|
||||
}
|
||||
|
||||
onReset = () => {
|
||||
this.setState({ done: false })
|
||||
this.props.onReset() // This is for show the TX list component
|
||||
}
|
||||
|
||||
render() {
|
||||
const { done } = this.state
|
||||
const { balance } = this.props
|
||||
const steps = getSteps()
|
||||
const finishedButton = <Stepper.FinishButton title={SEE_TXS_BUTTON_TEXT} />
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Stepper
|
||||
finishedTransaction={done}
|
||||
finishedButton={finishedButton}
|
||||
onSubmit={this.onTransaction}
|
||||
steps={steps}
|
||||
onReset={this.onReset}
|
||||
>
|
||||
<Stepper.Page balance={balance}>
|
||||
{ MultisigForm }
|
||||
</Stepper.Page>
|
||||
<Stepper.Page>
|
||||
{ ReviewTx }
|
||||
</Stepper.Page>
|
||||
</Stepper>
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(selector, actions)(AddTransaction)
|
|
@ -1,11 +0,0 @@
|
|||
// @flow
|
||||
import { createStructuredSelector } from 'reselect'
|
||||
import { userAccountSelector } from '~/wallets/store/selectors/index'
|
||||
|
||||
export type SelectorProps = {
|
||||
userAddress: userAccountSelector,
|
||||
}
|
||||
|
||||
export default createStructuredSelector({
|
||||
userAddress: userAccountSelector,
|
||||
})
|
|
@ -1,226 +0,0 @@
|
|||
// @flow
|
||||
import { List, Map } from 'immutable'
|
||||
import { storeTransaction, buildConfirmationsFrom, EXECUTED_CONFIRMATION_HASH, buildExecutedConfirmationFrom } from '~/routes/safe/component/AddTransaction/createTransactions'
|
||||
import { type Transaction } from '~/routes/safe/store/model/transaction'
|
||||
import { SafeFactory } from '~/routes/safe/store/test/builder/safe.builder'
|
||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||
import { type Owner } from '~/routes/safe/store/model/owner'
|
||||
import { loadSafeTransactions } from '~/routes/safe/store/actions/fetchTransactions'
|
||||
import { type Confirmation } from '~/routes/safe/store/model/confirmation'
|
||||
import { EMPTY_DATA } from '~/wallets/ethTransactions'
|
||||
import { testSizeOfSafesWith, testSizeOfTransactions, testTransactionFrom } from './transactionsHelper'
|
||||
|
||||
describe('Transactions Suite', () => {
|
||||
let safe: Safe
|
||||
let destination: string
|
||||
let value: number
|
||||
let owners: List<Owner>
|
||||
beforeEach(async () => {
|
||||
localStorage.clear()
|
||||
|
||||
safe = SafeFactory.twoOwnersSafe('foo', 'bar')
|
||||
destination = 'baz'
|
||||
value = 2
|
||||
owners = safe.get('owners')
|
||||
|
||||
const firstOwner = owners.get(0)
|
||||
if (!firstOwner) { throw new Error() }
|
||||
const secondOwner = owners.get(1)
|
||||
if (!secondOwner) { throw new Error() }
|
||||
})
|
||||
|
||||
it('adds first confirmation to stored safe', async () => {
|
||||
// GIVEN
|
||||
const txName = 'Buy butteries for project'
|
||||
const nonce: number = 10
|
||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(owners, 'foo', 'confirmationHash')
|
||||
storeTransaction(txName, nonce, destination, value, 'foo', confirmations, '', safe.get('address'), safe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
// WHEN
|
||||
const transactions: Map<string, List<Transaction>> = loadSafeTransactions()
|
||||
|
||||
// THEN
|
||||
testSizeOfSafesWith(transactions, 1)
|
||||
|
||||
const safeTransactions: List<Transaction> | typeof undefined = transactions.get(safe.get('address'))
|
||||
if (!safeTransactions) { throw new Error() }
|
||||
testSizeOfTransactions(safeTransactions, 1)
|
||||
|
||||
testTransactionFrom(safeTransactions, 0, txName, nonce, value, 2, destination, EMPTY_DATA, 'foo', 'confirmationHash', owners.get(0), owners.get(1))
|
||||
})
|
||||
|
||||
it('adds second confirmation to stored safe with one confirmation', async () => {
|
||||
// GIVEN
|
||||
const firstTxName = 'Buy butteries for project'
|
||||
const firstNonce: number = Date.now()
|
||||
const safeAddress = safe.get('address')
|
||||
const creator = 'foo'
|
||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(owners, creator, 'confirmationHash')
|
||||
storeTransaction(firstTxName, firstNonce, destination, value, creator, confirmations, '', safeAddress, safe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
const secondTxName = 'Buy printers for project'
|
||||
const secondNonce: number = firstNonce + 100
|
||||
const secondConfirmations: List<Confirmation> = buildConfirmationsFrom(owners, creator, 'confirmationHash')
|
||||
storeTransaction(secondTxName, secondNonce, destination, value, creator, secondConfirmations, '', safeAddress, safe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
// WHEN
|
||||
const transactions: Map<string, List<Transaction>> = loadSafeTransactions()
|
||||
|
||||
// THEN
|
||||
testSizeOfSafesWith(transactions, 1)
|
||||
|
||||
const safeTxs: List<Transaction> | typeof undefined = transactions.get(safeAddress)
|
||||
if (!safeTxs) { throw new Error() }
|
||||
testSizeOfTransactions(safeTxs, 2)
|
||||
|
||||
testTransactionFrom(safeTxs, 0, firstTxName, firstNonce, value, 2, destination, EMPTY_DATA, 'foo', 'confirmationHash', owners.get(0), owners.get(1))
|
||||
testTransactionFrom(safeTxs, 1, secondTxName, secondNonce, value, 2, destination, EMPTY_DATA, 'foo', 'confirmationHash', owners.get(0), owners.get(1))
|
||||
})
|
||||
|
||||
it('adds second confirmation to stored safe having two safes with one confirmation each', async () => {
|
||||
const txName = 'Buy batteris for Alplha project'
|
||||
const nonce = 10
|
||||
const safeAddress = safe.address
|
||||
const creator = 'foo'
|
||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(owners, creator, 'confirmationHash')
|
||||
storeTransaction(txName, nonce, destination, value, creator, confirmations, '', safeAddress, safe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
const secondSafe = SafeFactory.dailyLimitSafe(10, 2)
|
||||
const txSecondName = 'Buy batteris for Beta project'
|
||||
const txSecondNonce = 10
|
||||
const secondSafeAddress = secondSafe.address
|
||||
const secondCreator = '0x03db1a8b26d08df23337e9276a36b474510f0023'
|
||||
const secondConfirmations: List<Confirmation> = buildConfirmationsFrom(secondSafe.get('owners'), secondCreator, 'confirmationHash')
|
||||
storeTransaction(
|
||||
txSecondName, txSecondNonce, destination, value, secondCreator,
|
||||
secondConfirmations, '', secondSafeAddress, secondSafe.get('threshold'), EMPTY_DATA,
|
||||
)
|
||||
|
||||
let transactions: Map<string, List<Transaction>> = loadSafeTransactions()
|
||||
testSizeOfSafesWith(transactions, 2)
|
||||
|
||||
const firstSafeTxs: List<Transaction> | typeof undefined = transactions.get(safeAddress)
|
||||
if (!firstSafeTxs) { throw new Error() }
|
||||
testSizeOfTransactions(firstSafeTxs, 1)
|
||||
|
||||
const secondSafeTxs: List<Transaction> | typeof undefined = transactions.get(secondSafeAddress)
|
||||
if (!secondSafeTxs) { throw new Error() }
|
||||
testSizeOfTransactions(secondSafeTxs, 1)
|
||||
|
||||
// WHEN
|
||||
const txFirstName = 'Buy paper for Alplha project'
|
||||
const txFirstNonce = 11
|
||||
const txConfirmations: List<Confirmation> = buildConfirmationsFrom(owners, creator, 'secondConfirmationHash')
|
||||
storeTransaction(
|
||||
txFirstName, txFirstNonce, destination, value, creator,
|
||||
txConfirmations, '', safe.get('address'), safe.get('threshold'), EMPTY_DATA,
|
||||
)
|
||||
|
||||
transactions = loadSafeTransactions()
|
||||
|
||||
// THEN
|
||||
testSizeOfSafesWith(transactions, 2)
|
||||
testSizeOfTransactions(transactions.get(safeAddress), 2)
|
||||
testSizeOfTransactions(transactions.get(secondSafeAddress), 1)
|
||||
|
||||
// Test 2 transactions of first safe
|
||||
testTransactionFrom(
|
||||
transactions.get(safe.address), 0,
|
||||
txName, nonce, value, 2, destination, EMPTY_DATA,
|
||||
'foo', 'confirmationHash', owners.get(0), owners.get(1),
|
||||
)
|
||||
testTransactionFrom(
|
||||
transactions.get(safe.address), 1,
|
||||
txFirstName, txFirstNonce, value, 2, destination, EMPTY_DATA,
|
||||
'foo', 'secondConfirmationHash', owners.get(0), owners.get(1),
|
||||
)
|
||||
|
||||
// Test one transaction of second safe
|
||||
testTransactionFrom(
|
||||
transactions.get(secondSafe.address), 0,
|
||||
txSecondName, txSecondNonce, value, 2, destination, EMPTY_DATA,
|
||||
'0x03db1a8b26d08df23337e9276a36b474510f0023', 'confirmationHash', secondSafe.get('owners').get(0), secondSafe.get('owners').get(1),
|
||||
)
|
||||
})
|
||||
|
||||
it('does not allow to store same transaction twice', async () => {
|
||||
// GIVEN
|
||||
const txName = 'Buy butteries for project'
|
||||
const nonce: number = 10
|
||||
const creator = 'foo'
|
||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(owners, creator, 'confirmationHash')
|
||||
storeTransaction(txName, nonce, destination, value, creator, confirmations, '', safe.get('address'), safe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
// WHEN
|
||||
const createTxFnc = () => storeTransaction(txName, nonce, destination, value, creator, confirmations, '', safe.get('address'), safe.get('threshold'), EMPTY_DATA)
|
||||
expect(createTxFnc).toThrow(/Transaction with same nonce/)
|
||||
})
|
||||
|
||||
it('checks the owner who creates the tx has confirmed it', async () => {
|
||||
// GIVEN
|
||||
const txName = 'Buy butteries for project'
|
||||
const nonce: number = 10
|
||||
const creator = 'foo'
|
||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(owners, creator, 'confirmationHash')
|
||||
storeTransaction(txName, nonce, destination, value, creator, confirmations, '', safe.get('address'), safe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
// WHEN
|
||||
const transactions: Map<string, List<Transaction>> = loadSafeTransactions()
|
||||
|
||||
// THEN
|
||||
testSizeOfSafesWith(transactions, 1)
|
||||
})
|
||||
|
||||
it('checks the owner who creates the tx is an owner', async () => {
|
||||
// GIVEN
|
||||
const ownerName = 'invented'
|
||||
const buildConfirmationsTxFnc = () => buildConfirmationsFrom(owners, ownerName, 'confirmationHash')
|
||||
|
||||
expect(buildConfirmationsTxFnc).toThrow(/The creator of the tx is not an owner/)
|
||||
})
|
||||
|
||||
it('checks if safe has one owner transaction has been executed', async () => {
|
||||
const ownerName = 'foo'
|
||||
const oneOwnerSafe = SafeFactory.oneOwnerSafe(ownerName)
|
||||
const txName = 'Buy butteries for project'
|
||||
const nonce: number = 10
|
||||
const tx = ''
|
||||
const confirmations: List<Confirmation> = buildExecutedConfirmationFrom(oneOwnerSafe.get('owners'), ownerName)
|
||||
const createTxFnc = () => storeTransaction(txName, nonce, destination, value, ownerName, confirmations, tx, oneOwnerSafe.get('address'), oneOwnerSafe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
expect(createTxFnc).toThrow(/The tx should be mined before storing it in safes with one owner/)
|
||||
})
|
||||
|
||||
it('checks if safe has one owner transaction the confirmation list is correctly build', async () => {
|
||||
const ownerName = 'foo'
|
||||
const oneOwnerSafe = SafeFactory.oneOwnerSafe(ownerName)
|
||||
const txName = 'Buy butteries for project'
|
||||
const nonce: number = 10
|
||||
const tx = 'validTxHash'
|
||||
const confirmations: List<Confirmation> = buildExecutedConfirmationFrom(oneOwnerSafe.get('owners'), ownerName)
|
||||
storeTransaction(txName, nonce, destination, value, ownerName, confirmations, tx, oneOwnerSafe.get('address'), oneOwnerSafe.get('threshold'), EMPTY_DATA)
|
||||
|
||||
// WHEN
|
||||
const safeTransactions: Map<string, List<Transaction>> = loadSafeTransactions()
|
||||
|
||||
// THEN
|
||||
expect(safeTransactions.size).toBe(1)
|
||||
|
||||
const transactions: List<Transaction> | typeof undefined = safeTransactions.get(oneOwnerSafe.address)
|
||||
if (!transactions) throw new Error()
|
||||
expect(transactions.count()).toBe(1)
|
||||
|
||||
const batteriesTx: Transaction | typeof undefined = transactions.get(0)
|
||||
if (!batteriesTx) throw new Error()
|
||||
expect(batteriesTx.get('name')).toBe(txName)
|
||||
|
||||
const txConfirmations = batteriesTx.confirmations
|
||||
if (!txConfirmations) throw new Error()
|
||||
expect(txConfirmations.count()).toBe(1)
|
||||
|
||||
const firstConfirmation: Confirmation | typeof undefined = txConfirmations.get(0)
|
||||
if (!firstConfirmation) throw new Error()
|
||||
expect(firstConfirmation.get('hash')).toBe(EXECUTED_CONFIRMATION_HASH)
|
||||
})
|
||||
})
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
// @flow
|
||||
import { List, Map } from 'immutable'
|
||||
import { type Confirmation } from '~/routes/safe/store/model/confirmation'
|
||||
import { type Transaction } from '~/routes/safe/store/model/transaction'
|
||||
import { type Owner } from '~/routes/safe/store/model/owner'
|
||||
|
||||
export const testSizeOfSafesWith = (transactions: Map<string, List<Transaction>>, size: number) => {
|
||||
expect(transactions).not.toBe(undefined)
|
||||
expect(transactions).not.toBe(null)
|
||||
expect(transactions.size).toBe(size)
|
||||
}
|
||||
|
||||
export const testSizeOfTransactions = (safeTxs: List<Transaction> | typeof undefined, size: number) => {
|
||||
if (!safeTxs) { throw new Error() }
|
||||
expect(safeTxs.count()).toBe(size)
|
||||
expect(safeTxs.get(0)).not.toBe(undefined)
|
||||
expect(safeTxs.get(0)).not.toBe(null)
|
||||
}
|
||||
|
||||
export const testTransactionFrom = (
|
||||
safeTxs: List<Transaction> | typeof undefined, pos: number, name: string,
|
||||
nonce: number, value: number, threshold: number, destination: string,
|
||||
data: string, creator: string, txHash: string,
|
||||
firstOwner: Owner | typeof undefined, secondOwner: Owner | typeof undefined,
|
||||
) => {
|
||||
if (!safeTxs) { throw new Error() }
|
||||
const tx: Transaction | typeof undefined = safeTxs.get(pos)
|
||||
|
||||
if (!tx) { throw new Error() }
|
||||
expect(tx.get('name')).toBe(name)
|
||||
expect(tx.get('value')).toBe(value)
|
||||
expect(tx.get('threshold')).toBe(threshold)
|
||||
expect(tx.get('destination')).toBe(destination)
|
||||
expect(tx.get('confirmations').count()).toBe(2)
|
||||
expect(tx.get('nonce')).toBe(nonce)
|
||||
expect(tx.get('data')).toBe(data)
|
||||
|
||||
const confirmations: List<Confirmation> = tx.get('confirmations')
|
||||
const firstConfirmation: Confirmation | typeof undefined = confirmations.get(0)
|
||||
if (!firstConfirmation) { throw new Error() }
|
||||
expect(firstConfirmation.get('owner')).not.toBe(undefined)
|
||||
expect(firstConfirmation.get('owner')).toEqual(firstOwner)
|
||||
expect(firstConfirmation.get('status')).toBe(true)
|
||||
expect(firstConfirmation.get('hash')).toBe(txHash)
|
||||
|
||||
const secondConfirmation: Confirmation | typeof undefined = confirmations.get(1)
|
||||
if (!secondConfirmation) { throw new Error() }
|
||||
expect(secondConfirmation.get('owner')).not.toBe(undefined)
|
||||
expect(secondConfirmation.get('owner')).toEqual(secondOwner)
|
||||
expect(secondConfirmation.get('status')).toBe(false)
|
||||
}
|
Loading…
Reference in New Issue