chore: remove valid chain check (#1164)

* chore: remove valid chain check

* chore: lint

* fix: remove e2e test checking network ids

Co-authored-by: Botond <botond@vegaprotocol.io>
This commit is contained in:
Matthew Russell 2022-09-01 07:57:35 -07:00 committed by GitHub
parent 2a0f79d1d1
commit 429b57ec52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3 additions and 144 deletions

View File

@ -49,23 +49,6 @@ context.skip('Node switcher', function () {
validateNodeError(errorTypeTxt, nodeErrorTxt);
});
it('Cannot connect to network from different chain ID', function () {
const errorTypeTxt = 'Error: incorrect network';
const nodeErrorTxt = 'This node is not on the CUSTOM network.';
cy.getByTestId('node-url-custom').click();
cy.getByTestId(customNodeBtn).within(() => {
cy.get('input').clear().type('https://n03.s.vega.xyz/query');
cy.getByTestId('link').click();
});
cy.getByTestId('ssl-cell', { timeout: 6000 }).should(
'contain.text',
'Yes'
);
validateNodeError(errorTypeTxt, nodeErrorTxt);
});
function validateNodeError(errortype, errorMsg) {
cy.getByTestId(nodeErrorType).should('have.text', errortype);
cy.getByTestId(nodeErrorMsg).should('have.text', errorMsg);

View File

@ -285,45 +285,6 @@ describe('Node switcher', () => {
);
});
it('disables selecting a node when it is on an incorrect network', () => {
const mockUrl = 'https://mock.url';
const mockConfig = {
hosts: [mockUrl],
};
// @ts-ignore Typescript doesn't recognise mocked instances
useNodes.mockImplementation((config: Configuration) => {
const nodeState = getValidNodeState(Networks.TESTNET, mockUrl);
return {
state: {
[mockUrl]: {
...nodeState,
chain: {
...nodeState.chain,
value: `some-network-id`,
},
},
},
clients: createMockClients(config.hosts),
updateNodeUrl: jest.fn(),
updateNodeBlock: jest.fn(),
};
});
render(
<MockedProvider mocks={[statsQueryMock]}>
<NodeSwitcher config={mockConfig} onConnect={onConnect} />
</MockedProvider>
);
expect(screen.getByRole('radio', { name: mockUrl })).toHaveAttribute(
'disabled'
);
expect(screen.getByRole('button', { name: 'Connect' })).toHaveAttribute(
'disabled'
);
});
it('allows connecting to a valid node', () => {
render(<NodeSwitcher config={{ hosts: HOSTS }} onConnect={onConnect} />);
@ -583,56 +544,9 @@ describe('Node switcher', () => {
expect(screen.getByText(error?.headline ?? '')).toBeInTheDocument();
});
it('disables selecting a custom node when it is on an incorrect network', () => {
const mockUrl = 'https://mock.url';
const updateNodeUrlMock = jest.fn();
// @ts-ignore Typescript doesn't recognise mocked instances
useNodes.mockImplementation(
mockNodesImplementation(updateNodeUrlMock, (env, url) => {
const nodeState = getValidNodeState(env, url);
return {
...nodeState,
chain: {
...nodeState.chain,
value: 'network-chain-id',
},
};
})
);
render(
<MockedProvider mocks={[statsQueryMock]}>
<NodeSwitcher config={{ hosts: [] }} onConnect={onConnect} />
</MockedProvider>
);
fireEvent.click(screen.getByRole('radio', { name: 'Other' }));
fireEvent.change(screen.getByRole('textbox'), {
target: {
value: mockUrl,
},
});
fireEvent.click(screen.getByRole('link', { name: 'Check' }));
expect(screen.getByRole('button', { name: 'Connect' })).toHaveAttribute(
'disabled'
);
const error = getErrorByType(
ErrorType.INVALID_NETWORK,
Networks.TESTNET,
mockUrl
);
expect(error?.headline).not.toBeNull();
expect(screen.getByText(error?.headline ?? '')).toBeInTheDocument();
});
it.each`
description | errorType
${'the node has an invalid url'} | ${ErrorType.INVALID_URL}
${'the node is on an invalid network'} | ${ErrorType.INVALID_NETWORK}
${'the node has an ssl issue'} | ${ErrorType.SSL_ERROR}
${'the node cannot be reached'} | ${ErrorType.CONNECTION_ERROR}
${'none of the config nodes can be connected to'} | ${ErrorType.CONNECTION_ERROR_ALL}

View File

@ -15,10 +15,9 @@ import {
getIsFormDisabled,
getErrorType,
getErrorByType,
getHasInvalidChain,
} from '../../utils/validate-node';
import { CUSTOM_NODE_KEY } from '../../types';
import type { Configuration, NodeData, ErrorType, Networks } from '../../types';
import type { Configuration, NodeData, ErrorType } from '../../types';
import { LayoutRow } from './layout-row';
import { NodeError } from './node-error';
import { NodeStats } from './node-stats';
@ -34,9 +33,8 @@ const getDefaultNode = (urls: string[], currentUrl?: string) => {
return currentUrl && urls.includes(currentUrl) ? currentUrl : undefined;
};
const getHighestBlock = (env: Networks, state: Record<string, NodeData>) => {
const getHighestBlock = (state: Record<string, NodeData>) => {
return Object.keys(state).reduce((acc, node) => {
if (getHasInvalidChain(env, state[node].chain.value)) return acc;
const value = Number(state[node].block.value);
return value ? Math.max(acc, value) : acc;
}, 0);
@ -56,7 +54,7 @@ export const NodeSwitcher = ({
getDefaultNode(config.hosts, VEGA_URL)
);
const { state, clients, updateNodeUrl, updateNodeBlock } = useNodes(config);
const highestBlock = getHighestBlock(VEGA_ENV, state);
const highestBlock = getHighestBlock(state);
const customUrl = state[CUSTOM_NODE_KEY]?.url;

View File

@ -503,27 +503,6 @@ describe('node selection', () => {
});
});
it('has a network error when the selected node is not on the correct network', async () => {
act(async () => {
// @ts-ignore allow adding a mock return value to mocked module
createClient.mockImplementation(() => {
return createMockClient({ network: Networks.MAINNET });
});
const { result } = renderHook(() => useEnvironment(), {
wrapper: MockWrapper,
});
await waitFor(() => {
expect(result.current).toEqual({
...mockEnvironmentState,
networkError: ErrorType.INVALID_NETWORK,
setNodeSwitcherOpen: result.current.setNodeSwitcherOpen,
});
});
});
});
it('has a network error when the selected node has not ssl available', async () => {
act(async () => {
// @ts-ignore allow adding a mock return value to mocked module

View File

@ -10,7 +10,6 @@ export const CUSTOM_NODE_KEY = 'custom';
export enum ErrorType {
INVALID_URL,
INVALID_NETWORK,
SSL_ERROR,
CONNECTION_ERROR,
CONNECTION_ERROR_ALL,

View File

@ -12,10 +12,6 @@ export const getIsNodeLoading = (node?: NodeData): boolean => {
);
};
export const getHasInvalidChain = (env: Networks, chain = '') => {
return !chain.split('-').includes(env.toLowerCase());
};
export const getIsInvalidUrl = (url: string) => {
try {
new URL(url);
@ -29,7 +25,6 @@ export const getIsNodeDisabled = (env: Networks, data?: NodeData) => {
return (
!!data &&
(getIsNodeLoading(data) ||
getHasInvalidChain(env, data.chain.value) ||
getIsInvalidUrl(data.url) ||
data.chain.hasError ||
data.responseTime.hasError ||
@ -62,11 +57,6 @@ export const getErrorByType = (
headline: t('Error: invalid url'),
message: t(url ? `${url} is not a valid url.` : ''),
};
case ErrorType.INVALID_NETWORK:
return {
headline: t(`Error: incorrect network`),
message: t(`This node is not on the ${env} network.`),
};
case ErrorType.SSL_ERROR:
return {
headline: t(`Error: the node you are reading from does not have SSL`),
@ -122,10 +112,6 @@ export const getErrorType = (env: Networks, data?: NodeData) => {
return ErrorType.CONNECTION_ERROR;
}
if (!data.chain.isLoading && getHasInvalidChain(env, data.chain.value)) {
return ErrorType.INVALID_NETWORK;
}
if (data.ssl.hasError) {
return ErrorType.SSL_ERROR;
}