e463bbe238
* feat: unhardcode contract addresses * fix: linting and tests * feat: switch contract usage in token app to use unhardcoded addresses * chore: remove other usage of hard coded contract addresses * feat: convert contracts to classes, update claim contract to fix circular dependency * feat: add hard coded contract addresses to contracts page * fix: misc tidy up * chore: rename ethers big num conversion func * fix: remove pending transactions modal * chore: add single toBigNum function that can accept number string or EthersBignNumber * chore: delete unused tranche helpers and decimals functions from smart contracts lib * feat: add faucetable token class * fix: reset tx state after early exit from approve tx * feat: re add transaction modal using zustand store * fix: loader colors for eth wallet * fix: pass ethereum config to gurantee existence before tx execution * chore: lint smart contracts lib * chore: fix web3container to use children and not render prop * chore: lint * fix: use background to mock ethereum wallet to avoid mocking globally for every test * chore: move web3 mock to common steps and call from withdrawals feature tests
144 lines
3.8 KiB
TypeScript
144 lines
3.8 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import type { MockedResponse } from '@apollo/client/testing';
|
|
import { MockedProvider } from '@apollo/client/testing';
|
|
import { Web3Container } from './web3-container';
|
|
import type { useWeb3React } from '@web3-react/core';
|
|
import type { NetworkParamsQuery } from '@vegaprotocol/web3';
|
|
import { NETWORK_PARAMS_QUERY } from '@vegaprotocol/web3';
|
|
|
|
const defaultHookValue = {
|
|
isActive: false,
|
|
error: undefined,
|
|
connector: null,
|
|
chainId: 3,
|
|
} as unknown as ReturnType<typeof useWeb3React>;
|
|
let mockHookValue: ReturnType<typeof useWeb3React>;
|
|
|
|
const mockEthereumConfig = {
|
|
network_id: '3',
|
|
chain_id: '3',
|
|
confirmations: 3,
|
|
collateral_bridge_contract: {
|
|
address: 'bridge address',
|
|
},
|
|
};
|
|
|
|
const networkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
|
request: {
|
|
query: NETWORK_PARAMS_QUERY,
|
|
},
|
|
result: {
|
|
data: {
|
|
networkParameters: [
|
|
{
|
|
__typename: 'NetworkParameter',
|
|
key: 'blockchains.ethereumConfig',
|
|
value: JSON.stringify(mockEthereumConfig),
|
|
},
|
|
],
|
|
},
|
|
},
|
|
};
|
|
|
|
jest.mock('@web3-react/core', () => {
|
|
const original = jest.requireActual('@web3-react/core');
|
|
return {
|
|
...original,
|
|
useWeb3React: jest.fn(() => mockHookValue),
|
|
};
|
|
});
|
|
|
|
function setup(mock = networkParamsQueryMock) {
|
|
return render(
|
|
<MockedProvider mocks={[mock]}>
|
|
<Web3Container>
|
|
<div>
|
|
<div>Child</div>
|
|
<div>{mockEthereumConfig.collateral_bridge_contract.address}</div>
|
|
</div>
|
|
</Web3Container>
|
|
</MockedProvider>
|
|
);
|
|
}
|
|
|
|
it('Prompt to connect opens dialog', async () => {
|
|
mockHookValue = defaultHookValue;
|
|
setup();
|
|
|
|
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
expect(
|
|
await screen.findByText('Connect your Ethereum wallet')
|
|
).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Child')).not.toBeInTheDocument();
|
|
expect(screen.queryByTestId('web3-connector-list')).not.toBeInTheDocument();
|
|
|
|
fireEvent.click(screen.getByText('Connect'));
|
|
expect(screen.getByTestId('web3-connector-list')).toBeInTheDocument();
|
|
});
|
|
|
|
it('Error message is shown', async () => {
|
|
const message = 'Opps! An error';
|
|
mockHookValue = { ...defaultHookValue, error: new Error(message) };
|
|
setup();
|
|
|
|
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
expect(
|
|
await screen.findByText(`Something went wrong: ${message}`)
|
|
).toBeInTheDocument();
|
|
expect(screen.queryByText('Child')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('Checks that chain ID matches app ID', async () => {
|
|
const expectedChainId = 4;
|
|
mockHookValue = {
|
|
...defaultHookValue,
|
|
isActive: true,
|
|
chainId: expectedChainId,
|
|
};
|
|
setup();
|
|
|
|
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
expect(
|
|
await screen.findByText(`This app only works on chain ID: 3`)
|
|
).toBeInTheDocument();
|
|
expect(screen.queryByText('Child')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('Passes ethereum config to children', async () => {
|
|
mockHookValue = {
|
|
...defaultHookValue,
|
|
isActive: true,
|
|
};
|
|
setup();
|
|
|
|
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
expect(
|
|
await screen.findByText(
|
|
mockEthereumConfig.collateral_bridge_contract.address
|
|
)
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it('Shows no config found message if the network parameter doesnt exist', async () => {
|
|
const mock: MockedResponse<NetworkParamsQuery> = {
|
|
request: {
|
|
query: NETWORK_PARAMS_QUERY,
|
|
},
|
|
result: {
|
|
data: {
|
|
networkParameters: [
|
|
{
|
|
__typename: 'NetworkParameter',
|
|
key: 'nope',
|
|
value: 'foo',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
};
|
|
setup(mock);
|
|
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
expect(await screen.findByText('No data')).toBeInTheDocument();
|
|
});
|