Skip to content

Commit

Permalink
Merge branch 'develop' into review-spending-cap-screen
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsekulic authored Oct 4, 2022
2 parents 6ce3438 + 3b63ecf commit 984fdfb
Show file tree
Hide file tree
Showing 22 changed files with 1,758 additions and 1,814 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [10.20.0]
### Changed
- Deprecate Rinkeby, Ropsten and Kovan test networks and define Goerli as the default network in test mode ([#15989](https://github.com/MetaMask/metamask-extension/pull/15989))

### Fixed
- [FLASK] Fix crash when uninstalling snap ([#15799](https://github.com/MetaMask/metamask-extension/pull/15799))
- [FLASK] Fix crash with certain permissions on the snap settings page ([#15797](https://github.com/MetaMask/metamask-extension/pull/15797))
- [FLASK] Fix an issue with installing and updating snaps with 0 permissions ([#15796](https://github.com/MetaMask/metamask-extension/pull/15796))

## [10.19.0]
### Added
- Add ENS wildcard and secure offchain resolution (ENSIP-10 & EIP3668) ([#14675](https://github.com/MetaMask/metamask-extension/pull/14675))
Expand Down Expand Up @@ -3189,7 +3198,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Uncategorized
- Added the ability to restore accounts from seed words.

[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.19.0...HEAD
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.20.0...HEAD
[10.20.0]: https://github.com/MetaMask/metamask-extension/compare/v10.19.0...v10.20.0
[10.19.0]: https://github.com/MetaMask/metamask-extension/compare/v10.18.4...v10.19.0
[10.18.4]: https://github.com/MetaMask/metamask-extension/compare/v10.18.3...v10.18.4
[10.18.3]: https://github.com/MetaMask/metamask-extension/compare/v10.18.2...v10.18.3
Expand Down
Binary file added app/images/aurora.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/images/icons/icon-search-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions app/manifest/v3/_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@
"description": "__MSG_appDescription__",
"host_permissions": [
"http://localhost:8545/",
"https://*.infura.io/",
"https://chainid.network/chains.json",
"https://lattice.gridplus.io/*",
"*://*.eth/"
"file://*/*",
"http://*/*",
"https://*/*"
],
"icons": {
"16": "images/icon-16.png",
Expand Down
71 changes: 64 additions & 7 deletions app/scripts/controllers/network/createInfuraClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* @jest-environment node
*/

import { withInfuraClient } from './provider-api-tests/helpers';
import {
withMockedInfuraCommunications,
withInfuraClient,
} from './provider-api-tests/helpers';
import {
testsForRpcMethodNotHandledByMiddleware,
testsForRpcMethodAssumingNoBlockParam,
Expand Down Expand Up @@ -141,9 +144,36 @@ describe('createInfuraClient', () => {
});

describe('eth_getTransactionByHash', () => {
testsForRpcMethodsThatCheckForBlockHashInResponse(
'eth_getTransactionByHash',
);
const method = 'eth_getTransactionByHash';

testsForRpcMethodsThatCheckForBlockHashInResponse(method);

it("refreshes the block tracker's current block if it is less than the block number that comes back in the response", async () => {
await withMockedInfuraCommunications(async (comms) => {
const request = { method };

// The first time a block-cacheable request is made, the latest
// block number is retrieved through the block tracker first.
comms.mockNextBlockTrackerRequest({ blockNumber: '0x100' });
// This is our request.
comms.mockInfuraRpcCall({
request,
response: {
result: {
blockNumber: '0x200',
},
},
});
// The block-tracker-inspector middleware will request the latest
// block through the block tracker again.
comms.mockNextBlockTrackerRequest({ blockNumber: '0x300' });

await withInfuraClient(async ({ makeRpcCall, blockTracker }) => {
await makeRpcCall(request);
expect(blockTracker.getCurrentBlock()).toStrictEqual('0x300');
});
});
});
});

describe('eth_getTransactionCount', () => {
Expand All @@ -153,9 +183,36 @@ describe('createInfuraClient', () => {
});

describe('eth_getTransactionReceipt', () => {
testsForRpcMethodsThatCheckForBlockHashInResponse(
'eth_getTransactionReceipt',
);
const method = 'eth_getTransactionReceipt';

testsForRpcMethodsThatCheckForBlockHashInResponse(method);

it("refreshes the block tracker's current block if it is less than the block number that comes back in the response", async () => {
await withMockedInfuraCommunications(async (comms) => {
const request = { method };

// The first time a block-cacheable request is made, the latest
// block number is retrieved through the block tracker first.
comms.mockNextBlockTrackerRequest({ blockNumber: '0x100' });
// This is our request.
comms.mockInfuraRpcCall({
request,
response: {
result: {
blockNumber: '0x200',
},
},
});
// The block-tracker-inspector middleware will request the latest
// block through the block tracker again.
comms.mockNextBlockTrackerRequest({ blockNumber: '0x300' });

await withInfuraClient(async ({ makeRpcCall, blockTracker }) => {
await makeRpcCall(request);
expect(blockTracker.getCurrentBlock()).toStrictEqual('0x300');
});
});
});
});

describe('eth_getUncleByBlockHashAndIndex', () => {
Expand Down
114 changes: 86 additions & 28 deletions app/scripts/controllers/network/provider-api-tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,37 @@ import createInfuraClient from '../createInfuraClient';
*/

/**
* @typedef {{ nockScope: NockScope, blockNumber: string }} MockNextBlockTrackerRequestOptions
* @typedef {{ nockScope: NockScope, blockNumber: string }} MockBlockTrackerRequestOptions
*
* The options to `mockNextBlockTrackerRequest`.
* The options to `mockNextBlockTrackerRequest` and `mockAllBlockTrackerRequests`.
*/

/**
* @typedef {{ nockScope: NockScope, request: object, response: object, delay?: number }} MockSuccessfulInfuraRpcCallOptions
* @typedef {{ nockScope: NockScope, request: object, response: object, delay?: number }} MockInfuraRpcCallOptions
*
* The options to `mockSuccessfulInfuraRpcCall`.
* The options to `mockInfuraRpcCall`.
*/

/**
* @typedef {{mockNextBlockTrackerRequest: (options: Omit<MockNextBlockTrackerRequestOptions, 'nockScope'>) => void, mockSuccessfulInfuraRpcCall: (options: Omit<MockSuccessfulInfuraRpcCallOptions, 'nockScope'>) => NockScope}} InfuraCommunications
* @typedef {{mockNextBlockTrackerRequest: (options: Omit<MockBlockTrackerRequestOptions, 'nockScope'>) => void, mockAllBlockTrackerRequests: (options: Omit<MockBlockTrackerRequestOptions, 'nockScope'>) => void, mockInfuraRpcCall: (options: Omit<MockInfuraRpcCallOptions, 'nockScope'>) => NockScope}} InfuraCommunications
*
* Provides methods to mock different kinds of requests to Infura.
*/

/**
* @typedef {{network: string}} MockingInfuraCommunicationsOptions
* @typedef {{network: string}} WithMockedInfuraCommunicationsOptions
*
* The options bag that `mockingInfuraCommunications` takes.
*/

/**
* @typedef {(comms: InfuraCommunications) => Promise<any>} MockingInfuraCommunicationsCallback
* @typedef {(comms: InfuraCommunications) => Promise<any>} WithMockedInfuraCommunicationsCallback
*
* The callback that `mockingInfuraCommunications` takes.
*/

/**
* @typedef {[MockingInfuraCommunicationsOptions, MockingInfuraCommunicationsCallback] | [MockingInfuraCommunicationsCallback]} MockingInfuraCommunicationsArgs
* @typedef {[WithMockedInfuraCommunicationsOptions, WithMockedInfuraCommunicationsCallback] | [WithMockedInfuraCommunicationsCallback]} WithMockedInfuraCommunicationsArgs
*
* The arguments to `mockingInfuraCommunications`.
*/
Expand Down Expand Up @@ -111,7 +111,7 @@ function buildScopeForMockingInfuraRequests({ network = 'mainnet' } = {}) {
/**
* Mocks the next request for the latest block that the block tracker will make.
*
* @param {MockNextBlockTrackerRequestOptions} args - The arguments.
* @param {MockBlockTrackerRequestOptions} args - The arguments.
* @param {NockScope} args.nockScope - A nock scope (a set of mocked requests
* scoped to a certain base URL).
* @param {string} args.blockNumber - The block number that the block tracker
Expand All @@ -121,46 +121,100 @@ async function mockNextBlockTrackerRequest({
nockScope,
blockNumber = DEFAULT_LATEST_BLOCK_NUMBER,
}) {
await mockSuccessfulInfuraRpcCall({
await mockInfuraRpcCall({
nockScope,
request: { method: 'eth_blockNumber', params: [] },
response: { result: blockNumber },
});
}

/**
* Mocks all requests for the latest block that the block tracker will make.
*
* @param {MockBlockTrackerRequestOptions} args - The arguments.
* @param {NockScope} args.nockScope - A nock scope (a set of mocked requests
* scoped to a certain base URL).
* @param {string} args.blockNumber - The block number that the block tracker
* should report, as a 0x-prefixed hex string.
*/
async function mockAllBlockTrackerRequests({
nockScope,
blockNumber = DEFAULT_LATEST_BLOCK_NUMBER,
}) {
await mockInfuraRpcCall({
nockScope,
request: { method: 'eth_blockNumber', params: [] },
response: { result: blockNumber },
}).persist();
}

/**
* Mocks a JSON-RPC request sent to Infura with the given response.
*
* @param {MockSuccessfulInfuraRpcCallOptions} args - The arguments.
* @param {MockInfuraRpcCallOptions} args - The arguments.
* @param {NockScope} args.nockScope - A nock scope (a set of mocked requests
* scoped to a certain base URL).
* @param {object} args.request - The request data.
* @param {object} args.response - The response that the request should have.
* @param {number} args.delay - The amount of time that should pass before the
* @param {{body: string} | {httpStatus?: number; id?: number; method?: string; params?: string[]}} [args.response] - Information
* concerning the response that the request should have. If a `body` property is
* present, this is taken as the complete response body. If an `httpStatus`
* property is present, then it is taken as the HTTP status code to respond
* with. Properties other than these two are used to build a complete response
* body (including `id` and `jsonrpc` properties).
* @param {Error | string} [args.error] - An error to throw while making the
* request. Takes precedence over `response`.
* @param {number} [args.delay] - The amount of time that should pass before the
* request resolves with the response.
* @param {number} [args.times] - The number of times that the request is
* expected to be made.
* @returns {NockScope} The nock scope.
*/
function mockSuccessfulInfuraRpcCall({ nockScope, request, response, delay }) {
// eth-query always passes `params`, so even if we don't supply this property
function mockInfuraRpcCall({
nockScope,
request,
response,
error,
delay,
times,
}) {
// eth-query always passes `params`, so even if we don't supply this property,
// for consistency with makeRpcCall, assume that the `body` contains it
const { method, params = [], ...rest } = request;
const completeResponse = {
id: 1,
jsonrpc: '2.0',
...response,
};
const nockRequest = nockScope.post(`/v3/${INFURA_PROJECT_ID}`, {
const httpStatus = response?.httpStatus ?? 200;
let completeResponse;
if (response !== undefined) {
if (response.body === undefined) {
completeResponse = { id: 1, jsonrpc: '2.0' };
['id', 'jsonrpc', 'result', 'error'].forEach((prop) => {
if (response[prop] !== undefined) {
completeResponse[prop] = response[prop];
}
});
} else {
completeResponse = response.body;
}
}
let nockRequest = nockScope.post(`/v3/${INFURA_PROJECT_ID}`, {
jsonrpc: '2.0',
method,
params,
...rest,
});

if (delay !== undefined) {
nockRequest.delay(delay);
nockRequest = nockRequest.delay(delay);
}

if (times !== undefined) {
nockRequest = nockRequest.times(times);
}

return nockRequest.reply(200, completeResponse);
if (error !== undefined) {
return nockRequest.replyWithError(error);
} else if (completeResponse !== undefined) {
return nockRequest.reply(httpStatus, completeResponse);
}
return nockRequest;
}

/**
Expand Down Expand Up @@ -189,7 +243,7 @@ function makeRpcCall(ethQuery, request) {
/**
* Sets up request mocks for requests to Infura.
*
* @param {MockingInfuraCommunicationsArgs} args - Either an options bag + a
* @param {WithMockedInfuraCommunicationsArgs} args - Either an options bag + a
* function, or just a function. The options bag, at the moment, may contain
* `network` (that is, the Infura network; defaults to "mainnet"). The function
* is called with an object that allows you to mock different kinds of requests.
Expand All @@ -202,11 +256,14 @@ export async function withMockedInfuraCommunications(...args) {
const nockScope = buildScopeForMockingInfuraRequests({ network });
const curriedMockNextBlockTrackerRequest = (localOptions) =>
mockNextBlockTrackerRequest({ nockScope, ...localOptions });
const curriedMockSuccessfulInfuraRpcCall = (localOptions) =>
mockSuccessfulInfuraRpcCall({ nockScope, ...localOptions });
const curriedMockAllBlockTrackerRequests = (localOptions) =>
mockAllBlockTrackerRequests({ nockScope, ...localOptions });
const curriedMockInfuraRpcCall = (localOptions) =>
mockInfuraRpcCall({ nockScope, ...localOptions });
const comms = {
mockNextBlockTrackerRequest: curriedMockNextBlockTrackerRequest,
mockSuccessfulInfuraRpcCall: curriedMockSuccessfulInfuraRpcCall,
mockAllBlockTrackerRequests: curriedMockAllBlockTrackerRequests,
mockInfuraRpcCall: curriedMockInfuraRpcCall,
};

try {
Expand Down Expand Up @@ -258,9 +315,10 @@ export async function withInfuraClient(...args) {
// depends on `setTimeout`)
const clock = sinon.useFakeTimers();
const client = {
blockTracker,
clock,
makeRpcCall: curriedMakeRpcCall,
makeRpcCallsInSeries,
clock,
};

try {
Expand Down
Loading

0 comments on commit 984fdfb

Please sign in to comment.