1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Copy missing lookupNetwork-related tests from core (#19431)

These tests were present in the core version of the NetworkController
tests, but not here. Add them makes it easier to visually compare
differences in the tests between core and this repo.
This commit is contained in:
Elliot Winkler 2023-06-21 12:52:01 -07:00 committed by GitHub
parent 4ae483c6dd
commit b7f8c82edb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5676,6 +5676,60 @@ function lookupNetworkTests({
},
);
});
it('updates the network details', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: {
method: 'net_version',
},
response: { result: networkId },
},
{
request: {
method: 'eth_getBlockByNumber',
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called via `lookupNetwork` directly
{
request: {
method: 'net_version',
},
response: { result: networkId },
},
{
request: {
method: 'eth_getBlockByNumber',
},
response: {
result: POST_1559_BLOCK,
},
},
],
});
await operation(controller);
await expect(
controller.store.getState().networkDetails,
).toStrictEqual({
EIPS: {
1559: true,
},
});
},
);
});
});
});
}
@ -5838,6 +5892,58 @@ function lookupNetworkTests({
);
});
it('resets the network details in state', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: { method: 'net_version' },
response: SUCCESSFUL_NET_VERSION_RESPONSE,
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called when calling the operation directly
{
request: { method: 'net_version' },
error: ethErrors.rpc.limitExceeded('some error'),
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: POST_1559_BLOCK,
},
},
],
});
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
},
});
await operation(controller);
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {},
});
},
);
});
if (expectedProviderConfig.type === NetworkType.rpc) {
it('emits infuraIsUnblocked', async () => {
await withController(
@ -6096,6 +6202,58 @@ function lookupNetworkTests({
);
});
}
it('resets the network details in state', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: { method: 'net_version' },
response: SUCCESSFUL_NET_VERSION_RESPONSE,
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called when calling the operation directly
{
request: { method: 'net_version' },
error: BLOCKED_INFURA_JSON_RPC_ERROR,
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: POST_1559_BLOCK,
},
},
],
});
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
},
});
await operation(controller);
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {},
});
},
);
});
});
describe('if an internal error is encountered while retrieving the version of the current network', () => {
@ -6122,6 +6280,58 @@ function lookupNetworkTests({
);
});
it('resets the network details in state', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: { method: 'net_version' },
response: SUCCESSFUL_NET_VERSION_RESPONSE,
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called when calling the operation directly
{
request: { method: 'net_version' },
error: GENERIC_JSON_RPC_ERROR,
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: POST_1559_BLOCK,
},
},
],
});
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
},
});
await operation(controller);
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {},
});
},
);
});
if (expectedProviderConfig.type === NetworkType.rpc) {
it('emits infuraIsUnblocked', async () => {
await withController(
@ -6238,6 +6448,58 @@ function lookupNetworkTests({
);
});
it('resets the network details in state', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: { method: 'net_version' },
response: SUCCESSFUL_NET_VERSION_RESPONSE,
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called when calling the operation directly
{
request: { method: 'net_version' },
response: { result: 'invalid' },
},
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: POST_1559_BLOCK,
},
},
],
});
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
},
});
await operation(controller);
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {},
});
},
);
});
if (expectedProviderConfig.type === NetworkType.rpc) {
it('emits infuraIsUnblocked', async () => {
await withController(
@ -6357,6 +6619,48 @@ function lookupNetworkTests({
);
});
it('resets the network details in state', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called when calling the operation directly
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: ethErrors.rpc.limitExceeded('some error'),
},
],
});
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
},
});
await operation(controller);
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {},
});
},
);
});
if (expectedProviderConfig.type === NetworkType.rpc) {
it('emits infuraIsUnblocked', async () => {
await withController(
@ -6642,6 +6946,48 @@ function lookupNetworkTests({
);
});
}
it('resets the network details in state', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called when calling the operation directly
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: BLOCKED_INFURA_JSON_RPC_ERROR,
},
],
});
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
},
});
await operation(controller);
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {},
});
},
);
});
});
describe('if an internal error is encountered while retrieving the network details of the current network', () => {
@ -6670,6 +7016,48 @@ function lookupNetworkTests({
);
});
it('resets the network details in state', async () => {
await withController(
{
state: initialState,
},
async ({ controller }) => {
await setFakeProvider(controller, {
stubs: [
// Called during provider initialization
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
// Called when calling the operation directly
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: GENERIC_JSON_RPC_ERROR,
},
],
});
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
},
});
await operation(controller);
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {},
});
},
);
});
if (expectedProviderConfig.type === NetworkType.rpc) {
it('emits infuraIsUnblocked', async () => {
await withController(