Skip to content

Commit

Permalink
Merge branch 'develop' into feat/upgrade-preferences-controller-to-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
kanthesha authored Sep 25, 2024
2 parents 8db2f41 + 8c3e71f commit 68b75bf
Show file tree
Hide file tree
Showing 69 changed files with 1,239 additions and 440 deletions.
9 changes: 9 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion app/scripts/lib/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,25 @@ describe('app utils', () => {
name: 'Approve Tokens',
},
};

it('return null if use4ByteResolution is not true', async () => {
expect(
await getMethodDataName(knownMethodData, false, '0x60806040'),
).toStrictEqual(null);
});

it('return null if prefixedData is not defined', async () => {
expect(
await getMethodDataName(knownMethodData, true, undefined),
).toStrictEqual(null);
});

it('return details from knownMethodData if defined', async () => {
expect(
await getMethodDataName(knownMethodData, true, '0x60806040'),
).toStrictEqual(knownMethodData['0x60806040']);
});

it('invoke getMethodDataAsync if details not available in knownMethodData', async () => {
const DUMMY_METHOD_NAME = {
name: 'Dummy Method Name',
Expand All @@ -392,9 +396,10 @@ describe('app utils', () => {
.spyOn(FourBiteUtils, 'getMethodDataAsync')
.mockResolvedValue(DUMMY_METHOD_NAME);
expect(
await getMethodDataName(knownMethodData, true, '0x123'),
await getMethodDataName(knownMethodData, true, '0x123', jest.fn()),
).toStrictEqual(DUMMY_METHOD_NAME);
});

it('invoke addKnownMethodData if details not available in knownMethodData', async () => {
const DUMMY_METHOD_NAME = {
name: 'Dummy Method Name',
Expand All @@ -413,5 +418,22 @@ describe('app utils', () => {
).toStrictEqual(DUMMY_METHOD_NAME);
expect(addKnownMethodData).toHaveBeenCalledTimes(1);
});

it('does not invoke addKnownMethodData if no method data available', async () => {
const addKnownMethodData = jest.fn();

jest.spyOn(FourBiteUtils, 'getMethodDataAsync').mockResolvedValue({});

expect(
await getMethodDataName(
knownMethodData,
true,
'0x123',
addKnownMethodData,
),
).toStrictEqual({});

expect(addKnownMethodData).toHaveBeenCalledTimes(0);
});
});
});
2 changes: 1 addition & 1 deletion app/scripts/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export const getMethodDataName = async (
provider,
);

if (addKnownMethodData) {
if (methodData?.name) {
addKnownMethodData(fourBytePrefix, methodData as MethodData);
}

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ export default class MetamaskController extends EventEmitter {
},
},
env: {
isAccountSyncingEnabled: true,
isAccountSyncingEnabled: isManifestV3,
},
messenger: this.controllerMessenger.getRestricted({
name: 'UserStorageController',
Expand Down
4 changes: 4 additions & 0 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2069,14 +2069,18 @@
"URL": true,
"URLSearchParams": true,
"addEventListener": true,
"clearInterval": true,
"console.error": true,
"dispatchEvent": true,
"fetch": true,
"removeEventListener": true,
"setInterval": true,
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
Expand Down
4 changes: 4 additions & 0 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2069,14 +2069,18 @@
"URL": true,
"URLSearchParams": true,
"addEventListener": true,
"clearInterval": true,
"console.error": true,
"dispatchEvent": true,
"fetch": true,
"removeEventListener": true,
"setInterval": true,
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
Expand Down
4 changes: 4 additions & 0 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2069,14 +2069,18 @@
"URL": true,
"URLSearchParams": true,
"addEventListener": true,
"clearInterval": true,
"console.error": true,
"dispatchEvent": true,
"fetch": true,
"removeEventListener": true,
"setInterval": true,
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
Expand Down
4 changes: 4 additions & 0 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2161,14 +2161,18 @@
"URL": true,
"URLSearchParams": true,
"addEventListener": true,
"clearInterval": true,
"console.error": true,
"dispatchEvent": true,
"fetch": true,
"removeEventListener": true,
"setInterval": true,
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
"@keystonehq/bc-ur-registry-eth": "^0.19.1",
"@keystonehq/metamask-airgapped-keyring": "^0.13.1",
"@lavamoat/lavadome-react": "0.0.17",
"@lavamoat/snow": "^2.0.1",
"@lavamoat/snow": "^2.0.2",
"@material-ui/core": "^4.11.0",
"@metamask-institutional/custody-controller": "^0.2.31",
"@metamask-institutional/custody-keyring": "^2.0.3",
Expand Down Expand Up @@ -344,7 +344,7 @@
"@metamask/post-message-stream": "^8.0.0",
"@metamask/ppom-validator": "0.34.0",
"@metamask/preinstalled-example-snap": "^0.1.0",
"@metamask/profile-sync-controller": "^0.8.0",
"@metamask/profile-sync-controller": "^0.9.1",
"@metamask/providers": "^14.0.2",
"@metamask/queued-request-controller": "^2.0.0",
"@metamask/rate-limit-controller": "^6.0.0",
Expand Down
19 changes: 19 additions & 0 deletions shared/lib/four-byte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ describe('Four Byte', () => {

expect(result).toStrictEqual('someOtherFunction(address,uint256)');
});

// @ts-expect-error This is missing from the Mocha type definitions
it.each([undefined, null, '', '0x', '0X'])(
'returns undefined if four byte prefix is %s',
async (prefix: string) => {
expect(await getMethodFrom4Byte(prefix)).toBeUndefined();
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each([
['with hex prefix', '0x1234567'],
['without hex prefix', '1234567'],
])(
'returns undefined if length of four byte prefix %s is less than 8',
async (_: string, prefix: string) => {
expect(await getMethodFrom4Byte(prefix)).toBeUndefined();
},
);
});

describe('getMethodDataAsync', () => {
Expand Down
12 changes: 11 additions & 1 deletion shared/lib/four-byte.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { MethodRegistry } from 'eth-method-registry';
import { Hex } from '@metamask/utils';
import { hasTransactionData } from '../modules/transaction.utils';
import { stripHexPrefix } from '../modules/hexstring-utils';
import fetchWithCache from './fetch-with-cache';

type FourByteResult = {
Expand All @@ -12,7 +15,14 @@ type FourByteResponse = {

export async function getMethodFrom4Byte(
fourBytePrefix: string,
): Promise<string> {
): Promise<string | undefined> {
if (
!hasTransactionData(fourBytePrefix as Hex) ||
stripHexPrefix(fourBytePrefix)?.length < 8
) {
return undefined;
}

const fourByteResponse = (await fetchWithCache({
url: `https://www.4byte.directory/api/v1/signatures/?hex_signature=${fourBytePrefix}`,
fetchOptions: {
Expand Down
17 changes: 17 additions & 0 deletions shared/modules/transaction.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TransactionType } from '@metamask/transaction-controller';
import { createTestProviderTools } from '../../test/stub/provider';
import {
determineTransactionType,
hasTransactionData,
isEIP1559Transaction,
isLegacyTransaction,
parseStandardTokenTransactionData,
Expand Down Expand Up @@ -417,4 +418,20 @@ describe('Transaction.utils', function () {
});
});
});

describe('hasTransactionData', () => {
it.each([
['has prefix', '0x1234'],
['has no prefix', '1234'],
])('returns true if data %s', (_, data) => {
expect(hasTransactionData(data)).toBe(true);
});

it.each([undefined, null, '', '0x', '0X'])(
'returns false if data is %s',
(data) => {
expect(hasTransactionData(data)).toBe(false);
},
);
});
});
7 changes: 7 additions & 0 deletions shared/modules/transaction.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@metamask/transaction-controller';
import type { TransactionParams } from '@metamask/transaction-controller';

import { Hex } from '@metamask/utils';
import { AssetType, TokenStandard } from '../constants/transaction';
import { readAddressAsContract } from './contract-utils';
import { isEqualCaseInsensitive } from './string-utils';
Expand Down Expand Up @@ -319,3 +320,9 @@ export const parseTypedDataMessage = (dataToParse: string) => {

return result;
};

export function hasTransactionData(transactionData?: Hex): boolean {
return Boolean(
transactionData?.length && transactionData?.toLowerCase?.() !== '0x',
);
}
1 change: 0 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ sonar.organization=consensys
sonar.sources=app,development,offscreen,shared,types,ui
sonar.exclusions=**/*.test.**,**/*.spec.**,app/images,test/e2e/page-objects,test/data


# Tests
sonar.tests=app,development,offscreen,shared,test,types,ui
sonar.test.inclusions=**/*.test.**,**/*.spec.**
Expand Down
62 changes: 0 additions & 62 deletions test/e2e/accounts/snap-account-settings.spec.ts

This file was deleted.

Loading

0 comments on commit 68b75bf

Please sign in to comment.