From 1bb6c57dc008bfc98d9787f80d10857e2a07e4c8 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Thu, 28 Nov 2024 16:01:36 +0000 Subject: [PATCH] test: add scaffolding for e2e tests --- .../notifications/network-syncing/mockData.ts | 7 ++ .../network-syncing/rawMockData.ts | 77 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/e2e/tests/notifications/network-syncing/mockData.ts create mode 100644 test/e2e/tests/notifications/network-syncing/rawMockData.ts diff --git a/test/e2e/tests/notifications/network-syncing/mockData.ts b/test/e2e/tests/notifications/network-syncing/mockData.ts new file mode 100644 index 000000000000..c44270d59e01 --- /dev/null +++ b/test/e2e/tests/notifications/network-syncing/mockData.ts @@ -0,0 +1,7 @@ +export const networkSyncMockResponse = [ + { + HashedKey: + '5f7270de7bf5cab310c27a0cb3ce8b460399d3fdc680485b0f597e25b72872cc', + Data: '{"v":"1","t":"scrypt","d":"EogpRnWT/gSAzsuNJ3rJMHSkB/APrGB18yBkRHOtSaKXiKNROaBk70sQtXLJcN8Sa5GOU3uLxJxPrjoqwQ/ZMNOSfYOg2AdJk83BMU+Hpf1F3d4nzR3SX1h2AUbcHR6y3q6O6bMeNNDJa1GlG2HuHdS9FJ+xgRDaLligoG03qrSqqURAftteryweo9LuDC+1p0D4aCxE7yINjzX3rhiomVXQmn6Os5Vrv0ZvkStROxFryN4rGZIoBV+kZPjWUpubpRlzLhwW3VtGdAvOYCZMSLAVtZebLbBin9bi68u7RDvH/DRHkYtxgCTlFBaep26JPCXBqQWN7XeVimpiKE5qImeb9fKk/yS4+A/b0ibrVew4pkMNP7gWRRY/FO7Yp3X3DxVvnhA3rMmeq16cyErRvruis67c46S+/TuF25T9CytpEHt/DIGd3hYchpTYdwCIVx5jTyXziJ5xt7EuyduJUHReokR4yAdSDpcgnF+LFtXYqmTxxoEj8KR386MQePrILaS2phSSnn3IvevP449uzsgHL/Kz","o":{"N":131072,"r":8,"p":1,"dkLen":16},"saltLen":16}', + }, +]; diff --git a/test/e2e/tests/notifications/network-syncing/rawMockData.ts b/test/e2e/tests/notifications/network-syncing/rawMockData.ts new file mode 100644 index 000000000000..d471ff9767ea --- /dev/null +++ b/test/e2e/tests/notifications/network-syncing/rawMockData.ts @@ -0,0 +1,77 @@ +import { + NetworkConfiguration, + RpcEndpointType, +} from '@metamask/network-controller'; +import { + Encryption, + createSHA256Hash, +} from '@metamask/profile-sync-controller/sdk'; +import { NOTIFICATIONS_TEAM_STORAGE_KEY } from '../constants'; + +export type RPCEndpoint = NetworkConfiguration['rpcEndpoints'][number]; + +export const createMockInfuraRPC = (): RPCEndpoint => ({ + type: RpcEndpointType.Infura, + networkClientId: 'mainnet', + url: `https://mainnet.infura.io/v3/{infuraProjectId}`, +}); + +export const createMockCustomRpcEndpoint = ( + override: Partial>, +): RPCEndpoint => { + return { + type: RpcEndpointType.Custom, + networkClientId: '1111-1111-1111', + url: `https://FAKE_RPC/`, + ...override, + } as RPCEndpoint; +}; + +export const createMockNetworkConfiguration = ( + override?: Partial, +): NetworkConfiguration => { + return { + chainId: '0x1337', + blockExplorerUrls: ['https://etherscan.io'], + defaultRpcEndpointIndex: 0, + name: 'Mock Network', + nativeCurrency: 'MOCK TOKEN', + rpcEndpoints: [], + defaultBlockExplorerUrlIndex: 0, + ...override, + }; +}; + +// Run this to generate the `mockData.ts` data +const generateMockEncryptedData = async () => { + const networkConfig1337 = createMockNetworkConfiguration({ + chainId: '0x1337', + rpcEndpoints: [ + createMockCustomRpcEndpoint({ + networkClientId: '1', + url: `https://FAKE_RPC_1/`, + }), + createMockCustomRpcEndpoint({ + networkClientId: '2', + url: `https://FAKE_RPC_2/`, + }), + ], + // you can pass a very large lastUpdatedAt if you want it to win + // or you can pass a small number/0 for it to lose + // or you can leave undefined if you want to test if remote does not have this field + lastUpdatedAt: 9999999999999, + }); + + const encryptedData = await Encryption.encryptString( + JSON.stringify(networkConfig1337), + NOTIFICATIONS_TEAM_STORAGE_KEY, + ); + const encryptedHash = createSHA256Hash( + '0x1337' + NOTIFICATIONS_TEAM_STORAGE_KEY, + ); + + return { + HashedKey: encryptedHash, + Data: encryptedData, + }; +};