2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import * as actions from '../../../ui/app/store/actions';
|
|
|
|
import * as actionConstants from '../../../ui/app/store/actionConstants';
|
2016-04-30 00:53:29 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const middlewares = [thunk];
|
|
|
|
const mockStore = configureMockStore(middlewares);
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2018-07-08 03:53:00 +02:00
|
|
|
describe('tx confirmation screen', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const txId = 1457634084250832;
|
2018-07-08 03:53:00 +02:00
|
|
|
const initialState = {
|
2020-11-03 00:41:28 +01:00
|
|
|
appState: {},
|
2018-07-08 03:53:00 +02:00
|
|
|
metamask: {
|
|
|
|
unapprovedTxs: {
|
|
|
|
[txId]: {
|
|
|
|
id: txId,
|
|
|
|
status: 'unconfirmed',
|
|
|
|
time: 1457634084250,
|
2017-05-04 23:35:10 +02:00
|
|
|
},
|
2018-07-08 03:53:00 +02:00
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-08 03:53:00 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore(initialState);
|
2018-07-08 03:53:00 +02:00
|
|
|
|
|
|
|
describe('cancelTx', function () {
|
2020-02-11 17:51:13 +01:00
|
|
|
it('creates COMPLETED_TX with the cancelled transaction ID', async function () {
|
2018-07-08 03:53:00 +02:00
|
|
|
actions._setBackgroundConnection({
|
2020-11-03 00:41:28 +01:00
|
|
|
approveTransaction(_, cb) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb(new Error('An error!'));
|
2019-11-20 01:03:20 +01:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
cancelTransaction(_, cb) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb();
|
2019-11-20 01:03:20 +01:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
getState(cb) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb(null, {});
|
2019-11-20 01:03:20 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.cancelTx({ id: txId }));
|
|
|
|
const storeActions = store.getActions();
|
2020-11-03 00:41:28 +01:00
|
|
|
const completedTxAction = storeActions.find(
|
|
|
|
({ type }) => type === actionConstants.COMPLETED_TX,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const { id } = completedTxAction.value;
|
|
|
|
assert.equal(id, txId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|