1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/test/e2e/tests/ens.spec.js

136 lines
3.5 KiB
JavaScript
Raw Normal View History

const { strict: assert } = require('assert');
const { convertToHexValue, withFixtures } = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
describe('ENS', function () {
const sampleAddress = '1111111111111111111111111111111111111111';
const sampleEnsDomain = 'test.eth';
const infuraUrl =
'https://mainnet.infura.io/v3/00000000000000000000000000000000';
async function mockInfura(mockServer) {
await mockServer
.forPost(infuraUrl)
.withJsonBodyIncluding({ method: 'eth_blockNumber' })
.thenCallback(() => {
return {
statusCode: 200,
json: {
jsonrpc: '2.0',
id: '1111111111111111',
result: '0x1',
},
};
});
NetworkController: Split `network` into `networkId` and `networkStatus` (#17556) The `network` store of the network controller crams two types of data into one place. It roughly tracks whether we have enough information to make requests to the network and whether the network is capable of receiving requests, but it also stores the ID of the network (as obtained via `net_version`). Generally we shouldn't be using the network ID for anything, as it has been completely replaced by chain ID, which all custom RPC endpoints have been required to support for over a year now. However, as the network ID is used in various places within the extension codebase, removing it entirely would be a non-trivial effort. So, minimally, this commit splits `network` into two stores: `networkId` and `networkStatus`. But it also expands the concept of network status. Previously, the network was in one of two states: "loading" and "not-loading". But now it can be in one of four states: - `available`: The network is able to receive and respond to requests. - `unavailable`: The network is not able to receive and respond to requests for unknown reasons. - `blocked`: The network is actively blocking requests based on the user's geolocation. (This is specific to Infura.) - `unknown`: We don't know whether the network can receive and respond to requests, either because we haven't checked or we tried to check and were unsuccessful. This commit also changes how the network status is determined — specifically, how many requests are used to determine that status, when they occur, and whether they are awaited. Previously, the network controller would make 2 to 3 requests during the course of running `lookupNetwork`. * First, if it was an Infura network, it would make a request for `eth_blockNumber` to determine whether Infura was blocking requests or not, then emit an appropriate event. This operation was not awaited. * Then, regardless of the network, it would fetch the network ID via `net_version`. This operation was awaited. * Finally, regardless of the network, it would fetch the latest block via `eth_getBlockByNumber`, then use the result to determine whether the network supported EIP-1559. This operation was awaited. Now: * One fewer request is made, specifically `eth_blockNumber`, as we don't need to make an extra request to determine whether Infura is blocking requests; we can reuse `eth_getBlockByNumber`; * All requests are awaited, which makes `lookupNetwork` run fully in-band instead of partially out-of-band; and * Both requests for `net_version` and `eth_getBlockByNumber` are performed in parallel to make `lookupNetwork` run slightly faster.
2023-03-31 00:49:12 +02:00
await mockServer
.forPost(infuraUrl)
.withJsonBodyIncluding({ method: 'eth_getBalance' })
.thenCallback(() => {
return {
statusCode: 200,
json: {
jsonrpc: '2.0',
id: '1111111111111111',
result: '0x1',
},
};
});
await mockServer
.forPost(infuraUrl)
.withJsonBodyIncluding({ method: 'eth_getBlockByNumber' })
.thenCallback(() => {
return {
statusCode: 200,
json: {
jsonrpc: '2.0',
id: '1111111111111111',
result: {},
},
};
});
await mockServer
.forPost(infuraUrl)
.withJsonBodyIncluding({ method: 'eth_call' })
.thenCallback(() => {
return {
statusCode: 200,
json: {
jsonrpc: '2.0',
id: '1111111111111111',
result: `0x000000000000000000000000${sampleAddress}`,
},
};
});
}
const ganacheOptions = {
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: convertToHexValue(25000000000000000000),
},
],
};
it('domain resolves to a correct address', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withNetworkController({
providerConfig: {
chainId: '0x1',
nickname: '',
rpcUrl: '',
type: 'mainnet',
},
})
.build(),
ganacheOptions,
title: this.test.title,
testSpecificMock: mockInfura,
},
async ({ driver }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await driver.waitForElementNotPresent('.loading-overlay');
await driver.clickElement('[data-testid="eth-overview-send"]');
await driver.pasteIntoField(
'input[placeholder="Enter public address (0x) or ENS name"]',
sampleEnsDomain,
);
await driver.clickElement(
'.send__select-recipient-wrapper__group-item__title',
);
const currentEnsDomain = await driver.findElement(
'.ens-input__selected-input__title',
);
assert.equal(
await currentEnsDomain.getText(),
'test.eth',
'Domain name not correct',
);
const resolvedAddress = await driver.findElement(
'.ens-input__selected-input__subtitle',
);
assert.equal(
await resolvedAddress.getText(),
`0x${sampleAddress}`,
'Resolved address not correct',
);
},
);
});
});