Bump dev deps (#1215)

* Bump dev deps

* Bump deps
This commit is contained in:
Jaco
2023-02-25 14:18:38 +02:00
committed by GitHub
parent c5aa85bb75
commit c9edeea445
29 changed files with 576 additions and 2221 deletions
-17
View File
@@ -1,17 +0,0 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0
const config = require('@polkadot/dev/config/jest.cjs');
module.exports = {
...config,
moduleNameMapper: {
'@polkadot/extension-(base|chains|compat-metamask|dapp|inject|mocks|ui)(.*)$': '<rootDir>/packages/extension-$1/src/$2',
// eslint-disable-next-line sort-keys
'@polkadot/extension(.*)$': '<rootDir>/packages/extension/src/$1',
'\\.(css|less)$': 'empty/object',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/packages/extension-mocks/src/fileMock.cjs'
},
setupFilesAfterEnv: ['<rootDir>/jest/setupEnv.js'],
testEnvironment: 'jsdom'
};
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2017-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0
import nodeCrypto from 'crypto';
import { TextDecoder } from '@polkadot/x-textencoder/node';
import { TextEncoder } from '@polkadot/x-textencoder/node';
window.crypto ??= {
getRandomValues: function (buffer) {
return nodeCrypto.randomFillSync(buffer);
}
};
global.TextDecoder ??= TextDecoder;
global.TextEncoder ??= TextEncoder;
+6 -6
View File
@@ -27,19 +27,19 @@
"build:ui": "cd packages/extension && NODE_ENV=production yarn polkadot-exec-webpack --config webpack.extension.cjs --mode production",
"build:zip": "yarn build:zip:dst && yarn build:zip:src",
"build:zip:dst": "rm -rf ./master-build.zip && cd packages/extension/build && zip -r -FS ../../../master-build.zip .",
"build:zip:src": "rm -rf ./master-src.zip && zip -r -x '*build/*' -x '*node_modules*' -FS ./master-src.zip packages .editorconfig .eslintignore .eslintrc.js babel.config.cjs CHANGELOG.md CONTRIBUTING.md i18next-scanner.config.js jest.config.cjs LICENSE package.json README.md tsconfig.json yarn.lock",
"build:zip:src": "rm -rf ./master-src.zip && zip -r -x '*build/*' -x '*node_modules*' -FS ./master-src.zip packages .editorconfig .eslintignore .eslintrc.js babel.config.cjs CHANGELOG.md CONTRIBUTING.md i18next-scanner.config.js LICENSE package.json README.md tsconfig.json yarn.lock",
"clean": "polkadot-dev-clean-build",
"lint": "polkadot-dev-run-lint",
"postinstall": "polkadot-dev-yarn-only",
"start": "yarn watch",
"test": "EXTENSION_PREFIX='test' polkadot-dev-run-test --env jest",
"test:one": "EXTENSION_PREFIX='test' polkadot-dev-run-test --env jest",
"test": "EXTENSION_PREFIX='test' polkadot-dev-run-test --env browser ^:.spec.tsx",
"test:one": "EXTENSION_PREFIX='test' polkadot-dev-run-test --env browser",
"watch": "cd packages/extension && yarn polkadot-exec-webpack --config webpack.watch.cjs --mode development --watch"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@polkadot/dev": "^0.68.41",
"@types/jest": "^29.4.0",
"@babel/core": "^7.21.0",
"@polkadot/dev": "^0.69.14",
"@types/node": "^18.14.1",
"i18next-scanner": "^4.1.1",
"sinon-chrome": "^3.0.1"
},
+1 -1
View File
@@ -20,7 +20,7 @@
"version": "0.44.10-0-x",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"@polkadot/api": "^9.14.2",
"@polkadot/extension-chains": "^0.44.10-0-x",
"@polkadot/extension-dapp": "^0.44.10-0-x",
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ResponseSigning } from '@polkadot/extension-base/background/types';
@@ -28,23 +31,29 @@ describe('Extension', () => {
const address = '5FbSap4BsWfjyRhCchoVdZHkDnmDm3NEgLZ25mesq4aw2WvX';
async function createExtension (): Promise<Extension> {
await cryptoWaitReady();
try {
await cryptoWaitReady();
keyring.loadAll({ store: new AccountsStore() });
const authUrls: AuthUrls = {};
keyring.loadAll({ store: new AccountsStore() });
const authUrls: AuthUrls = {};
authUrls['localhost:3000'] = {
authorizedAccounts: [address],
count: 0,
id: '11',
origin: 'example.com',
url: 'http://localhost:3000'
};
localStorage.setItem('authUrls', JSON.stringify(authUrls));
state = new State();
tabs = new Tabs(state);
authUrls['localhost:3000'] = {
authorizedAccounts: [address],
count: 0,
id: '11',
origin: 'example.com',
url: 'http://localhost:3000'
};
localStorage.setItem('authUrls', JSON.stringify(authUrls));
state = new State();
tabs = new Tabs(state);
return new Extension(state);
return new Extension(state);
} catch (e) {
console.error(e);
throw e;
}
}
const createAccount = async (type?: KeypairType): Promise<string> => {
@@ -76,7 +85,7 @@ describe('Extension', () => {
extension = await createExtension();
});
test('exports account from keyring', async () => {
it('exports account from keyring', async () => {
const { pair: { address } } = keyring.addUri(suri, password);
const result = await extension.handle('id', 'pri(accounts.export)', {
address,
@@ -94,36 +103,36 @@ describe('Extension', () => {
address = await createAccount();
});
test('pri(derivation.validate) passes for valid suri', async () => {
it('pri(derivation.validate) passes for valid suri', async () => {
const result = await extension.handle('id', 'pri(derivation.validate)', {
parentAddress: address,
parentPassword: password,
suri: '//path'
}, {} as chrome.runtime.Port);
expect(result).toStrictEqual({
expect(result).toEqual({
address: '5FP3TT3EruYBNh8YM8yoxsreMx7uZv1J1zNX7fFhoC5enwmN',
suri: '//path'
});
});
test('pri(derivation.validate) throws for invalid suri', async () => {
it('pri(derivation.validate) throws for invalid suri', async () => {
await expect(extension.handle('id', 'pri(derivation.validate)', {
parentAddress: address,
parentPassword: password,
suri: 'invalid-path'
}, {} as chrome.runtime.Port)).rejects.toStrictEqual(new Error('"invalid-path" is not a valid derivation path'));
}, {} as chrome.runtime.Port)).rejects.toThrow(/is not a valid derivation path/);
});
test('pri(derivation.validate) throws for invalid password', async () => {
it('pri(derivation.validate) throws for invalid password', async () => {
await expect(extension.handle('id', 'pri(derivation.validate)', {
parentAddress: address,
parentPassword: 'invalid-password',
suri: '//path'
}, {} as chrome.runtime.Port)).rejects.toStrictEqual(new Error('invalid password'));
}, {} as chrome.runtime.Port)).rejects.toThrow(/invalid password/);
});
test('pri(derivation.create) adds a derived account', async () => {
it('pri(derivation.create) adds a derived account', async () => {
await extension.handle('id', 'pri(derivation.create)', {
name: 'child',
parentAddress: address,
@@ -134,7 +143,7 @@ describe('Extension', () => {
expect(keyring.getAccounts()).toHaveLength(2);
});
test('pri(derivation.create) saves parent address in meta', async () => {
it('pri(derivation.create) saves parent address in meta', async () => {
await extension.handle('id', 'pri(derivation.create)', {
name: 'child',
parentAddress: address,
@@ -153,7 +162,7 @@ describe('Extension', () => {
address = await createAccount();
});
test('pri(accounts.changePassword) changes account password', async () => {
it('pri(accounts.changePassword) changes account password', async () => {
const newPass = 'pa55word';
const wrongPass = 'ZZzzZZzz';
@@ -161,13 +170,15 @@ describe('Extension', () => {
address,
newPass,
oldPass: wrongPass
}, {} as chrome.runtime.Port)).rejects.toStrictEqual(new Error('oldPass is invalid'));
}, {} as chrome.runtime.Port)).rejects.toThrow(/oldPass is invalid/);
await expect(extension.handle('id', 'pri(accounts.changePassword)', {
const res = await extension.handle('id', 'pri(accounts.changePassword)', {
address,
newPass,
oldPass: password
}, {} as chrome.runtime.Port)).resolves.toEqual(true);
}, {} as chrome.runtime.Port);
expect(res).toEqual(true);
const pair = keyring.getPair(address);
@@ -175,7 +186,7 @@ describe('Extension', () => {
expect(() => {
pair.decodePkcs8(password);
}).toThrowError('Unable to decode using the supplied passphrase');
}).toThrow(/Unable to decode using the supplied passphrase/);
});
});
@@ -202,7 +213,7 @@ describe('Extension', () => {
};
});
test('signs with default signed extensions', async () => {
it('signs with default signed extensions', async () => {
const registry = new TypeRegistry();
registry.setSignedExtensions(payload.signedExtensions);
@@ -215,14 +226,16 @@ describe('Extension', () => {
expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
}).catch((err) => console.log(err));
await expect(extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
const res = await extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
id: state.allSignRequests[0].id,
password,
savePass: false
}, {} as chrome.runtime.Port)).resolves.toEqual(true);
}, {} as chrome.runtime.Port);
expect(res).toEqual(true);
});
test('signs with default signed extensions - ethereum', async () => {
it('signs with default signed extensions - ethereum', async () => {
const ethAddress = await createAccount('ethereum');
const ethPair = keyring.getPair(ethAddress);
@@ -261,14 +274,16 @@ describe('Extension', () => {
expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
}).catch((err) => console.log(err));
await expect(extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
const res = await extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
id: state.allSignRequests[0].id,
password,
savePass: false
}, {} as chrome.runtime.Port)).resolves.toEqual(true);
}, {} as chrome.runtime.Port);
expect(res).toEqual(true);
});
test('signs with user extensions, known types', async () => {
it('signs with user extensions, known types', async () => {
const types = {} as unknown as Record<string, string>;
const userExtensions = {
@@ -323,14 +338,16 @@ describe('Extension', () => {
expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
}).catch((err) => console.log(err));
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
const res = await extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
id: state.allSignRequests[0].id,
password,
savePass: false
}, {} as chrome.runtime.Port)).resolves.toEqual(true);
}, {} as chrome.runtime.Port);
expect(res).toEqual(true);
});
test('override default signed extension', async () => {
it('override default signed extension', async () => {
const types = {
FeeExchangeV1: {
assetId: 'Compact<AssetId>',
@@ -379,14 +396,16 @@ describe('Extension', () => {
expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
}).catch((err) => console.log(err));
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
const res = await extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
id: state.allSignRequests[0].id,
password,
savePass: false
}, {} as chrome.runtime.Port)).resolves.toEqual(true);
}, {} as chrome.runtime.Port);
expect(res).toEqual(true);
});
test('signs with user extensions, additional types', async () => {
it('signs with user extensions, additional types', async () => {
const types = {
myCustomType: {
feeExchange: 'Compact<AssetId>',
@@ -446,11 +465,13 @@ describe('Extension', () => {
expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
}).catch((err) => console.log(err));
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
const res = await extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
id: state.allSignRequests[0].id,
password,
savePass: false
}, {} as chrome.runtime.Port)).resolves.toEqual(true);
}, {} as chrome.runtime.Port);
expect(res).toEqual(true);
});
});
});
+1 -1
View File
@@ -20,7 +20,7 @@
"version": "0.44.10-0-x",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"@polkadot/extension-inject": "^0.44.10-0-x",
"@polkadot/networks": "^10.4.2",
"@polkadot/util": "^10.4.2",
@@ -20,7 +20,7 @@
"version": "0.44.10-0-x",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"@metamask/detect-provider": "^1.2.0",
"@polkadot/extension-inject": "^0.44.10-0-x",
"@polkadot/types": "^9.14.2",
+1 -1
View File
@@ -20,7 +20,7 @@
"version": "0.44.10-0-x",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"@polkadot/extension-inject": "^0.44.10-0-x",
"@polkadot/util": "^10.4.2",
"@polkadot/util-crypto": "^10.4.2"
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import { u8aConcat, u8aEq, u8aToString } from '@polkadot/util';
import { ETHEREUM, POSTFIX, PREFIX, unwrapBytes, wrapBytes } from './wrapBytes';
+2 -2
View File
@@ -17,7 +17,7 @@
"version": "0.44.10-0-x",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"@polkadot/rpc-provider": "^9.14.2",
"@polkadot/types": "^9.14.2",
"@polkadot/util": "^10.4.2",
@@ -25,7 +25,7 @@
"@polkadot/x-global": "^10.4.2"
},
"devDependencies": {
"@types/chrome": "^0.0.216",
"@types/chrome": "^0.0.217",
"@types/firefox-webext-browser": "^109.0.0"
},
"peerDependencies": {
+1 -1
View File
@@ -17,7 +17,7 @@
"version": "0.44.10-0-x",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"sinon-chrome": "^3.0.1"
}
}
+1 -1
View File
@@ -29,6 +29,6 @@ const messagingFake = new MessagingFake();
chrome.runtime.connect.returns(messagingFake);
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
(window as any).chrome = chrome;
(window as any).chrome = (globalThis as any).chrome = chrome;
export default chrome;
+1 -1
View File
@@ -16,7 +16,7 @@
"type": "module",
"version": "0.44.10-0-x",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-brands-svg-icons": "^6.3.0",
"@fortawesome/free-regular-svg-icons": "^6.3.0",
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -19,17 +22,17 @@ import Account from './Account';
const { configure, mount } = enzyme;
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../../messaging')
}));
// // NOTE Required for spyOn when using @swc/jest
// // https://github.com/swc-project/swc/issues/3843
// jest.mock('../../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../../messaging')
// }));
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
configure({ adapter: new Adapter() });
jest.spyOn(messaging, 'getAllMetadata').mockResolvedValue([]);
jest.spyOn(messaging, 'getAllMetadata').mockImplementation(() => Promise.resolve([]));
describe('Account component', () => {
let wrapper: ReactWrapper;
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -19,12 +22,12 @@ import CreateAccount from '.';
const { configure, mount } = enzyme;
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../../messaging')
}));
// // NOTE Required for spyOn when using @swc/jest
// // https://github.com/swc-project/swc/issues/3843
// jest.mock('../../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../../messaging')
// }));
// For this file, there are a lot of them
/* eslint-disable @typescript-eslint/no-unsafe-argument */
@@ -34,7 +37,7 @@ configure({ adapter: new Adapter() });
describe('Create Account', () => {
let wrapper: ReactWrapper;
let onActionStub: jest.Mock;
let onActionStub: ReturnType<typeof jest.fn>;
const exampleAccount = {
address: 'HjoBp62cvsWDA3vtNMWxz6c9q13ReEHi9UGHK7JbZweH5g5',
seed: 'horse battery staple correct'
@@ -62,8 +65,8 @@ describe('Create Account', () => {
beforeEach(async () => {
onActionStub = jest.fn();
jest.spyOn(messaging, 'createSeed').mockResolvedValue(exampleAccount);
jest.spyOn(messaging, 'createAccountSuri').mockResolvedValue(true);
jest.spyOn(messaging, 'createSeed').mockImplementation(() => Promise.resolve(exampleAccount));
jest.spyOn(messaging, 'createAccountSuri').mockImplementation(() => Promise.resolve(true));
wrapper = mountComponent();
await act(flushAllPromises);
wrapper.update();
@@ -84,7 +87,7 @@ describe('Create Account', () => {
it('clicking "Cancel" redirects to main screen', () => {
wrapper.find(Header).find(ActionText).simulate('click');
expect(onActionStub).toBeCalledWith('/');
expect(onActionStub).toHaveBeenCalledWith('/');
});
it('checking the checkbox enables the Next button', () => {
@@ -119,8 +122,8 @@ describe('Create Account', () => {
wrapper.find('[data-button-action="add new root"] button').simulate('click');
await act(flushAllPromises);
expect(messaging.createAccountSuri).toBeCalledWith('abc', 'abcdef', exampleAccount.seed, 'sr25519', kusamaGenesis);
expect(onActionStub).toBeCalledWith('/');
expect(messaging.createAccountSuri).toHaveBeenCalledWith('abc', 'abcdef', exampleAccount.seed, 'sr25519', kusamaGenesis);
expect(onActionStub).toHaveBeenCalledWith('/');
});
});
});
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -22,12 +25,12 @@ import Derive from '.';
const { configure, mount } = enzyme;
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../../messaging')
}));
// // NOTE Required for spyOn when using @swc/jest
// // https://github.com/swc-project/swc/issues/3843
// jest.mock('../../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../../messaging')
// }));
// For this file, there are a lot of them
/* eslint-disable @typescript-eslint/no-unsafe-argument */
@@ -53,7 +56,7 @@ const accounts = [
describe('Derive', () => {
const mountComponent = async (locked = false, account = 1): Promise<{
wrapper: ReactWrapper;
onActionStub: jest.Mock;
onActionStub: ReturnType<typeof jest.fn>;
}> => {
const onActionStub = jest.fn();
@@ -82,7 +85,7 @@ describe('Derive', () => {
};
let wrapper: ReactWrapper;
let onActionStub: jest.Mock;
let onActionStub: ReturnType<typeof jest.fn>;
const type = async (input: ReactWrapper, value: string): Promise<void> => {
input.simulate('change', { target: { value } });
@@ -103,7 +106,7 @@ describe('Derive', () => {
});
// eslint-disable-next-line @typescript-eslint/require-await
jest.spyOn(messaging, 'validateAccount').mockImplementation(async (_, pass: string) => pass === parentPassword);
jest.spyOn(messaging, 'validateAccount').mockImplementation(async (_, pass) => pass === parentPassword);
// silencing the following expected console.error
console.error = jest.fn();
// eslint-disable-next-line @typescript-eslint/require-await
@@ -259,7 +262,7 @@ describe('Derive', () => {
it('redirects to derive from next account when other option is selected', () => {
wrapper.find('[data-parent-option]').first().simulate('click');
expect(onActionStub).toBeCalledWith(`/account/derive/${accounts[0].address}`);
expect(onActionStub).toHaveBeenCalledWith(`/account/derive/${accounts[0].address}`);
});
});
@@ -296,8 +299,8 @@ describe('Derive', () => {
await act(flushAllPromises);
wrapper.update();
expect(deriveMock).toBeCalledWith(accounts[1].address, defaultDerivation, parentPassword, newAccount.name, newAccount.password, westendGenesis);
expect(onActionStub).toBeCalledWith('/');
expect(deriveMock).toHaveBeenCalledWith(accounts[1].address, defaultDerivation, parentPassword, newAccount.name, newAccount.password, westendGenesis);
expect(onActionStub).toHaveBeenCalledWith('/');
});
});
});
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -20,12 +23,12 @@ import Export from './Export';
const { configure, mount } = enzyme;
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../messaging')
}));
// // NOTE Required for spyOn when using @swc/jest
// // https://github.com/swc-project/swc/issues/3843
// jest.mock('../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../messaging')
// }));
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
configure({ adapter: new Adapter() });
@@ -39,7 +42,7 @@ describe('Export component', () => {
};
beforeEach(() => {
jest.spyOn(messaging, 'exportAccount').mockResolvedValue({ exportedJson: { meta: { name: 'account_name' } } as unknown as KeyringPair$Json });
jest.spyOn(messaging, 'exportAccount').mockImplementation(() => Promise.resolve({ exportedJson: { meta: { name: 'account_name' } } as unknown as KeyringPair$Json }));
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
wrapper = mount(
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -41,12 +44,12 @@ interface QrScanAddressProps {
style?: React.CSSProperties;
}
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../messaging')
}));
// // NOTE Required for spyOn when using @swc/jest
// // https://github.com/swc-project/swc/issues/3843
// jest.mock('../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../messaging')
// }));
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
configure({ adapter: new Adapter() });
@@ -57,14 +60,14 @@ const typeName = async (wrapper: ReactWrapper, value: string) => {
wrapper.update();
};
jest.mock('@polkadot/react-qr', () => {
return {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
QrScanAddress: ({ onScan }: QrScanAddressProps): null => {
return null;
}
};
});
// jest.mock('@polkadot/react-qr', () => {
// return {
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
// QrScanAddress: ({ onScan }: QrScanAddressProps): null => {
// return null;
// }
// };
// });
describe('ImportQr component', () => {
let wrapper: ReactWrapper;
@@ -131,7 +134,7 @@ describe('ImportQr component', () => {
});
it('creates the external account', async () => {
jest.spyOn(messaging, 'createAccountExternal').mockResolvedValue(false);
jest.spyOn(messaging, 'createAccountExternal').mockImplementation(() => Promise.resolve(false));
wrapper.find(Button).simulate('click');
await act(flushAllPromises);
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -27,12 +30,12 @@ const account = {
seed: 'upgrade multiply predict hip multiply march leg devote social outer oppose debris'
};
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../../messaging')
}));
// // NOTE Required for spyOn when using @swc/jest
// // https://github.com/swc-project/swc/issues/3843
// jest.mock('../../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../../messaging')
// }));
// For this file, there are a lot of them
/* eslint-disable @typescript-eslint/no-unsafe-argument */
@@ -40,7 +43,7 @@ jest.mock('../../messaging', (): Record<string, unknown> => ({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
configure({ adapter: new Adapter() });
jest.spyOn(messaging, 'getAllMetadata').mockResolvedValue([]);
jest.spyOn(messaging, 'getAllMetadata').mockImplementation(() => Promise.resolve([]));
const typeSeed = async (wrapper: ReactWrapper, value: string) => {
wrapper.find('textarea').first().simulate('change', { target: { value } });
@@ -93,7 +96,7 @@ describe.skip('ImportSeed', () => {
});
it('shows the expected account when correct seed is typed and next step button is enabled', async () => {
jest.spyOn(messaging, 'validateSeed').mockResolvedValue({ address: account.expectedAddress, suri: account.seed });
jest.spyOn(messaging, 'validateSeed').mockImplementation(() => Promise.resolve({ address: account.expectedAddress, suri: account.seed }));
await typeSeed(wrapper, account.seed);
expect(wrapper.find(Warning).exists()).toBe(false);
@@ -127,7 +130,7 @@ describe.skip('ImportSeed', () => {
it('shows the expected account with derivation when correct seed is typed and next step button is enabled', async () => {
const suri = `${account.seed}${account.derivation}`;
const validateCall = jest.spyOn(messaging, 'validateSeed').mockResolvedValue({ address: account.expectedAddressWithDerivation, suri });
const validateCall = jest.spyOn(messaging, 'validateSeed').mockImplementation(() => Promise.resolve({ address: account.expectedAddressWithDerivation, suri }));
await typeSeed(wrapper, account.seed);
wrapper.find('.advancedToggle').simulate('click');
@@ -144,8 +147,6 @@ describe.skip('ImportSeed', () => {
const wrongPath = 'wrong';
const suri = `${account.seed}${wrongPath}`;
// silencing the following expected console.error
console.error = jest.fn();
// eslint-disable-next-line @typescript-eslint/require-await
const validateCall = jest.spyOn(messaging, 'validateSeed').mockImplementation(async () => {
throw new Error('Some test error message');
@@ -163,7 +164,7 @@ describe.skip('ImportSeed', () => {
});
it('moves to the second step', async () => {
jest.spyOn(messaging, 'validateSeed').mockResolvedValue({ address: account.expectedAddress, suri: account.seed });
jest.spyOn(messaging, 'validateSeed').mockImplementation(() => Promise.resolve({ address: account.expectedAddress, suri: account.seed }));
await typeSeed(wrapper, account.seed);
wrapper.find(Button).simulate('click');
await act(flushAllPromises);
@@ -178,8 +179,8 @@ describe.skip('ImportSeed', () => {
const suri = `${account.seed}${account.derivation}`;
beforeEach(async () => {
jest.spyOn(messaging, 'createAccountSuri').mockResolvedValue(true);
jest.spyOn(messaging, 'validateSeed').mockResolvedValue({ address: account.expectedAddressWithDerivation, suri });
jest.spyOn(messaging, 'createAccountSuri').mockImplementation(() => Promise.resolve(true));
jest.spyOn(messaging, 'validateSeed').mockImplementation(() => Promise.resolve({ address: account.expectedAddressWithDerivation, suri }));
await typeSeed(wrapper, account.seed);
wrapper.find('.advancedToggle').simulate('click');
@@ -196,8 +197,8 @@ describe.skip('ImportSeed', () => {
await act(flushAllPromises);
wrapper.update();
expect(messaging.createAccountSuri).toBeCalledWith(account.name, account.password, suri, undefined, '');
expect(onActionStub).toBeCalledWith('/');
expect(messaging.createAccountSuri).toHaveBeenCalledWith(account.name, account.password, suri, undefined, '');
expect(onActionStub).toHaveBeenCalledWith('/');
});
});
});
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -26,17 +29,17 @@ import Signing from '.';
const { configure, mount } = enzyme;
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../../messaging')
}));
// // NOTE Required for spyOn when using @swc/jest
// // https://github.com/swc-project/swc/issues/3843
// jest.mock('../../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../../messaging')
// }));
jest.mock('../../MetadataCache', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../../MetadataCache')
}));
// jest.mock('../../MetadataCache', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../../MetadataCache')
// }));
// For this file, there are a lot of them
/* eslint-disable @typescript-eslint/no-unsafe-argument */
@@ -46,7 +49,7 @@ configure({ adapter: new Adapter() });
describe('Signing requests', () => {
let wrapper: ReactWrapper;
let onActionStub: jest.Mock;
let onActionStub: ReturnType<typeof jest.fn>;
let signRequests: SigningRequest[] = [];
const emitter = new EventEmitter();
@@ -79,10 +82,10 @@ describe('Signing requests', () => {
const check = (input: ReactWrapper): unknown => input.simulate('change', { target: { checked: true } });
beforeEach(async () => {
jest.spyOn(messaging, 'cancelSignRequest').mockResolvedValue(true);
jest.spyOn(messaging, 'approveSignPassword').mockResolvedValue(true);
jest.spyOn(messaging, 'isSignLocked').mockResolvedValue({ isLocked: true, remainingTime: 0 });
jest.spyOn(MetadataCache, 'getSavedMeta').mockResolvedValue(westendMetadata);
jest.spyOn(messaging, 'cancelSignRequest').mockImplementation(() => Promise.resolve(true));
jest.spyOn(messaging, 'approveSignPassword').mockImplementation(() => Promise.resolve(true));
jest.spyOn(messaging, 'isSignLocked').mockImplementation(() => Promise.resolve({ isLocked: true, remainingTime: 0 }));
jest.spyOn(MetadataCache, 'getSavedMeta').mockImplementation(() => Promise.resolve(westendMetadata));
signRequests = [
{
@@ -297,7 +300,7 @@ describe('Signing requests', () => {
wrapper.find('.cancelButton').find('a').simulate('click');
await act(flushAllPromises);
expect(messaging.cancelSignRequest).toBeCalledWith(signRequests[0].id);
expect(messaging.cancelSignRequest).toHaveBeenCalledWith(signRequests[0].id);
});
it('passes request id and password to approve call', async () => {
@@ -308,7 +311,7 @@ describe('Signing requests', () => {
await act(flushAllPromises);
wrapper.update();
expect(messaging.approveSignPassword).toBeCalledWith(signRequests[0].id, false, 'hunter1');
expect(messaging.approveSignPassword).toHaveBeenCalledWith(signRequests[0].id, false, 'hunter1');
});
it('asks the background to cache the password when the relevant checkbox is checked', async () => {
@@ -322,7 +325,7 @@ describe('Signing requests', () => {
await act(flushAllPromises);
wrapper.update();
expect(messaging.approveSignPassword).toBeCalledWith(signRequests[0].id, true, 'hunter1');
expect(messaging.approveSignPassword).toHaveBeenCalledWith(signRequests[0].id, true, 'hunter1');
});
it('shows an error when the password is wrong', async () => {
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -151,7 +154,7 @@ describe('AccountNamePasswordCreation', () => {
wrapper.find('[data-button-action="add new root"] button').simulate('click');
await act(flushAllPromises);
expect(onCreate).toBeCalledWith(account.name, account.password);
expect(onCreate).toHaveBeenCalledWith(account.name, account.password);
});
describe('All fields are filled correctly, but then', () => {
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -26,15 +29,15 @@ const { configure, mount } = enzyme;
// NOTE Required for spyOn when using @swc/jest
// https://github.com/swc-project/swc/issues/3843
jest.mock('../messaging', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../messaging')
}));
// jest.mock('../messaging', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../messaging')
// }));
jest.mock('../MetadataCache', (): Record<string, unknown> => ({
__esModule: true,
...jest.requireActual('../MetadataCache')
}));
// jest.mock('../MetadataCache', (): Record<string, unknown> => ({
// __esModule: true,
// ...jest.requireActual('../MetadataCache')
// }));
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
configure({ adapter: new Adapter() });
@@ -182,7 +185,7 @@ const genericTestSuite = (account: AccountTestJson, withAccountsInContext = true
});
it('can hide the account', () => {
jest.spyOn(messaging, 'showAccount').mockResolvedValue(false);
jest.spyOn(messaging, 'showAccount').mockImplementation(() => Promise.resolve(false));
const visibleIcon = wrapper.find('FontAwesomeIcon.visibleIcon');
const hiddenIcon = wrapper.find('FontAwesomeIcon.hiddenIcon');
@@ -191,7 +194,7 @@ const genericTestSuite = (account: AccountTestJson, withAccountsInContext = true
expect(hiddenIcon.exists()).toBe(false);
visibleIcon.simulate('click');
expect(messaging.showAccount).toBeCalledWith(address, false);
expect(messaging.showAccount).toHaveBeenCalledWith(address, false);
});
it('can show the account if hidden', async () => {
@@ -203,7 +206,7 @@ const genericTestSuite = (account: AccountTestJson, withAccountsInContext = true
const wrapperHidden = mountedHiddenComponent.wrapper;
jest.spyOn(messaging, 'showAccount').mockResolvedValue(true);
jest.spyOn(messaging, 'showAccount').mockImplementation(() => Promise.resolve(true));
const visibleIcon = wrapperHidden.find('FontAwesomeIcon.visibleIcon');
const hiddenIcon = wrapperHidden.find('FontAwesomeIcon.hiddenIcon');
@@ -212,7 +215,7 @@ const genericTestSuite = (account: AccountTestJson, withAccountsInContext = true
expect(hiddenIcon.exists()).toBe(true);
hiddenIcon.simulate('click');
expect(messaging.showAccount).toBeCalledWith(address, true);
expect(messaging.showAccount).toHaveBeenCalledWith(address, true);
});
it('has settings button', () => {
@@ -302,7 +305,7 @@ describe('Address', () => {
let wrapper: ReactWrapper;
beforeAll(async () => {
jest.spyOn(MetadataCache, 'getSavedMeta').mockResolvedValue(westendMetadata);
jest.spyOn(MetadataCache, 'getSavedMeta').mockImplementation(() => Promise.resolve(westendMetadata));
wrapper = await getWrapper(westEndAccount, [], false);
});
+4 -1
View File
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
@@ -12,7 +15,7 @@ import { exportAccount } from './messaging';
enzyme.configure({ adapter: new Adapter() });
describe('messaging sends message to background via extension port for', () => {
test('exportAccount', () => {
it('exportAccount', () => {
const callback = jest.fn();
chrome.runtime.connect().onMessage.addListener(callback);
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import '@polkadot/extension-mocks/chrome';
import type { ReactWrapper } from 'enzyme';
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import type { AccountJson, AccountWithChildren } from '@polkadot/extension-base/background/types';
import { buildHierarchy } from './buildHierarchy';
@@ -1,6 +1,9 @@
// Copyright 2019-2023 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import { nextDerivationPath } from './nextDerivationPath';
describe('Generate Derivation Path', () => {
+2 -2
View File
@@ -16,13 +16,13 @@
"type": "module",
"version": "0.44.10-0-x",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.0",
"@polkadot/extension-base": "^0.44.10-0-x",
"@polkadot/extension-inject": "^0.44.10-0-x",
"@polkadot/extension-ui": "^0.44.10-0-x"
},
"devDependencies": {
"@polkadot/dev": "^0.68.41",
"@polkadot/dev": "^0.69.14",
"babel-loader": "^8.3.0",
"browser-resolve": "^2.0.0",
"buffer": "^6.0.3",
+350 -2026
View File
File diff suppressed because it is too large Load Diff