2017-08-24 08:53:59 +00:00
|
|
|
import { wallet, INITIAL_STATE } from 'reducers/wallet';
|
2017-11-17 21:12:27 +00:00
|
|
|
import { Wei, TokenValue } from 'libs/units';
|
2017-08-24 08:53:59 +00:00
|
|
|
import * as walletActions from 'actions/wallet';
|
|
|
|
|
|
|
|
describe('wallet reducer', () => {
|
|
|
|
it('should handle WALLET_SET', () => {
|
2017-10-25 02:17:26 +00:00
|
|
|
const doSomething = new Promise<string>(resolve => {
|
2017-11-17 21:12:27 +00:00
|
|
|
setTimeout(() => resolve('Success'), 10);
|
2017-10-25 02:17:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const walletInstance = {
|
2017-11-08 18:16:43 +00:00
|
|
|
getAddressString: () => doSomething,
|
2017-10-30 19:10:25 +00:00
|
|
|
signRawTransaction: () => doSomething,
|
|
|
|
signMessage: () => doSomething
|
2017-10-25 02:17:26 +00:00
|
|
|
};
|
|
|
|
|
2017-08-24 08:53:59 +00:00
|
|
|
expect(wallet(undefined, walletActions.setWallet(walletInstance))).toEqual({
|
|
|
|
...INITIAL_STATE,
|
2017-11-15 03:44:55 +00:00
|
|
|
inst: walletInstance
|
2017-08-24 08:53:59 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-17 21:12:27 +00:00
|
|
|
it('should handle WALLET_RESET', () => {
|
|
|
|
expect(wallet(undefined, walletActions.resetWallet())).toEqual(
|
|
|
|
INITIAL_STATE
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle WALLET_SET_BALANCE_PENDING', () => {
|
|
|
|
expect(wallet(undefined, walletActions.setBalancePending())).toEqual({
|
|
|
|
...INITIAL_STATE,
|
|
|
|
balance: {
|
|
|
|
...INITIAL_STATE.balance,
|
|
|
|
isPending: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle WALLET_SET_BALANCE_FULFILLED', () => {
|
|
|
|
const balance = Wei('100');
|
|
|
|
expect(
|
|
|
|
wallet(undefined, walletActions.setBalanceFullfilled(balance))
|
|
|
|
).toEqual({
|
|
|
|
...INITIAL_STATE,
|
|
|
|
balance: {
|
|
|
|
wei: balance,
|
|
|
|
isPending: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle WALLET_SET_BALANCE_REJECTED', () => {
|
|
|
|
expect(wallet(undefined, walletActions.setBalanceRejected())).toEqual({
|
|
|
|
...INITIAL_STATE,
|
|
|
|
balance: {
|
|
|
|
...INITIAL_STATE.balance,
|
|
|
|
isPending: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-24 08:53:59 +00:00
|
|
|
it('should handle WALLET_SET_TOKEN_BALANCES', () => {
|
2017-11-12 19:45:52 +00:00
|
|
|
const tokenBalances = { OMG: TokenValue('20') };
|
2017-08-24 08:53:59 +00:00
|
|
|
expect(
|
|
|
|
wallet(undefined, walletActions.setTokenBalances(tokenBalances))
|
|
|
|
).toEqual({
|
|
|
|
...INITIAL_STATE,
|
|
|
|
tokens: tokenBalances
|
|
|
|
});
|
|
|
|
});
|
2017-11-17 21:12:27 +00:00
|
|
|
|
|
|
|
it('should handle WALLET_BROADCAST_TX_REQUESTED', () => {
|
|
|
|
const signedTx = '0xdeadbeef';
|
|
|
|
|
|
|
|
// test broadcast where first time seeing transaction
|
|
|
|
expect(wallet(undefined, walletActions.broadcastTx(signedTx))).toEqual({
|
|
|
|
...INITIAL_STATE,
|
|
|
|
transactions: [
|
|
|
|
{
|
|
|
|
signedTx,
|
|
|
|
isBroadcasting: true,
|
|
|
|
successfullyBroadcast: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle WALLET_BROADCAST_TX_SUCCEEDED', () => {
|
|
|
|
const signedTx = '0xdead';
|
|
|
|
const txHash = '0xbeef';
|
|
|
|
const state = wallet(undefined, walletActions.broadcastTx(signedTx));
|
|
|
|
|
|
|
|
expect(
|
|
|
|
wallet(state, walletActions.broadcastTxSucceded(txHash, signedTx))
|
|
|
|
).toEqual({
|
|
|
|
...INITIAL_STATE,
|
|
|
|
transactions: [
|
|
|
|
{
|
|
|
|
signedTx,
|
|
|
|
isBroadcasting: false,
|
|
|
|
successfullyBroadcast: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle WALLET_BROADCAST_TX_FAILED', () => {
|
|
|
|
const signedTx = '0xdeadbeef';
|
|
|
|
const errorMsg = 'Broadcasting failed.';
|
|
|
|
const state = wallet(undefined, walletActions.broadcastTx(signedTx));
|
|
|
|
|
|
|
|
expect(
|
|
|
|
wallet(state, walletActions.broadCastTxFailed(signedTx, errorMsg))
|
|
|
|
).toEqual({
|
|
|
|
...INITIAL_STATE,
|
|
|
|
transactions: [
|
|
|
|
{
|
|
|
|
signedTx,
|
|
|
|
isBroadcasting: false,
|
|
|
|
successfullyBroadcast: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2017-08-24 08:53:59 +00:00
|
|
|
});
|