Daniel Kmak 985ea0fb89 Ethereum Alarm Clock Integration (#1343)
* [FEATURE] Initial EAC integration.

* Title and explanation

* [FEATURE] Move the Schedule Payment to the main tab.

* [FEATURE] TimeBounty slider.

* [FEATURE] Move to main menu.

* [FEATURE] Redirection to the DApp for details.

* [FEATURE] Timestamp scheduling

* Scheduling: Basic date and time widget

* Linting fixes

* Moved the datetime field to new tab

* Fixed push errors

* Added missing specs

* Undid unintentional UI change

* Fixed some failing tests

* Ignore datetime parameter when checking if a transaction is full

* Added a date selector widget and renamed ScheduleTimestamp to ScheduleDate

* Marked componentDidMount

* Initialized Pikaday

* Revert "Initialized Pikaday"

This reverts commit 4e5bf5b2b882f236f5977400abf9b7092cbd1592.

* Revert "Marked componentDidMount"

This reverts commit 85d52192ac58f4b6ca9219e702f7390cd27e582f.

* Revert "Added a date selector widget and renamed ScheduleTimestamp to ScheduleDate"

This reverts commit aaad0ac9b565a78d1bfc631754160919fd38a59b.

* Converted the date picker into a datetime picker

* Added decent styling to the datetimepicker

* Added validation to the datetime picker

* Fixed prepush errors for scheduling timestamp

* Adjusted validation logic scheduling timestamp

* [FEATURE] Move scheduling to main tab.

* [FEATURE] Timezone selector

* [FEATURE] Scheduling: Timezone selector

* Removed zombie files

* [FEATURE] Reimplement Time Bounty.

* [FEATURE] Time/block selector

* [FEATURE] Add Window Size field.

* [FEATURE] Time/block switch functionality

* Implemented time/block switcher fuctionality

* [FEATURE] Add Schedule Gas Price field.

* [FEATURE] Scheduling toggle

* [FEATURE] Add basic styling and network check.

* [FEATURE] Add Schedule Gas Limit field

* [FEATURE] "Scheduled" button styling

* Reordered, renamed and centered scheduling elements

* Added the toggle button styling

* Class -> ClassName

* [FEATURE] Add Deposit field

*  [FEATURE] Move scheduling code into one directory

* [FIX] Scheduling responsiveness

* [FIX] Datetime picker not working on md screens

* [FEATURE] Timestamp Scheduling basic functionality

* [FIX] Fix data serialization.

* [FEATURE] Timezone inclusion

* [FEATURE] Add ChronoLogic logo.

* [FEATURE] Add link to image.

* [FIX] Update CSS of logo.

* [FEATURE] Default Window Size

* [FEATURE] Modified Help component to enable acting as a tooltip

* [FEATURE] Call contract to validate scheduling params

* [FIX] Change moment import to fix tests

* [FEATURE] Gas estimation for scheduling

* [FEATURE] Additional validation

* [FEATURE] UI changes and descriptions

* [FEATURE] Add tooltip to window and fix fee display.

* [FIX] Fix ethereumjs-abi dependency.

* [FEATURE] Hide scheduling when sending tokens.

* [FIX] Improved styling datetime picker

* [FEATURE] Add Redux state for scheduling

* [FEATURE] Create Toggle component, Share code between components

* [FEATURE] Use Tooltip component for help.

* [FEATURE] Better datetime picker

* [FEATURE] Remove fee

* Trigger mycryptobuild

* [FIX] Timestamp scheduling - Validation match

* [FIX] EAC integration touchups

* [FIX] Code review fixes

* [FIX] Window Size type

* [FIX] Type fixes.

* [FIX] Make tooltips only show on icons + resposiveness fixes

* [FIX] Break tooltips into more lines

* [FIX] Remove unnecessary code.

* [FIX] Remove unnecessary code.

* [FIX] Remove unnecessary types declaration.

* [FIX] Fee class names
2018-04-14 17:21:33 -05:00

234 lines
6.8 KiB
TypeScript

import { getWeb3Tx, getSignedTx, getTransactionStatus } from 'selectors/transaction';
import { select, call, put } from 'redux-saga/effects';
import {
broadcastTransactionFailed,
broadcastTransactionSucceeded,
broadcastTransactionQueued,
reset
} from 'actions/transaction';
import { bufferToHex } from 'ethereumjs-util';
import { showNotification } from 'actions/notifications';
import React from 'react';
import { getNetworkConfig } from 'selectors/config';
import TransactionSucceeded from 'components/ExtendedNotifications/TransactionSucceeded';
import { computeIndexingHash } from 'libs/transaction';
import { cloneableGenerator } from 'redux-saga/utils';
/* tslint:disable */
import 'actions/transaction';
import 'selectors/transaction'; //throws if not imported
/* tslint:enable */
import {
broadcastTransactionWrapper,
getSerializedTxAndIndexingHash,
shouldBroadcastTransaction
} from 'sagas/transaction/broadcast/helpers';
import { isSchedulingEnabled } from 'selectors/schedule/fields';
describe('broadcastTransactionWrapper*', () => {
const indexingHash = 'indexingHash';
const serializedTransaction = new Buffer('serializedTransaction');
const shouldBroadcast = true;
const stringTx = 'stringTx';
const broadcastedHash: any = 'broadcastedHash';
const network: any = {
blockExplorer: 'blockExplorer'
};
let random: () => number;
const func: any = () => undefined;
const action: any = {};
const gens: any = {};
gens.gen = cloneableGenerator(broadcastTransactionWrapper(func))(action);
beforeAll(() => {
random = Math.random;
Math.random = () => 0.001;
});
afterAll(() => {
Math.random = random;
});
it('should call getSerializedTxAndIndexingHash with action', () => {
expect(gens.gen.next().value).toEqual(call(getSerializedTxAndIndexingHash, action));
});
it('should call shouldBroadcastTransaction with indexingHash', () => {
expect(
gens.gen.next({
indexingHash,
serializedTransaction
}).value
).toEqual(call(shouldBroadcastTransaction, indexingHash));
});
it('should handle exceptions', () => {
gens.clone1 = gens.gen.clone();
const error = { message: 'message' };
expect(gens.clone1.throw(error).value).toEqual(
put(broadcastTransactionFailed({ indexingHash }))
);
expect(gens.clone1.next().value).toEqual(put(showNotification('danger', error.message)));
expect(gens.clone1.next().done).toEqual(true);
});
it('should put showNotification & reset if !shouldBroadcast', () => {
gens.clone2 = gens.gen.clone();
expect(gens.clone2.next().value).toEqual(
put(
showNotification(
'warning',
'TxHash identical: This transaction has already been broadcasted or is broadcasting'
)
)
);
expect(gens.clone2.next().value).toEqual(put(reset()));
expect(gens.clone2.next(!shouldBroadcast).done).toEqual(true);
});
it('should put broadcastTransactionQueued', () => {
expect(gens.gen.next(shouldBroadcast).value).toEqual(
put(
broadcastTransactionQueued({
indexingHash,
serializedTransaction
})
)
);
});
it('should call bufferToHex with serializedTransactioin', () => {
expect(gens.gen.next().value).toEqual(call(bufferToHex, serializedTransaction));
});
it('should call func with stringTx', () => {
expect(gens.gen.next(stringTx).value).toEqual(call(func, stringTx));
});
it('should put broadcastTransactionSucceeded', () => {
expect(gens.gen.next(broadcastedHash).value).toEqual(
put(
broadcastTransactionSucceeded({
indexingHash,
broadcastedHash
})
)
);
});
it('select getNetworkConfig', () => {
expect(gens.gen.next().value).toEqual(select(getNetworkConfig));
});
it('select isSchedulingEnabled', () => {
expect(gens.gen.next(network).value).toEqual(select(isSchedulingEnabled));
});
it('should put showNotification', () => {
expect(gens.gen.next(false).value).toEqual(
put(
showNotification(
'success',
<TransactionSucceeded
txHash={broadcastedHash}
blockExplorer={network.blockExplorer}
scheduling={false}
/>,
Infinity
)
)
);
});
it('should be done', () => {
expect(gens.gen.next().done).toEqual(true);
});
});
describe('shouldBroadCastTransaction*', () => {
const indexingHash = 'indexingHash';
const existingTxIsBroadcasting: any = {
isBroadcasting: true
};
const existingTxBroadcastSuccessful: any = {
broadcastSuccessful: true
};
const existingTxFalse: any = false;
const gens: any = {};
gens.gen = cloneableGenerator(shouldBroadcastTransaction)(indexingHash);
it('should select getTransactionStats with indexingHash', () => {
expect(gens.gen.next().value).toEqual(select(getTransactionStatus, indexingHash));
});
it('should return false when isBroadcasting', () => {
gens.clone1 = gens.gen.clone();
expect(gens.clone1.next(existingTxIsBroadcasting).value).toEqual(false);
});
it('should return false when broadcastSuccessful', () => {
gens.clone2 = gens.gen.clone();
expect(gens.clone2.next(existingTxBroadcastSuccessful).value).toEqual(false);
});
it('should return true when there is no existingTx', () => {
gens.gen = gens.gen.clone();
expect(gens.gen.next(existingTxFalse).value).toEqual(true);
});
it('should be done', () => {
expect(gens.gen.next().done).toEqual(true);
});
});
describe('getSerializedTxAndIndexingHash*', () => {
const web3Req: any = {
type: 'BROADCAST_WEB3_TRANSACTION_REQUESTED'
};
const notWeb3Req: any = {
type: 'NOT_WEB3_TRANSACTION_REQUEST'
};
const serializedTransaction: any = true;
const indexingHash = 'indexingHash';
const gens: any = {};
gens.gen1 = cloneableGenerator(getSerializedTxAndIndexingHash)(web3Req);
const gen2 = getSerializedTxAndIndexingHash(notWeb3Req);
it('should select getWeb3Tx', () => {
expect(gens.gen1.next().value).toEqual(select(getWeb3Tx));
});
it('should select getSignedTx', () => {
expect(gen2.next().value).toEqual(select(getSignedTx));
});
it('should throw error if !serializedTransaction', () => {
gens.clone1 = gens.gen1.clone();
expect(() => gens.clone1.next(!serializedTransaction)).toThrowError(
'Can not broadcast: tx does not exist'
);
});
it('should call computeIndexingHash', () => {
expect(gens.gen1.next(serializedTransaction).value).toEqual(
call(computeIndexingHash, serializedTransaction)
);
});
it('should return correctly', () => {
expect(gens.gen1.next(indexingHash).value).toEqual({
serializedTransaction,
indexingHash
});
});
it('should be done', () => {
expect(gens.gen1.next().done).toEqual(true);
});
});