You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
429 lines
15 KiB
429 lines
15 KiB
4 years ago
|
import { KOVAN_CHAIN_ID } from '../../shared/constants/network';
|
||
5 years ago
|
import {
|
||
|
getConnectedDomainsForSelectedAddress,
|
||
|
getOrderedConnectedAccountsForActiveTab,
|
||
|
getPermissionsForActiveTab,
|
||
4 years ago
|
} from './permissions';
|
||
5 years ago
|
|
||
4 years ago
|
describe('selectors', () => {
|
||
|
describe('getConnectedDomainsForSelectedAddress', () => {
|
||
|
it('should return the list of connected domains when there is 1 connected account', () => {
|
||
5 years ago
|
const mockState = {
|
||
|
metamask: {
|
||
|
selectedAddress: '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
|
domainMetadata: {
|
||
|
'peepeth.com': {
|
||
4 years ago
|
icon: 'https://peepeth.com/favicon-32x32.png',
|
||
|
name: 'Peepeth',
|
||
|
host: 'peepeth.com',
|
||
5 years ago
|
},
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
icon: 'https://remix.ethereum.org/icon.png',
|
||
|
name: 'Remix - Ethereum IDE',
|
||
|
host: 'remix.ethereum.org',
|
||
5 years ago
|
},
|
||
|
},
|
||
|
domains: {
|
||
|
'peepeth.com': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
|
type: 'filterResponse',
|
||
|
value: ['0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'],
|
||
5 years ago
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1585676177970,
|
||
|
'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
|
||
|
'invoker': 'peepeth.com',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
type: 'filterResponse',
|
||
|
value: ['0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'],
|
||
|
name: 'exposedAccounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1585685128948,
|
||
|
'id': '6b9615cc-64e4-4317-afab-3c4f8ee0244a',
|
||
|
'invoker': 'https://remix.ethereum.org',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
|
const extensionId = undefined;
|
||
4 years ago
|
expect(getConnectedDomainsForSelectedAddress(mockState)).toStrictEqual([
|
||
4 years ago
|
{
|
||
|
extensionId,
|
||
|
icon: 'https://peepeth.com/favicon-32x32.png',
|
||
|
origin: 'peepeth.com',
|
||
|
name: 'Peepeth',
|
||
|
host: 'peepeth.com',
|
||
|
},
|
||
|
{
|
||
|
extensionId,
|
||
|
name: 'Remix - Ethereum IDE',
|
||
|
icon: 'https://remix.ethereum.org/icon.png',
|
||
|
origin: 'https://remix.ethereum.org',
|
||
|
host: 'remix.ethereum.org',
|
||
|
},
|
||
4 years ago
|
]);
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should return the list of connected domains when there are 2 connected accounts', () => {
|
||
5 years ago
|
const mockState = {
|
||
|
metamask: {
|
||
|
selectedAddress: '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
|
domainMetadata: {
|
||
|
'peepeth.com': {
|
||
4 years ago
|
icon: 'https://peepeth.com/favicon-32x32.png',
|
||
|
name: 'Peepeth',
|
||
|
host: 'peepeth.com',
|
||
5 years ago
|
},
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
icon: 'https://remix.ethereum.org/icon.png',
|
||
|
name: 'Remix - Ethereum IDE',
|
||
|
host: 'remix.ethereum.com',
|
||
5 years ago
|
},
|
||
|
},
|
||
|
domains: {
|
||
|
'peepeth.com': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
|
type: 'filterResponse',
|
||
|
value: ['0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'],
|
||
5 years ago
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1585676177970,
|
||
|
'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
|
||
|
'invoker': 'peepeth.com',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
type: 'filterResponse',
|
||
|
value: [
|
||
5 years ago
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
|
],
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1585685128948,
|
||
|
'id': '6b9615cc-64e4-4317-afab-3c4f8ee0244a',
|
||
|
'invoker': 'https://remix.ethereum.org',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
|
const extensionId = undefined;
|
||
4 years ago
|
expect(getConnectedDomainsForSelectedAddress(mockState)).toStrictEqual([
|
||
4 years ago
|
{
|
||
|
extensionId,
|
||
|
name: 'Remix - Ethereum IDE',
|
||
|
icon: 'https://remix.ethereum.org/icon.png',
|
||
|
origin: 'https://remix.ethereum.org',
|
||
|
host: 'remix.ethereum.com',
|
||
|
},
|
||
4 years ago
|
]);
|
||
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('getConnectedAccountsForActiveTab', () => {
|
||
5 years ago
|
const mockState = {
|
||
|
activeTab: {
|
||
4 years ago
|
title: 'Eth Sign Tests',
|
||
|
origin: 'https://remix.ethereum.org',
|
||
|
protocol: 'https:',
|
||
|
url: 'https://remix.ethereum.org/',
|
||
5 years ago
|
},
|
||
|
metamask: {
|
||
4 years ago
|
provider: {
|
||
|
chainId: KOVAN_CHAIN_ID,
|
||
|
},
|
||
5 years ago
|
accounts: {
|
||
|
0x7250739de134d33ec7ab1ee592711e15098c9d2d: {
|
||
|
address: '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
5 years ago
|
},
|
||
5 years ago
|
0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5: {
|
||
|
address: '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
5 years ago
|
},
|
||
5 years ago
|
0xb3958fb96c8201486ae20be1d5c9f58083df343a: {
|
||
|
address: '0xb3958fb96c8201486ae20be1d5c9f58083df343a',
|
||
|
},
|
||
|
0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc: {
|
||
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
|
},
|
||
|
0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4: {
|
||
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
5 years ago
|
},
|
||
|
},
|
||
5 years ago
|
cachedBalances: {},
|
||
5 years ago
|
domains: {
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
|
type: 'filterResponse',
|
||
|
value: [
|
||
5 years ago
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
5 years ago
|
'0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a',
|
||
5 years ago
|
],
|
||
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1586359844177,
|
||
|
'id': '3aa65a8b-3bcb-4944-941b-1baa5fe0ed8b',
|
||
|
'invoker': 'https://remix.ethereum.org',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
|
'peepeth.com': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
|
type: 'filterResponse',
|
||
|
value: ['0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'],
|
||
5 years ago
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1585676177970,
|
||
|
'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
|
||
|
'invoker': 'peepeth.com',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
5 years ago
|
identities: {
|
||
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': {
|
||
4 years ago
|
address: '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
|
name: 'Really Long Name That Should Be Truncated',
|
||
5 years ago
|
},
|
||
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
|
||
4 years ago
|
address: '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
5 years ago
|
lastSelected: 1586359844192,
|
||
4 years ago
|
name: 'Account 1',
|
||
5 years ago
|
},
|
||
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a': {
|
||
|
lastSelected: 1586359844193,
|
||
4 years ago
|
address: '0xb3958fb96c8201486ae20be1d5c9f58083df343a',
|
||
|
name: 'Account 2',
|
||
5 years ago
|
},
|
||
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
|
||
4 years ago
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
5 years ago
|
lastSelected: 1586359844192,
|
||
4 years ago
|
name: 'Account 3',
|
||
5 years ago
|
},
|
||
|
'0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4': {
|
||
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
|
name: 'Account 4',
|
||
5 years ago
|
},
|
||
|
},
|
||
4 years ago
|
keyrings: [
|
||
|
{
|
||
|
accounts: [
|
||
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
|
'0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a',
|
||
|
],
|
||
|
},
|
||
|
],
|
||
5 years ago
|
permissionsHistory: {
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
eth_accounts: {
|
||
|
accounts: {
|
||
5 years ago
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': 1586359844192,
|
||
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': 1586359844192,
|
||
5 years ago
|
'0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4': 1586359844192,
|
||
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': 1586359844192,
|
||
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a': 1586359844192,
|
||
5 years ago
|
},
|
||
4 years ago
|
lastApproved: 1586359844192,
|
||
5 years ago
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
it('should return connected accounts sorted by last selected, then by keyring controller order', () => {
|
||
|
expect(getOrderedConnectedAccountsForActiveTab(mockState)).toStrictEqual([
|
||
|
{
|
||
|
address: '0xb3958fb96c8201486ae20be1d5c9f58083df343a',
|
||
|
name: 'Account 2',
|
||
|
lastActive: 1586359844192,
|
||
|
lastSelected: 1586359844193,
|
||
|
},
|
||
|
{
|
||
|
address: '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
|
name: 'Account 1',
|
||
|
lastActive: 1586359844192,
|
||
|
lastSelected: 1586359844192,
|
||
|
},
|
||
|
{
|
||
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
|
name: 'Account 3',
|
||
|
lastActive: 1586359844192,
|
||
|
lastSelected: 1586359844192,
|
||
|
},
|
||
|
{
|
||
|
address: '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
|
name: 'Really Long Name That Should Be Truncated',
|
||
|
lastActive: 1586359844192,
|
||
|
},
|
||
|
{
|
||
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
|
name: 'Account 4',
|
||
|
lastActive: 1586359844192,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('getPermissionsForActiveTab', () => {
|
||
5 years ago
|
const mockState = {
|
||
|
activeTab: {
|
||
4 years ago
|
title: 'Eth Sign Tests',
|
||
|
origin: 'https://remix.ethereum.org',
|
||
|
protocol: 'https:',
|
||
|
url: 'https://remix.ethereum.org/',
|
||
5 years ago
|
},
|
||
|
metamask: {
|
||
|
identities: {
|
||
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': {
|
||
4 years ago
|
address: '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
|
name: 'Really Long Name That Should Be Truncated',
|
||
5 years ago
|
},
|
||
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': {
|
||
4 years ago
|
address: '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
|
name: 'Account 1',
|
||
5 years ago
|
},
|
||
|
'0xb3958fb96c8201486ae20be1d5c9f58083df343a': {
|
||
4 years ago
|
address: '0xb3958fb96c8201486ae20be1d5c9f58083df343a',
|
||
|
name: 'Account 2',
|
||
5 years ago
|
},
|
||
|
},
|
||
|
domains: {
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
|
type: 'filterResponse',
|
||
|
value: [
|
||
5 years ago
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
|
||
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d',
|
||
|
],
|
||
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1586359844177,
|
||
|
'id': '3aa65a8b-3bcb-4944-941b-1baa5fe0ed8b',
|
||
|
'invoker': 'https://remix.ethereum.org',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
|
'peepeth.com': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
|
type: 'filterResponse',
|
||
|
value: ['0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'],
|
||
5 years ago
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1585676177970,
|
||
|
'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
|
||
|
'invoker': 'peepeth.com',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
|
'uniswap.exchange': {
|
||
4 years ago
|
permissions: [
|
||
5 years ago
|
{
|
||
4 years ago
|
'@context': ['https://github.com/MetaMask/rpc-cap'],
|
||
4 years ago
|
'caveats': [
|
||
5 years ago
|
{
|
||
4 years ago
|
name: 'exposedAccounts',
|
||
|
type: 'filterResponse',
|
||
|
value: ['0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'],
|
||
5 years ago
|
},
|
||
|
],
|
||
4 years ago
|
'date': 1585616816623,
|
||
|
'id': 'ce625215-f2e9-48e7-93ca-21ba193244ff',
|
||
|
'invoker': 'uniswap.exchange',
|
||
|
'parentCapability': 'eth_accounts',
|
||
5 years ago
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
domainMetadata: {
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
icon: 'https://remix.ethereum.org/icon.png',
|
||
|
name: 'Remix - Ethereum IDE',
|
||
5 years ago
|
},
|
||
|
},
|
||
|
permissionsHistory: {
|
||
5 years ago
|
'https://remix.ethereum.org': {
|
||
4 years ago
|
eth_accounts: {
|
||
|
accounts: {
|
||
5 years ago
|
'0x7250739de134d33ec7ab1ee592711e15098c9d2d': 1586359844192,
|
||
|
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5': 1586359844192,
|
||
|
},
|
||
4 years ago
|
lastApproved: 1586359844192,
|
||
5 years ago
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
it('should return a list of permissions strings', () => {
|
||
|
expect(getPermissionsForActiveTab(mockState)).toStrictEqual([
|
||
4 years ago
|
{
|
||
|
key: 'eth_accounts',
|
||
|
},
|
||
4 years ago
|
]);
|
||
|
});
|
||
|
});
|
||
|
});
|