2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import React from 'react';
|
|
|
|
import proxyquire from 'proxyquire';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import timeout from '../../../../lib/test-timeout';
|
|
|
|
|
|
|
|
import AddRecipient from '../send-content/add-recipient/add-recipient.container';
|
|
|
|
import SendHeader from '../send-header/send-header.container';
|
|
|
|
import SendContent from '../send-content/send-content.container';
|
|
|
|
import SendFooter from '../send-footer/send-footer.container';
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
describe('Send Component', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2018-10-09 18:35:54 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const mockBasicGasEstimates = {
|
|
|
|
blockTime: 'mockBlockTime',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
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(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-11 21:33:32 +01:00
|
|
|
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),
|
2021-02-04 19:15:23 +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,
|
2021-02-04 19:15:23 +01:00
|
|
|
}).default;
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
before(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
/>,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
SendTransactionScreen.prototype.componentDidMount.resetHistory();
|
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
|
|
|
utilsMethodStubs.doesAmountErrorRequireUpdate.resetHistory();
|
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
|
|
|
propsMethodSpies.fetchBasicGasEstimates.resetHistory();
|
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
|
|
|
propsMethodSpies.updateSendErrors.resetHistory();
|
|
|
|
propsMethodSpies.updateSendTokenBalance.resetHistory();
|
|
|
|
propsMethodSpies.updateToNicknameIfNecessary.resetHistory();
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
after(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call componentDidMount', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(SendTransactionScreen.prototype.componentDidMount.calledOnce);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('componentDidMount', function () {
|
|
|
|
it('should call props.fetchBasicGasAndTimeEstimates', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.fetchBasicGasEstimates.resetHistory();
|
|
|
|
assert.strictEqual(propsMethodSpies.fetchBasicGasEstimates.callCount, 0);
|
|
|
|
wrapper.instance().componentDidMount();
|
|
|
|
assert.strictEqual(propsMethodSpies.fetchBasicGasEstimates.callCount, 1);
|
|
|
|
});
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call this.updateGas', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
|
|
|
propsMethodSpies.updateSendErrors.resetHistory();
|
|
|
|
assert.strictEqual(
|
|
|
|
SendTransactionScreen.prototype.updateGas.callCount,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
wrapper.instance().componentDidMount();
|
|
|
|
await timeout(250);
|
|
|
|
assert.strictEqual(
|
|
|
|
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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.resetSendState.resetHistory();
|
|
|
|
assert.strictEqual(propsMethodSpies.resetSendState.callCount, 0);
|
|
|
|
wrapper.instance().componentWillUnmount();
|
|
|
|
assert.strictEqual(propsMethodSpies.resetSendState.callCount, 1);
|
|
|
|
});
|
|
|
|
});
|
2018-06-29 19:19:40 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('componentDidUpdate', function () {
|
|
|
|
it('should call doesAmountErrorRequireUpdate with the expected params', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: '',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert(utilsMethodStubs.doesAmountErrorRequireUpdate.calledTwice);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2018-05-07 14:03:20 +02:00
|
|
|
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
|
|
|
},
|
2021-02-04 19:15:23 +01: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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'mockBalance',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(utilsMethodStubs.getAmountErrorObject.callCount, 0);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call getAmountErrorObject if doesAmountErrorRequireUpdate returns true', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(utilsMethodStubs.getAmountErrorObject.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2018-05-07 14:03:20 +02:00
|
|
|
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
|
|
|
},
|
2021-02-04 19:15:23 +01: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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
2018-06-29 19:19:40 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(utilsMethodStubs.getGasFeeErrorObject.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2018-06-29 19:19:40 +02:00
|
|
|
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
|
|
|
},
|
2021-02-04 19:15:23 +01: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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
2018-06-29 19:19:40 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: { address: 'mockAddress', balance: 'mockBalance' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(utilsMethodStubs.getGasFeeErrorObject.callCount, 0);
|
|
|
|
});
|
2018-06-29 19:19:40 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should not call getGasFeeErrorObject if doesAmountErrorRequireUpdate returns true but sendToken is falsy', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
|
|
|
wrapper.setProps({ sendToken: null });
|
2018-06-29 19:19:40 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(utilsMethodStubs.getGasFeeErrorObject.callCount, 0);
|
|
|
|
});
|
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 falsy', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.updateSendErrors.resetHistory();
|
|
|
|
wrapper.setProps({ sendToken: null });
|
2018-06-29 19:19:40 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(propsMethodSpies.updateSendErrors.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
propsMethodSpies.updateSendErrors.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
amount: 'mockAmountError',
|
|
|
|
gasFee: null,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.updateSendErrors.resetHistory();
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.setProps({
|
|
|
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
wrapper.instance().componentDidUpdate({
|
|
|
|
from: {
|
|
|
|
balance: 'balanceChanged',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(propsMethodSpies.updateSendErrors.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
propsMethodSpies.updateSendErrors.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
amount: 'mockAmountError',
|
|
|
|
gasFee: 'mockGasFeeError',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
|
|
|
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
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(propsMethodSpies.updateSendTokenBalance.callCount, 0);
|
|
|
|
assert.strictEqual(
|
|
|
|
SendTransactionScreen.prototype.updateGas.callCount,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
});
|
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 === loading', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ network: 'loading' });
|
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
|
|
|
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
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(propsMethodSpies.updateSendTokenBalance.callCount, 0);
|
|
|
|
assert.strictEqual(
|
|
|
|
SendTransactionScreen.prototype.updateGas.callCount,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call updateSendTokenBalance and this.updateGas with the correct params', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
|
|
|
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
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(propsMethodSpies.updateSendTokenBalance.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2018-05-07 14:03:20 +02:00
|
|
|
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
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
SendTransactionScreen.prototype.updateGas.callCount,
|
|
|
|
1,
|
|
|
|
);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2018-05-07 14:03:20 +02:00
|
|
|
SendTransactionScreen.prototype.updateGas.getCall(0).args,
|
2020-07-14 17:20:41 +02:00
|
|
|
[],
|
2021-02-04 19:15:23 +01: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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
2019-11-22 02:17:08 +01:00
|
|
|
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' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
propsMethodSpies.updateToNicknameIfNecessary.callCount,
|
|
|
|
0,
|
2021-02-04 19:15:23 +01:00
|
|
|
); // Network did not change
|
|
|
|
assert.strictEqual(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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
|
|
|
wrapper.instance().updateGas();
|
|
|
|
assert.strictEqual(propsMethodSpies.updateAndSetGasLimit.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
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
|
|
|
},
|
2021-02-04 19:15:23 +01: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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
|
|
|
wrapper.setProps({ to: 'someAddress' });
|
|
|
|
wrapper.instance().updateGas();
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2018-09-13 10:47:05 +02:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0].to,
|
2018-06-18 18:37:01 +02:00
|
|
|
'someaddress',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-06-18 18:37:01 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call updateAndSetGasLimit with to set to lowercase if passed', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
|
|
|
wrapper.instance().updateGas({ to: '0xABC' });
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0].to,
|
|
|
|
'0xabc',
|
2021-02-04 19:15:23 +01: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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(wrapper.find('.page-container').length, 1);
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render SendHeader and AddRecipient', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(wrapper.find(SendHeader).length, 1);
|
|
|
|
assert.strictEqual(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',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(wrapper.find(SendHeader).length, 1);
|
|
|
|
assert.strictEqual(wrapper.find(SendContent).length, 1);
|
|
|
|
assert.strictEqual(wrapper.find(SendFooter).length, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(wrapper.find(SendFooter).props(), {
|
2020-11-03 00:41:28 +01:00
|
|
|
history: { mockProp: 'history-abc' },
|
2021-02-04 19:15:23 +01: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',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(wrapper.find(SendContent).props().showHexData, true);
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('validate when input change', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let clock;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
clock = sinon.useFakeTimers();
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
clock.restore();
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should validate when input changes', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const instance = wrapper.instance();
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(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,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should validate when input changes and has error', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const instance = wrapper.instance();
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
clock.tick(1001);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(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,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should validate when input changes and has error on a bad network', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ network: 'bad' });
|
|
|
|
const instance = wrapper.instance();
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
clock.tick(1001);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(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,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should synchronously validate when input changes to ""', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ network: 'bad' });
|
|
|
|
const instance = wrapper.instance();
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
clock.tick(1001);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(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,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
instance.onRecipientInputChange('');
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(instance.state, {
|
2020-11-07 00:16:51 +01:00
|
|
|
internalSearch: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
query: '',
|
|
|
|
toError: '',
|
|
|
|
toWarning: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should warn when send to a known token contract address', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ address: '0x888', decimals: 18, symbol: '888' });
|
|
|
|
const instance = wrapper.instance();
|
2020-11-03 00:41:28 +01:00
|
|
|
instance.onRecipientInputChange(
|
|
|
|
'0x13cb85823f78Cff38f0B0E90D3e975b8CB3AAd64',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
clock.tick(1001);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(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',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|