mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-11 19:44:21 +00:00
Get passing existing saga tests
This commit is contained in:
parent
b1b17a155f
commit
edcad4b7a9
@ -4,7 +4,7 @@ import { Web3Wallet } from 'libs/wallet';
|
|||||||
import { SagaIterator } from 'redux-saga';
|
import { SagaIterator } from 'redux-saga';
|
||||||
import { select, put, takeEvery, call } from 'redux-saga/effects';
|
import { select, put, takeEvery, call } from 'redux-saga/effects';
|
||||||
import { changeNodeIntent, TypeKeys, web3SetNode } from 'actions/config';
|
import { changeNodeIntent, TypeKeys, web3SetNode } from 'actions/config';
|
||||||
import { getNodeId, getStaticAltNodeToWeb3 } from 'selectors/config';
|
import { getNodeId, getStaticAltNodeIdToWeb3 } from 'selectors/config';
|
||||||
import { setupWeb3Node, Web3Service } from 'libs/nodes/web3';
|
import { setupWeb3Node, Web3Service } from 'libs/nodes/web3';
|
||||||
import { Web3NodeConfig } from 'types/node';
|
import { Web3NodeConfig } from 'types/node';
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ export function* unsetWeb3NodeOnWalletEvent(action): SagaIterator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const altNode = yield select(getStaticAltNodeToWeb3);
|
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
||||||
// switch back to a node with the same network as MetaMask/Mist
|
// switch back to a node with the same network as MetaMask/Mist
|
||||||
yield put(changeNodeIntent(altNode));
|
yield put(changeNodeIntent(altNode));
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ export function* unsetWeb3Node(): SagaIterator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const altNode = yield select(getStaticAltNodeToWeb3);
|
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
||||||
// switch back to a node with the same network as MetaMask/Mist
|
// switch back to a node with the same network as MetaMask/Mist
|
||||||
yield put(changeNodeIntent(altNode));
|
yield put(changeNodeIntent(altNode));
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ export const getCustomNodeFromId = (
|
|||||||
nodeId: string
|
nodeId: string
|
||||||
): CustomNodeConfig | undefined => getCustomNodeConfigs(state)[nodeId];
|
): CustomNodeConfig | undefined => getCustomNodeConfigs(state)[nodeId];
|
||||||
|
|
||||||
export const getStaticAltNodeToWeb3 = (state: AppState) => {
|
export const getStaticAltNodeIdToWeb3 = (state: AppState) => {
|
||||||
const { web3, ...configs } = getStaticNodeConfigs(state);
|
const { web3, ...configs } = getStaticNodeConfigs(state);
|
||||||
if (!web3) {
|
if (!web3) {
|
||||||
return SELECTED_NODE_INITIAL_STATE.nodeId;
|
return SELECTED_NODE_INITIAL_STATE.nodeId;
|
||||||
|
@ -7,32 +7,28 @@ import {
|
|||||||
handleNodeChangeIntent,
|
handleNodeChangeIntent,
|
||||||
handlePollOfflineStatus,
|
handlePollOfflineStatus,
|
||||||
pollOfflineStatus,
|
pollOfflineStatus,
|
||||||
reload,
|
reload
|
||||||
switchToNewNode
|
|
||||||
} from 'sagas/config/node';
|
} from 'sagas/config/node';
|
||||||
import {
|
import {
|
||||||
getNodeId,
|
getNodeId,
|
||||||
getNodeConfig,
|
getNodeConfig,
|
||||||
getOffline,
|
getOffline,
|
||||||
getCustomNodeConfigs,
|
|
||||||
getCustomNetworkConfigs,
|
|
||||||
isStaticNodeId,
|
isStaticNodeId,
|
||||||
getStaticNodeFromId,
|
getStaticNodeFromId,
|
||||||
getNetworkConfigById,
|
getNetworkConfigById,
|
||||||
getCustomNodeFromId
|
getCustomNodeFromId,
|
||||||
|
getStaticAltNodeIdToWeb3
|
||||||
} from 'selectors/config';
|
} from 'selectors/config';
|
||||||
import { Web3Wallet } from 'libs/wallet';
|
import { Web3Wallet } from 'libs/wallet';
|
||||||
import { RPCNode } from 'libs/nodes';
|
|
||||||
import { showNotification } from 'actions/notifications';
|
import { showNotification } from 'actions/notifications';
|
||||||
import { translateRaw } from 'translations';
|
import { translateRaw } from 'translations';
|
||||||
import { StaticNodeConfig } from 'types/node';
|
import { StaticNodeConfig } from 'types/node';
|
||||||
import { staticNodesExpectedState } from './nodes/staticNodes.spec';
|
import { staticNodesExpectedState } from './nodes/staticNodes.spec';
|
||||||
import { metaExpectedState } from './meta/meta.spec';
|
import { metaExpectedState } from './meta/meta.spec';
|
||||||
import { selectedNodeExpectedState } from './nodes/selectedNode.spec';
|
import { selectedNodeExpectedState } from './nodes/selectedNode.spec';
|
||||||
import { staticNetworksExpectedState } from './networks/staticNetworks.spec';
|
|
||||||
import { customNetworksExpectedState } from './networks/customNetworks.spec';
|
|
||||||
import { StaticNetworkConfig } from '../../../shared/types/network';
|
|
||||||
import { customNodesExpectedState, firstCustomNodeId } from './nodes/customNodes.spec';
|
import { customNodesExpectedState, firstCustomNodeId } from './nodes/customNodes.spec';
|
||||||
|
import { unsetWeb3Node, unsetWeb3NodeOnWalletEvent } from 'sagas/config/web3';
|
||||||
|
|
||||||
// init module
|
// init module
|
||||||
configuredStore.getState();
|
configuredStore.getState();
|
||||||
|
|
||||||
@ -268,20 +264,19 @@ describe('handleNodeChangeIntent*', () => {
|
|||||||
|
|
||||||
describe('unsetWeb3Node*', () => {
|
describe('unsetWeb3Node*', () => {
|
||||||
const node = 'web3';
|
const node = 'web3';
|
||||||
const mockNodeConfig = { network: 'ETH' } as any;
|
const alternativeNodeId = 'eth_mew';
|
||||||
const newNode = equivalentNodeOrDefault(mockNodeConfig);
|
|
||||||
const gen = unsetWeb3Node();
|
const gen = unsetWeb3Node();
|
||||||
|
|
||||||
it('should select getNode', () => {
|
it('should select getNode', () => {
|
||||||
expect(gen.next().value).toEqual(select(getNodeId));
|
expect(gen.next().value).toEqual(select(getNodeId));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should select getNodeConfig', () => {
|
it('should select an alternative node to web3', () => {
|
||||||
expect(gen.next(node).value).toEqual(select(getNodeConfig));
|
expect(gen.next(node).value).toEqual(select(getStaticAltNodeIdToWeb3));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should put changeNodeIntent', () => {
|
it('should put changeNodeIntent', () => {
|
||||||
expect(gen.next(mockNodeConfig).value).toEqual(put(changeNodeIntent(newNode)));
|
expect(gen.next(alternativeNodeId).value).toEqual(put(changeNodeIntent(alternativeNodeId)));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be done', () => {
|
it('should be done', () => {
|
||||||
@ -298,22 +293,20 @@ describe('unsetWeb3Node*', () => {
|
|||||||
|
|
||||||
describe('unsetWeb3NodeOnWalletEvent*', () => {
|
describe('unsetWeb3NodeOnWalletEvent*', () => {
|
||||||
const fakeAction = {};
|
const fakeAction = {};
|
||||||
const mockNode = 'web3';
|
const mockNodeId = 'web3';
|
||||||
const mockNodeConfig: Partial<StaticNodeConfig> = { network: 'ETH' };
|
const alternativeNodeId = 'eth_mew';
|
||||||
const gen = unsetWeb3NodeOnWalletEvent(fakeAction);
|
const gen = unsetWeb3NodeOnWalletEvent(fakeAction);
|
||||||
|
|
||||||
it('should select getNode', () => {
|
it('should select getNode', () => {
|
||||||
expect(gen.next().value).toEqual(select(getNodeId));
|
expect(gen.next().value).toEqual(select(getNodeId));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should select getNodeConfig', () => {
|
it('should select an alternative node to web3', () => {
|
||||||
expect(gen.next(mockNode).value).toEqual(select(getNodeConfig));
|
expect(gen.next(mockNodeId).value).toEqual(select(getStaticAltNodeIdToWeb3));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should put changeNodeIntent', () => {
|
it('should put changeNodeIntent', () => {
|
||||||
expect(gen.next(mockNodeConfig).value).toEqual(
|
expect(gen.next(alternativeNodeId).value).toEqual(put(changeNodeIntent(alternativeNodeId)));
|
||||||
put(changeNodeIntent(equivalentNodeOrDefault(mockNodeConfig as any)))
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be done', () => {
|
it('should be done', () => {
|
||||||
@ -337,51 +330,3 @@ describe('unsetWeb3NodeOnWalletEvent*', () => {
|
|||||||
expect(gen2.next().done).toEqual(true);
|
expect(gen2.next().done).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('equivalentNodeOrDefault', () => {
|
|
||||||
const originalNodeList = Object.keys(NODES);
|
|
||||||
const appDefaultNode = configInitialState.nodeSelection;
|
|
||||||
const mockNodeConfig = {
|
|
||||||
network: 'ETH',
|
|
||||||
service: 'fakeService',
|
|
||||||
lib: new RPCNode('fakeEndpoint'),
|
|
||||||
estimateGas: false
|
|
||||||
};
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
Object.keys(NODES).forEach(node => {
|
|
||||||
if (originalNodeList.indexOf(node) === -1) {
|
|
||||||
delete NODES[node];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return node with equivalent network', () => {
|
|
||||||
const node = equivalentNodeOrDefault({
|
|
||||||
...mockNodeConfig,
|
|
||||||
network: 'Kovan'
|
|
||||||
});
|
|
||||||
expect(NODES[node].network).toEqual('Kovan');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return app default if no eqivalent is found', () => {
|
|
||||||
const node = equivalentNodeOrDefault({
|
|
||||||
...mockNodeConfig,
|
|
||||||
network: 'noEqivalentExists'
|
|
||||||
} as any);
|
|
||||||
expect(node).toEqual(appDefaultNode);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should ignore web3 from node list', () => {
|
|
||||||
NODES.web3 = {
|
|
||||||
...mockNodeConfig,
|
|
||||||
network: 'uniqueToWeb3'
|
|
||||||
} as any;
|
|
||||||
|
|
||||||
const node = equivalentNodeOrDefault({
|
|
||||||
...mockNodeConfig,
|
|
||||||
network: 'uniqueToWeb3'
|
|
||||||
} as any);
|
|
||||||
expect(node).toEqual(appDefaultNode);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user