2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import proxyquire from 'proxyquire';
|
|
|
|
import sinon from 'sinon';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapDispatchToProps;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
addToAddressBook: sinon.spy(),
|
|
|
|
clearSend: sinon.spy(),
|
|
|
|
signTokenTx: sinon.spy(),
|
|
|
|
signTx: sinon.spy(),
|
|
|
|
updateTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-05 17:11:53 +02:00
|
|
|
const utilsStubs = {
|
|
|
|
addressIsNew: sinon.stub().returns(true),
|
2019-02-25 19:16:23 +01:00
|
|
|
constructTxParams: sinon.stub().returns({
|
|
|
|
value: 'mockAmount',
|
|
|
|
}),
|
2018-05-05 17:11:53 +02:00
|
|
|
constructUpdatedTx: sinon.stub().returns('mockConstructedUpdatedTxParams'),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-05 17:11:53 +02:00
|
|
|
|
|
|
|
proxyquire('../send-footer.container.js', {
|
|
|
|
'react-redux': {
|
2020-01-10 15:23:54 +01:00
|
|
|
connect: (_, md) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToProps = md;
|
|
|
|
return () => ({});
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
},
|
2019-04-17 21:15:13 +02:00
|
|
|
'../../../store/actions': actionSpies,
|
2020-05-04 21:06:28 +02:00
|
|
|
'../../../selectors': {
|
2018-05-05 17:11:53 +02:00
|
|
|
getGasLimit: (s) => `mockGasLimit:${s}`,
|
|
|
|
getGasPrice: (s) => `mockGasPrice:${s}`,
|
|
|
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendToken: (s) => `mockSendToken:${s}`,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendAmount: (s) => `mockAmount:${s}`,
|
|
|
|
getSendEditingTransactionId: (s) => `mockEditingTransactionId:${s}`,
|
|
|
|
getSendFromObject: (s) => `mockFromObject:${s}`,
|
|
|
|
getSendTo: (s) => `mockTo:${s}`,
|
2019-08-08 20:45:30 +02:00
|
|
|
getSendToNickname: (s) => `mockToNickname:${s}`,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendToAccounts: (s) => `mockToAccounts:${s}`,
|
|
|
|
getTokenBalance: (s) => `mockTokenBalance:${s}`,
|
2018-07-17 00:50:26 +02:00
|
|
|
getSendHexData: (s) => `mockHexData:${s}`,
|
2018-05-05 17:11:53 +02:00
|
|
|
getUnapprovedTxs: (s) => `mockUnapprovedTxs:${s}`,
|
2019-03-05 16:45:01 +01:00
|
|
|
getSendErrors: (s) => `mockSendErrors:${s}`,
|
2020-05-04 17:22:34 +02:00
|
|
|
isSendFormInError: (s) => `mockInError:${s}`,
|
2020-11-03 00:41:28 +01:00
|
|
|
getRenderableEstimateDataForSmallButtonsFromGWEI: (s) => [
|
|
|
|
{ gasEstimateType: `mockGasEstimateType:${s}` },
|
|
|
|
],
|
2019-04-05 06:02:47 +02:00
|
|
|
getDefaultActiveButtonIndex: () => 0,
|
|
|
|
},
|
2020-05-04 21:06:28 +02:00
|
|
|
'./send-footer.utils': utilsStubs,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('send-footer container', function () {
|
|
|
|
describe('mapDispatchToProps()', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let dispatchSpy;
|
|
|
|
let mapDispatchToPropsObject;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatchSpy = sinon.spy();
|
|
|
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('clearSend()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.clearSend();
|
|
|
|
assert(dispatchSpy.calledOnce);
|
|
|
|
assert(actionSpies.clearSend.calledOnce);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('sign()', function () {
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should dispatch a signTokenTx action if sendToken is defined', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.sign({
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: {
|
2018-05-05 17:11:53 +02:00
|
|
|
address: '0xabc',
|
|
|
|
},
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
utilsStubs.constructTxParams.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
sendToken: {
|
|
|
|
address: '0xabc',
|
|
|
|
},
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(actionSpies.signTokenTx.getCall(0).args, [
|
2020-11-03 00:41:28 +01:00
|
|
|
'0xabc',
|
|
|
|
'mockTo',
|
|
|
|
'mockAmount',
|
|
|
|
{ value: 'mockAmount' },
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should dispatch a sign action if sendToken is not defined', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
utilsStubs.constructTxParams.resetHistory();
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.sign({
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
utilsStubs.constructTxParams.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
sendToken: undefined,
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(actionSpies.signTx.getCall(0).args, [
|
2020-11-03 00:41:28 +01:00
|
|
|
{ value: 'mockAmount' },
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('update()', function () {
|
|
|
|
it('should dispatch an updateTransaction action', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.update({
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
editingTransactionId: 'mockEditingTransactionId',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockAddress' },
|
2018-05-05 17:11:53 +02:00
|
|
|
unapprovedTxs: 'mockUnapprovedTxs',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
utilsStubs.constructUpdatedTx.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
editingTransactionId: 'mockEditingTransactionId',
|
|
|
|
sendToken: { address: 'mockAddress' },
|
|
|
|
unapprovedTxs: 'mockUnapprovedTxs',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
actionSpies.updateTransaction.getCall(0).args[0],
|
|
|
|
'mockConstructedUpdatedTxParams',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('addToAddressBookIfNew()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
mapDispatchToPropsObject.addToAddressBookIfNew(
|
|
|
|
'mockNewAddress',
|
|
|
|
'mockToAccounts',
|
|
|
|
'mockNickname',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
utilsStubs.addressIsNew.getCall(0).args[0],
|
|
|
|
'mockToAccounts',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(actionSpies.addToAddressBook.getCall(0).args, [
|
2020-11-03 00:41:28 +01:00
|
|
|
'0xmockNewAddress',
|
|
|
|
'mockNickname',
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|