2018-05-07 14:03:20 +02:00
|
|
|
import assert from 'assert'
|
2020-08-18 21:18:25 +02:00
|
|
|
import React from 'react'
|
2018-05-07 14:03:20 +02:00
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
import { shallow } from 'enzyme'
|
|
|
|
import sinon from 'sinon'
|
2019-04-17 21:15:13 +02:00
|
|
|
import timeout from '../../../../lib/test-timeout'
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
import AddRecipient from '../send-content/add-recipient/add-recipient.container'
|
2018-05-07 14:03:20 +02:00
|
|
|
import SendHeader from '../send-header/send-header.container'
|
2019-07-31 21:56:44 +02:00
|
|
|
import SendContent from '../send-content/send-content.container'
|
2018-05-07 14:03:20 +02:00
|
|
|
import SendFooter from '../send-footer/send-footer.container'
|
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
describe('Send Component', function () {
|
|
|
|
let wrapper
|
2018-10-09 18:35:54 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const mockBasicGasEstimates = {
|
|
|
|
blockTime: 'mockBlockTime',
|
|
|
|
}
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const propsMethodSpies = {
|
|
|
|
updateAndSetGasLimit: sinon.spy(),
|
|
|
|
updateSendErrors: sinon.spy(),
|
|
|
|
updateSendTokenBalance: sinon.spy(),
|
|
|
|
resetSendState: sinon.spy(),
|
2020-11-03 00:41:28 +01:00
|
|
|
fetchBasicGasEstimates: sinon
|
|
|
|
.stub()
|
|
|
|
.returns(Promise.resolve(mockBasicGasEstimates)),
|
2020-02-11 21:33:32 +01:00
|
|
|
fetchGasEstimates: sinon.spy(),
|
|
|
|
updateToNicknameIfNecessary: sinon.spy(),
|
|
|
|
}
|
|
|
|
const utilsMethodStubs = {
|
|
|
|
getAmountErrorObject: sinon.stub().returns({ amount: 'mockAmountError' }),
|
|
|
|
getGasFeeErrorObject: sinon.stub().returns({ gasFee: 'mockGasFeeError' }),
|
2020-11-03 00:41:28 +01:00
|
|
|
doesAmountErrorRequireUpdate: sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((obj) => obj.balance !== obj.prevBalance),
|
2020-02-11 21:33:32 +01:00
|
|
|
}
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const SendTransactionScreen = proxyquire('../send.component.js', {
|
|
|
|
'./send.utils': utilsMethodStubs,
|
|
|
|
}).default
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
before(function () {
|
|
|
|
sinon.spy(SendTransactionScreen.prototype, 'componentDidMount')
|
|
|
|
sinon.spy(SendTransactionScreen.prototype, 'updateGas')
|
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<SendTransactionScreen
|
|
|
|
amount="mockAmount"
|
|
|
|
blockGasLimit="mockBlockGasLimit"
|
|
|
|
conversionRate={10}
|
|
|
|
editingTransactionId="mockEditingTransactionId"
|
|
|
|
fetchBasicGasEstimates={propsMethodSpies.fetchBasicGasEstimates}
|
|
|
|
fetchGasEstimates={propsMethodSpies.fetchGasEstimates}
|
2020-11-03 00:41:28 +01:00
|
|
|
from={{ address: 'mockAddress', balance: 'mockBalance' }}
|
2019-12-03 17:35:44 +01:00
|
|
|
gasLimit="mockGasLimit"
|
|
|
|
gasPrice="mockGasPrice"
|
|
|
|
gasTotal="mockGasTotal"
|
2019-12-03 21:50:55 +01:00
|
|
|
history={{ mockProp: 'history-abc' }}
|
2019-12-03 17:35:44 +01:00
|
|
|
network="3"
|
|
|
|
primaryCurrency="mockPrimaryCurrency"
|
|
|
|
selectedAddress="mockSelectedAddress"
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken={{ address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }}
|
2019-12-03 17:35:44 +01:00
|
|
|
showHexData
|
|
|
|
tokenBalance="mockTokenBalance"
|
|
|
|
tokenContract={{ method: 'mockTokenMethod' }}
|
|
|
|
updateAndSetGasLimit={propsMethodSpies.updateAndSetGasLimit}
|
2020-08-14 13:47:02 +02:00
|
|
|
qrCodeDetected={() => undefined}
|
|
|
|
scanQrCode={() => undefined}
|
|
|
|
updateSendEnsResolution={() => undefined}
|
|
|
|
updateSendEnsResolutionError={() => undefined}
|
2019-12-03 17:35:44 +01:00
|
|
|
updateSendErrors={propsMethodSpies.updateSendErrors}
|
2020-08-14 13:47:02 +02:00
|
|
|
updateSendTo={() => undefined}
|
2019-12-03 17:35:44 +01:00
|
|
|
updateSendTokenBalance={propsMethodSpies.updateSendTokenBalance}
|
|
|
|
resetSendState={propsMethodSpies.resetSendState}
|
2020-11-03 00:41:28 +01:00
|
|
|
updateToNicknameIfNecessary={
|
|
|
|
propsMethodSpies.updateToNicknameIfNecessary
|
|
|
|
}
|
|
|
|
/>,
|
|
|
|
)
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
SendTransactionScreen.prototype.componentDidMount.resetHistory()
|
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory()
|
|
|
|
utilsMethodStubs.doesAmountErrorRequireUpdate.resetHistory()
|
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory()
|
2018-06-29 19:19:40 +02:00
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory()
|
2018-10-09 18:35:54 +02:00
|
|
|
propsMethodSpies.fetchBasicGasEstimates.resetHistory()
|
2018-09-13 10:47:05 +02:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
propsMethodSpies.updateSendErrors.resetHistory()
|
|
|
|
propsMethodSpies.updateSendTokenBalance.resetHistory()
|
2019-11-22 02:17:08 +01:00
|
|
|
propsMethodSpies.updateToNicknameIfNecessary.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
after(function () {
|
|
|
|
sinon.restore()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call componentDidMount', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
assert(SendTransactionScreen.prototype.componentDidMount.calledOnce)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('componentDidMount', function () {
|
|
|
|
it('should call props.fetchBasicGasAndTimeEstimates', function () {
|
2018-10-09 18:35:54 +02:00
|
|
|
propsMethodSpies.fetchBasicGasEstimates.resetHistory()
|
|
|
|
assert.equal(propsMethodSpies.fetchBasicGasEstimates.callCount, 0)
|
2018-08-16 14:28:27 +02:00
|
|
|
wrapper.instance().componentDidMount()
|
2018-10-09 18:35:54 +02:00
|
|
|
assert.equal(propsMethodSpies.fetchBasicGasEstimates.callCount, 1)
|
2018-08-16 14:28:27 +02:00
|
|
|
})
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call this.updateGas', async function () {
|
2018-09-13 10:47:05 +02:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory()
|
|
|
|
propsMethodSpies.updateSendErrors.resetHistory()
|
|
|
|
assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 0)
|
|
|
|
wrapper.instance().componentDidMount()
|
2018-10-09 18:35:54 +02:00
|
|
|
await timeout(250)
|
|
|
|
assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 1)
|
|
|
|
})
|
2018-08-16 14:28:27 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('componentWillUnmount', function () {
|
|
|
|
it('should call this.props.resetSendState', function () {
|
2018-06-29 19:19:40 +02:00
|
|
|
propsMethodSpies.resetSendState.resetHistory()
|
|
|
|
assert.equal(propsMethodSpies.resetSendState.callCount, 0)
|
|
|
|
wrapper.instance().componentWillUnmount()
|
|
|
|
assert.equal(propsMethodSpies.resetSendState.callCount, 1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('componentDidUpdate', function () {
|
|
|
|
it('should call doesAmountErrorRequireUpdate with the expected params', function () {
|
2018-05-30 18:40:30 +02:00
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: '',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert(utilsMethodStubs.doesAmountErrorRequireUpdate.calledOnce)
|
|
|
|
assert.deepEqual(
|
|
|
|
utilsMethodStubs.doesAmountErrorRequireUpdate.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
balance: 'mockBalance',
|
|
|
|
gasTotal: 'mockGasTotal',
|
|
|
|
prevBalance: '',
|
|
|
|
prevGasTotal: undefined,
|
|
|
|
prevTokenBalance: undefined,
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken: {
|
|
|
|
address: 'mockTokenAddress',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'TST',
|
|
|
|
},
|
2018-05-07 14:03:20 +02:00
|
|
|
tokenBalance: 'mockTokenBalance',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2018-05-07 14:03:20 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should not call getAmountErrorObject if doesAmountErrorRequireUpdate returns false', function () {
|
2018-05-30 18:40:30 +02:00
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'mockBalance',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equal(utilsMethodStubs.getAmountErrorObject.callCount, 0)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call getAmountErrorObject if doesAmountErrorRequireUpdate returns true', function () {
|
2018-05-30 18:40:30 +02:00
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equal(utilsMethodStubs.getAmountErrorObject.callCount, 1)
|
|
|
|
assert.deepEqual(
|
|
|
|
utilsMethodStubs.getAmountErrorObject.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
amount: 'mockAmount',
|
|
|
|
balance: 'mockBalance',
|
|
|
|
conversionRate: 10,
|
|
|
|
gasTotal: 'mockGasTotal',
|
|
|
|
primaryCurrency: 'mockPrimaryCurrency',
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken: {
|
|
|
|
address: 'mockTokenAddress',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'TST',
|
|
|
|
},
|
2018-05-07 14:03:20 +02:00
|
|
|
tokenBalance: 'mockTokenBalance',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2018-05-07 14:03:20 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should call getGasFeeErrorObject if doesAmountErrorRequireUpdate returns true and sendToken is truthy', function () {
|
2018-06-29 19:19:40 +02:00
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory()
|
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equal(utilsMethodStubs.getGasFeeErrorObject.callCount, 1)
|
|
|
|
assert.deepEqual(
|
|
|
|
utilsMethodStubs.getGasFeeErrorObject.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
balance: 'mockBalance',
|
|
|
|
conversionRate: 10,
|
|
|
|
gasTotal: 'mockGasTotal',
|
|
|
|
primaryCurrency: 'mockPrimaryCurrency',
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken: {
|
|
|
|
address: 'mockTokenAddress',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'TST',
|
|
|
|
},
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2018-06-29 19:19:40 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should not call getGasFeeErrorObject if doesAmountErrorRequireUpdate returns false', function () {
|
2018-06-29 19:19:40 +02:00
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory()
|
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: { address: 'mockAddress', balance: 'mockBalance' },
|
|
|
|
})
|
|
|
|
assert.equal(utilsMethodStubs.getGasFeeErrorObject.callCount, 0)
|
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should not call getGasFeeErrorObject if doesAmountErrorRequireUpdate returns true but sendToken is falsy', function () {
|
2018-06-29 19:19:40 +02:00
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory()
|
2020-05-29 19:46:10 +02:00
|
|
|
wrapper.setProps({ sendToken: null })
|
2018-06-29 19:19:40 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equal(utilsMethodStubs.getGasFeeErrorObject.callCount, 0)
|
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should call updateSendErrors with the expected params if sendToken is falsy', function () {
|
2018-06-29 19:19:40 +02:00
|
|
|
propsMethodSpies.updateSendErrors.resetHistory()
|
2020-05-29 19:46:10 +02:00
|
|
|
wrapper.setProps({ sendToken: null })
|
2018-06-29 19:19:40 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equal(propsMethodSpies.updateSendErrors.callCount, 1)
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(propsMethodSpies.updateSendErrors.getCall(0).args[0], {
|
|
|
|
amount: 'mockAmountError',
|
|
|
|
gasFee: null,
|
|
|
|
})
|
2018-06-29 19:19:40 +02:00
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should call updateSendErrors with the expected params if sendToken is truthy', function () {
|
2018-05-30 18:40:30 +02:00
|
|
|
propsMethodSpies.updateSendErrors.resetHistory()
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.setProps({
|
|
|
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' },
|
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equal(propsMethodSpies.updateSendErrors.callCount, 1)
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(propsMethodSpies.updateSendErrors.getCall(0).args[0], {
|
|
|
|
amount: 'mockAmountError',
|
|
|
|
gasFee: 'mockGasFeeError',
|
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should not call updateSendTokenBalance or this.updateGas if network === prevNetwork', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory()
|
2018-05-25 03:00:07 +02:00
|
|
|
propsMethodSpies.updateSendTokenBalance.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
network: '3',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }, // Make sure not to hit updateGas when changing asset
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
assert.equal(propsMethodSpies.updateSendTokenBalance.callCount, 0)
|
|
|
|
assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 0)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should not call updateSendTokenBalance or this.updateGas if network === loading', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.setProps({ network: 'loading' })
|
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory()
|
|
|
|
propsMethodSpies.updateSendTokenBalance.resetHistory()
|
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
network: '3',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }, // Make sure not to hit updateGas when changing asset
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
assert.equal(propsMethodSpies.updateSendTokenBalance.callCount, 0)
|
|
|
|
assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 0)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call updateSendTokenBalance and this.updateGas with the correct params', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory()
|
2018-05-25 03:00:07 +02:00
|
|
|
propsMethodSpies.updateSendTokenBalance.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
|
|
|
network: '2',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }, // Make sure not to hit updateGas when changing asset
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
assert.equal(propsMethodSpies.updateSendTokenBalance.callCount, 1)
|
|
|
|
assert.deepEqual(
|
|
|
|
propsMethodSpies.updateSendTokenBalance.getCall(0).args[0],
|
|
|
|
{
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken: {
|
|
|
|
address: 'mockTokenAddress',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'TST',
|
|
|
|
}, // Make sure not to hit updateGas when changing asset
|
2019-11-22 02:17:08 +01:00
|
|
|
tokenContract: { method: 'mockTokenMethod' },
|
2018-05-07 14:03:20 +02:00
|
|
|
address: 'mockAddress',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2018-05-07 14:03:20 +02:00
|
|
|
)
|
|
|
|
assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 1)
|
|
|
|
assert.deepEqual(
|
|
|
|
SendTransactionScreen.prototype.updateGas.getCall(0).args,
|
2020-07-14 17:20:41 +02:00
|
|
|
[],
|
2018-05-07 14:03:20 +02:00
|
|
|
)
|
|
|
|
})
|
2019-11-22 02:17:08 +01:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should call updateGas when sendToken.address is changed', function () {
|
2019-11-22 02:17:08 +01:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory()
|
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory()
|
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balancedChanged',
|
|
|
|
},
|
|
|
|
network: '3', // Make sure not to hit updateGas when changing network
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'newSelectedToken' },
|
2019-11-22 02:17:08 +01:00
|
|
|
})
|
|
|
|
assert.equal(propsMethodSpies.updateToNicknameIfNecessary.callCount, 0) // Network did not change
|
|
|
|
assert.equal(propsMethodSpies.updateAndSetGasLimit.callCount, 1)
|
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateGas', function () {
|
|
|
|
it('should call updateAndSetGasLimit with the correct params if no to prop is passed', function () {
|
2018-09-13 10:47:05 +02:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory()
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().updateGas()
|
2018-09-13 10:47:05 +02:00
|
|
|
assert.equal(propsMethodSpies.updateAndSetGasLimit.callCount, 1)
|
2018-05-07 14:03:20 +02:00
|
|
|
assert.deepEqual(
|
2018-09-13 10:47:05 +02:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0],
|
2018-05-07 14:03:20 +02:00
|
|
|
{
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit: 'mockBlockGasLimit',
|
2018-05-07 14:03:20 +02:00
|
|
|
editingTransactionId: 'mockEditingTransactionId',
|
|
|
|
gasLimit: 'mockGasLimit',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
selectedAddress: 'mockSelectedAddress',
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken: {
|
|
|
|
address: 'mockTokenAddress',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'TST',
|
|
|
|
},
|
2018-06-18 18:37:01 +02:00
|
|
|
to: '',
|
2018-05-23 18:43:25 +02:00
|
|
|
value: 'mockAmount',
|
2018-09-27 15:46:24 +02:00
|
|
|
data: undefined,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2018-05-07 14:03:20 +02:00
|
|
|
)
|
|
|
|
})
|
2018-05-23 18:43:25 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call updateAndSetGasLimit with the correct params if a to prop is passed', function () {
|
2018-09-13 10:47:05 +02:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory()
|
2018-06-18 18:37:01 +02:00
|
|
|
wrapper.setProps({ to: 'someAddress' })
|
|
|
|
wrapper.instance().updateGas()
|
|
|
|
assert.equal(
|
2018-09-13 10:47:05 +02:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0].to,
|
2018-06-18 18:37:01 +02:00
|
|
|
'someaddress',
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call updateAndSetGasLimit with to set to lowercase if passed', function () {
|
2018-09-13 10:47:05 +02:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory()
|
2018-05-23 18:43:25 +02:00
|
|
|
wrapper.instance().updateGas({ to: '0xABC' })
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0].to,
|
|
|
|
'0xabc',
|
|
|
|
)
|
2018-05-23 18:43:25 +02:00
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
|
|
|
it('should render a page-container class', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
assert.equal(wrapper.find('.page-container').length, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render SendHeader and AddRecipient', function () {
|
2018-05-07 14:03:20 +02:00
|
|
|
assert.equal(wrapper.find(SendHeader).length, 1)
|
2019-07-31 21:56:44 +02:00
|
|
|
assert.equal(wrapper.find(AddRecipient).length, 1)
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should pass the history prop to SendHeader and SendFooter', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
|
|
|
})
|
|
|
|
assert.equal(wrapper.find(SendHeader).length, 1)
|
|
|
|
assert.equal(wrapper.find(SendContent).length, 1)
|
|
|
|
assert.equal(wrapper.find(SendFooter).length, 1)
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(wrapper.find(SendFooter).props(), {
|
|
|
|
history: { mockProp: 'history-abc' },
|
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
2018-08-16 09:43:13 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should pass showHexData to SendContent', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({
|
|
|
|
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
|
|
|
})
|
2018-08-16 09:43:13 +02:00
|
|
|
assert.equal(wrapper.find(SendContent).props().showHexData, true)
|
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('validate when input change', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
let clock
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
clock = sinon.useFakeTimers()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
clock.restore()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should validate when input changes', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
const instance = wrapper.instance()
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
assert.deepEqual(instance.state, {
|
2020-11-07 00:16:51 +01:00
|
|
|
internalSearch: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
query: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
|
|
|
toError: null,
|
|
|
|
toWarning: null,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should validate when input changes and has error', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
const instance = wrapper.instance()
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
clock.tick(1001)
|
|
|
|
assert.deepEqual(instance.state, {
|
2020-11-07 00:16:51 +01:00
|
|
|
internalSearch: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
|
|
|
toError: 'invalidAddressRecipient',
|
|
|
|
toWarning: null,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should validate when input changes and has error on a bad network', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({ network: 'bad' })
|
|
|
|
const instance = wrapper.instance()
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
clock.tick(1001)
|
|
|
|
assert.deepEqual(instance.state, {
|
2020-11-07 00:16:51 +01:00
|
|
|
internalSearch: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
|
|
|
toError: 'invalidAddressRecipientNotEthNetwork',
|
|
|
|
toWarning: null,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should synchronously validate when input changes to ""', function () {
|
2019-07-31 21:56:44 +02:00
|
|
|
wrapper.setProps({ network: 'bad' })
|
|
|
|
const instance = wrapper.instance()
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
clock.tick(1001)
|
|
|
|
assert.deepEqual(instance.state, {
|
2020-11-07 00:16:51 +01:00
|
|
|
internalSearch: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
|
|
|
toError: 'invalidAddressRecipientNotEthNetwork',
|
|
|
|
toWarning: null,
|
|
|
|
})
|
|
|
|
|
|
|
|
instance.onRecipientInputChange('')
|
|
|
|
assert.deepEqual(instance.state, {
|
2020-11-07 00:16:51 +01:00
|
|
|
internalSearch: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
query: '',
|
|
|
|
toError: '',
|
|
|
|
toWarning: '',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should warn when send to a known token contract address', function () {
|
2019-11-22 02:17:08 +01:00
|
|
|
wrapper.setProps({ address: '0x888', decimals: 18, symbol: '888' })
|
2019-07-31 21:56:44 +02:00
|
|
|
const instance = wrapper.instance()
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x13cb85823f78Cff38f0B0E90D3e975b8CB3AAd64',
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
clock.tick(1001)
|
|
|
|
assert.deepEqual(instance.state, {
|
2020-11-07 00:16:51 +01:00
|
|
|
internalSearch: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
query: '0x13cb85823f78Cff38f0B0E90D3e975b8CB3AAd64',
|
|
|
|
toError: null,
|
|
|
|
toWarning: 'knownAddressRecipient',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-05-07 14:03:20 +02:00
|
|
|
})
|