From 39595c8a09c6d67b889dc02230c7c5beca262b99 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Fri, 20 Oct 2023 00:06:29 +0200 Subject: [PATCH 1/4] E2E test migrating older V1 state to current RootState --- .changelog/1755.internal.md | 1 + .../tests/migrating-persisted-state.spec.ts | 39 ++++++++ playwright/utils/test-inputs.ts | 98 +++++++++++++++++++ src/app/pages/E2EPage/index.tsx | 12 ++- 4 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 .changelog/1755.internal.md create mode 100644 playwright/tests/migrating-persisted-state.spec.ts diff --git a/.changelog/1755.internal.md b/.changelog/1755.internal.md new file mode 100644 index 0000000000..20fcb3eca8 --- /dev/null +++ b/.changelog/1755.internal.md @@ -0,0 +1 @@ +E2E test migrating older V1 state to current RootState diff --git a/playwright/tests/migrating-persisted-state.spec.ts b/playwright/tests/migrating-persisted-state.spec.ts new file mode 100644 index 0000000000..f586967484 --- /dev/null +++ b/playwright/tests/migrating-persisted-state.spec.ts @@ -0,0 +1,39 @@ +import { test, expect } from '@playwright/test' +import { mockApi } from '../utils/mockApi' +import { warnSlowApi } from '../utils/warnSlowApi' +import { expectNoFatal } from '../utils/expectNoFatal' +import { addPersistedStorage, clearPersistedStorage } from '../utils/storage' +import { password, privateKeyUnlockedState } from '../utils/test-inputs' + +test.beforeEach(async ({ context, page }) => { + await warnSlowApi(context) + await mockApi(context, 0) + await clearPersistedStorage(page) +}) + +test.afterEach(async ({ context }, testInfo) => { + await expectNoFatal(context, testInfo) +}) + +test.describe('Migrating persisted state', () => { + test('Decrypting V1 state should result in valid RootState', async ({ context, page }) => { + await addPersistedStorage(page) + await page.goto('/') + await page.getByPlaceholder('Enter your password here').fill(password) + await page.keyboard.press('Enter') + + const tab2 = await context.newPage() + await tab2.goto('/e2e') + const decryptedStateV1 = await tab2.evaluate(() => { + const store: any = window['store'] + return store.getState() + }) + expect(decryptedStateV1).toEqual({ + ...privateKeyUnlockedState, + persist: { + ...privateKeyUnlockedState.persist, + stringifiedEncryptionKey: expect.any(String), + }, + }) + }) +}) diff --git a/playwright/utils/test-inputs.ts b/playwright/utils/test-inputs.ts index 5cc334040b..799cd70b08 100644 --- a/playwright/utils/test-inputs.ts +++ b/playwright/utils/test-inputs.ts @@ -26,3 +26,101 @@ export const privateKeyPersistedState = JSON.stringify({ nonce: { $Uint8Array$: 'uTf/3wnfC1PnWEoJrmULoMg0qffau4MM' }, salt: { $Uint8Array$: 'dQSGvwmyAqxs/vECZ2eIAkphq0pNKG+w69jNz/lIpKI=' }, }) + +export const privateKeyUnlockedState = { + account: { + address: '', + available: null, + debonding: null, + delegations: null, + total: null, + accountError: undefined, + transactions: [], + transactionsError: undefined, + loading: true, + }, + contacts: {}, + evmAccounts: {}, + createWallet: { checkbox: false, mnemonic: [] }, + fiatOnramp: { thirdPartyAcknowledged: false }, + fatalError: {}, + importAccounts: { + accounts: [], + showAccountsSelectionModal: false, + accountsSelectionPageNumber: 0, + step: 'idle', + }, + network: { + ticker: 'ROSE', + chainContext: 'b11b369e0da5bb230b220127f5e7b242d385ef8c6f54906243f30af63c815535', + selectedNetwork: 'mainnet', + epoch: 18372, + minimumStakingAmount: 100, + }, + paraTimes: { + balance: '', + isLoading: false, + transactionForm: { + amount: '', + confirmTransfer: false, + confirmTransferToValidator: false, + confirmTransferToForeignAccount: false, + defaultFeeAmount: '', + ethPrivateKey: '', + feeAmount: '', + feeGas: '', + paraTime: undefined, + recipient: '', + type: undefined, + }, + transactionFormStep: 'transferType', + }, + staking: { + debondingDelegations: null, + delegations: null, + updateDelegationsError: undefined, + validators: null, + updateValidatorsError: undefined, + selectedValidatorDetails: null, + selectedValidator: null, + loading: false, + }, + theme: { selected: 'dark' }, + transaction: { success: false, active: false }, + wallet: { + wallets: { + oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk: { + address: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', + balance: { + address: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', + allowances: [], + available: '0', + debonding: '0', + delegations: '0', + total: '0', + validator: { + escrow: '0', + escrow_debonding: '0', + }, + }, + privateKey: + '5f48e5a6fb243f5abc13aac7c56449afbc93be90ae38f10a0465bc82db954f17e75624c8d2cd9f062ce0331373a3be50ef0eccc5d257b4e2dea83a05506c7132', + publicKey: 'e75624c8d2cd9f062ce0331373a3be50ef0eccc5d257b4e2dea83a05506c7132', + type: 'private_key', + }, + }, + isOpen: true, + selectedWallet: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', + }, + persist: { + hasPersistedProfiles: true, + isPersistenceUnsupported: false, + loading: false, + stringifiedEncryptionKey: JSON.stringify({ + // Varies + key: { $Uint8Array$: 'tZVWIC8qNX4pBAFHUBeDTHppyH1Z4uwqRilH27kx+Us=' }, + salt: { $Uint8Array$: 'dQSGvwmyAqxs/vECZ2eIAkphq0pNKG+w69jNz/lIpKI=' }, + }), + enteredWrongPassword: false, + }, +} diff --git a/src/app/pages/E2EPage/index.tsx b/src/app/pages/E2EPage/index.tsx index 30fd5b1477..88a6c5b3bc 100644 --- a/src/app/pages/E2EPage/index.tsx +++ b/src/app/pages/E2EPage/index.tsx @@ -9,7 +9,7 @@ import { useNavigate } from 'react-router-dom' import * as monitor from 'vendors/monitor' import * as oasisscan from 'vendors/oasisscan' import * as oasis from '@oasisprotocol/client' -import { useDispatch } from 'react-redux' +import { useDispatch, useStore } from 'react-redux' import { walletActions } from '../../state/wallet' import { AlertBox, AlertBoxStatus } from '../../components/AlertBox' import { Info } from 'grommet-icons/es6/icons/Info' @@ -18,7 +18,7 @@ import { Text } from 'grommet/es6/components/Text' export function E2EPage() { return (
- +

@@ -33,20 +33,24 @@ interface e2eWindow extends Window { monitor: any oasisscan: any oasis: any + store: any } declare const window: e2eWindow -function TestVendors() { +function ExposeInternals() { + const store = useStore() useEffect(() => { window.monitor = monitor window.oasisscan = oasisscan window.oasis = oasis + window.store = store return () => { window.monitor = undefined window.oasisscan = undefined window.oasis = undefined + window.store = undefined } - }, []) + }, [store]) return <> } From b8f29925fc3138e3a7b725f8863e645d971c84a2 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Fri, 20 Oct 2023 00:06:34 +0200 Subject: [PATCH 2/4] Try to check types of persisted state fixture --- .../tests/migrating-persisted-state.spec.ts | 5 +++-- playwright/utils/test-inputs.ts | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/playwright/tests/migrating-persisted-state.spec.ts b/playwright/tests/migrating-persisted-state.spec.ts index f586967484..d117cdd3ec 100644 --- a/playwright/tests/migrating-persisted-state.spec.ts +++ b/playwright/tests/migrating-persisted-state.spec.ts @@ -4,6 +4,7 @@ import { warnSlowApi } from '../utils/warnSlowApi' import { expectNoFatal } from '../utils/expectNoFatal' import { addPersistedStorage, clearPersistedStorage } from '../utils/storage' import { password, privateKeyUnlockedState } from '../utils/test-inputs' +import { RootState } from '../../src/types/RootState' test.beforeEach(async ({ context, page }) => { await warnSlowApi(context) @@ -26,7 +27,7 @@ test.describe('Migrating persisted state', () => { await tab2.goto('/e2e') const decryptedStateV1 = await tab2.evaluate(() => { const store: any = window['store'] - return store.getState() + return store.getState() as RootState }) expect(decryptedStateV1).toEqual({ ...privateKeyUnlockedState, @@ -34,6 +35,6 @@ test.describe('Migrating persisted state', () => { ...privateKeyUnlockedState.persist, stringifiedEncryptionKey: expect.any(String), }, - }) + } satisfies RootState) }) }) diff --git a/playwright/utils/test-inputs.ts b/playwright/utils/test-inputs.ts index 799cd70b08..d90a240d03 100644 --- a/playwright/utils/test-inputs.ts +++ b/playwright/utils/test-inputs.ts @@ -1,3 +1,8 @@ +import type { ImportAccountsStep } from '../../src/app/state/importaccounts/types' +import type { TransactionFormSteps } from '../../src/app/state/paratimes/types' +import type { WalletType } from '../../src/app/state/wallet/types' +import type { RootState } from '../../src/types/RootState' + export const mnemonicAddress0 = 'oasis1qqca0gplrfn63ljg9c833te7em36lkz0cv8djffh' export const mnemonicAddress0Pretty = 'oasis1 qqca 0gpl rfn6 3ljg 9c83 3te7 em36 lkz0 cv8d jffh' export const mnemonic = 'planet believe session regular rib kiss police deposit prison hundred apart tongue' @@ -18,7 +23,11 @@ export const privateKey2 = ` export const password = 'Abcd1234&' export const wrongPassword = 'wrongPassword1&' -export const privateKeyPersistedState = JSON.stringify({ +function typedStringify(obj: T): string & { stringifiedType: T } { + return JSON.stringify(obj) as any +} + +export const privateKeyPersistedState = typedStringify({ secretbox: { $Uint8Array$: 'lKwFkSoMsqI/hMJe5hhDh0lnRAUxdhgWw9TpnBg1LcpUkilXDYPZFLigkGxdTKgJG57OI1cBtsISb6mEtrDcIgAovjRDa+N3DaGooZnjdDJcJJXIJWaPRKc42afPlqz+Akb5m18lKsmS06g69om63xY4Hyi6ebBNik5RZ5unfMKVsL2+jDop22mmFKLfuPjMeIiuPo50SXWOiU/qsRKwp0fhpRf6hbQ2zSNLtVIzfDtCLyKbal1ElEQym116gtC67SeP1wlRZSWuoRPWuljC4h4WWndHgwxgIFoc+GrcqdLJ2iBv10CG1EsYmC+jqj4Eeq6b2zZUIQRq6Pl7WRKo+SoazyVKqoLPsXSJ1xfayrs0VvqFOeVpP1p26hrMb0RwAt9bxc6WxF6Os8AjVme7ONTaimYxtAcwC1D0/KJ406duhNoymO+E9OGmBwKn+I4BYglTH0Gvn/qQDwjFcOQRdEXYTljDpfI2UBZqFARmM8kH0Yvho1M7KEY+uAvZt4ijOkY/qT/XCUTFpIsZsERT3P6GWDagGsl5GEDZm9MJS+6VLrK8OIje90Z+2vgTxAY4bawLU/b5lQsMRQldC4gukK0UIisXLyRgqKeVEy3Wr2sx+fYFSOaQycReMS1wqJpsYSMzZNMVCO9G8ef1ZzYXF9570fpwRzJhC0xI7NLcMOgUCTq4VoNenIBAW50l7RLXVhnMKodFYBgcjjoMy7j7kUk2SxiF83CIEn8156wSL2mH4loaSHRHaNx6mRxmEldrSFcuCqhHeEw12b5KeW9lJA9TpYNHJk5Y0vDAsi7Y7AZosBVn7x4sKBhslSbUdM8NLEf9rAcmBdwEYnTiJoSfPqd6AcE8cgcoiAgEKxyYOFS+cVQj9RofMXdnrG2W7Mp93KRVxLcZN805AnqwCJu15GosFhXhRTVLu8aaCOJ9T+N6gXVUVJpR4l4vVhFLuXHn4p5I7lzN1HYrS9WyWFzWqGGPCGism34eCxOohsQ8dnazE/xWibOYamu44f7I+o1yW5F/MmCBOzro7fher1kfv0V4RBQZyNUlQzOSA3zPc+JTYhSW0KQyaPIJTYKjVXEvnPUuPjirwlQ63RjFTQAWCuIjAeHQT2YjjqP7X5yWKMNIB78tbmCwpmnvZx2ysSrpNS/YXlaz1QRFBVOz0hiMKE1k9ihyOnlo+lmh6vQmzP85WgFqFKyzye6iWElTy2M=', @@ -48,7 +57,7 @@ export const privateKeyUnlockedState = { accounts: [], showAccountsSelectionModal: false, accountsSelectionPageNumber: 0, - step: 'idle', + step: 'idle' satisfies `${ImportAccountsStep}` as ImportAccountsStep, }, network: { ticker: 'ROSE', @@ -73,7 +82,7 @@ export const privateKeyUnlockedState = { recipient: '', type: undefined, }, - transactionFormStep: 'transferType', + transactionFormStep: 'transferType' satisfies `${TransactionFormSteps}` as TransactionFormSteps, }, staking: { debondingDelegations: null, @@ -106,7 +115,7 @@ export const privateKeyUnlockedState = { privateKey: '5f48e5a6fb243f5abc13aac7c56449afbc93be90ae38f10a0465bc82db954f17e75624c8d2cd9f062ce0331373a3be50ef0eccc5d257b4e2dea83a05506c7132', publicKey: 'e75624c8d2cd9f062ce0331373a3be50ef0eccc5d257b4e2dea83a05506c7132', - type: 'private_key', + type: 'private_key' satisfies `${WalletType}` as WalletType, }, }, isOpen: true, @@ -116,11 +125,12 @@ export const privateKeyUnlockedState = { hasPersistedProfiles: true, isPersistenceUnsupported: false, loading: false, - stringifiedEncryptionKey: JSON.stringify({ + stringifiedEncryptionKey: typedStringify({ // Varies key: { $Uint8Array$: 'tZVWIC8qNX4pBAFHUBeDTHppyH1Z4uwqRilH27kx+Us=' }, salt: { $Uint8Array$: 'dQSGvwmyAqxs/vECZ2eIAkphq0pNKG+w69jNz/lIpKI=' }, }), enteredWrongPassword: false, }, -} + // TODO: this doesn't check types?! +} satisfies RootState From 184252f7127f316e8f5cdb6bc78b6b0ec6ac11bc Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Wed, 15 Nov 2023 05:12:11 +0100 Subject: [PATCH 3/4] Move test-inputs.ts into src/ to check types of fixtures --- playwright/tests/extension.spec.ts | 2 +- playwright/tests/fiat.spec.ts | 2 +- playwright/tests/migrating-persisted-state.spec.ts | 2 +- playwright/tests/paraTimes.spec.ts | 2 +- playwright/tests/persist.spec.ts | 2 +- .../tests/preventSavingInputsToDisk/chromium.spec.ts | 2 +- .../tests/preventSavingInputsToDisk/firefox.spec.ts | 2 +- playwright/tests/refreshing-balance.spec.ts | 2 +- playwright/tests/syncTabs.spec.ts | 2 +- playwright/tests/toolbar.spec.ts | 8 +++++++- playwright/tests/validators.spec.ts | 2 +- playwright/utils/fillPrivateKey.ts | 2 +- playwright/utils/storage.ts | 2 +- .../utils => src/utils/__fixtures__}/test-inputs.ts | 9 ++++----- src/utils/{ => __tests__}/webextension.test.ts | 2 +- 15 files changed, 24 insertions(+), 19 deletions(-) rename {playwright/utils => src/utils/__fixtures__}/test-inputs.ts (94%) rename src/utils/{ => __tests__}/webextension.test.ts (94%) diff --git a/playwright/tests/extension.spec.ts b/playwright/tests/extension.spec.ts index 17937e1f26..e315bf3e57 100644 --- a/playwright/tests/extension.spec.ts +++ b/playwright/tests/extension.spec.ts @@ -4,7 +4,7 @@ import { warnSlowApi } from '../utils/warnSlowApi' import { mockApi } from '../utils/mockApi' import { expectNoErrorsInConsole } from '../utils/expectNoErrorsInConsole' import { fillPrivateKeyWithoutPassword } from '../utils/fillPrivateKey' -import { privateKey, privateKeyAddress } from '../utils/test-inputs' +import { privateKey, privateKeyAddress } from '../../src/utils/__fixtures__/test-inputs' // Test dev build by default, but also allow testing production const extensionPath = path.join(__dirname, '..', process.env.EXTENSION_PATH ?? '../build-dev/') diff --git a/playwright/tests/fiat.spec.ts b/playwright/tests/fiat.spec.ts index a5bd5d7984..2fbd8e7c4c 100644 --- a/playwright/tests/fiat.spec.ts +++ b/playwright/tests/fiat.spec.ts @@ -1,5 +1,5 @@ import { test, expect, Page } from '@playwright/test' -import { privateKey, privateKeyAddress } from '../utils/test-inputs' +import { privateKey, privateKeyAddress } from '../../src/utils/__fixtures__/test-inputs' import { fillPrivateKeyWithoutPassword } from '../utils/fillPrivateKey' import { warnSlowApi } from '../utils/warnSlowApi' import { mockApi } from '../utils/mockApi' diff --git a/playwright/tests/migrating-persisted-state.spec.ts b/playwright/tests/migrating-persisted-state.spec.ts index d117cdd3ec..6ab6fc8bdd 100644 --- a/playwright/tests/migrating-persisted-state.spec.ts +++ b/playwright/tests/migrating-persisted-state.spec.ts @@ -3,7 +3,7 @@ import { mockApi } from '../utils/mockApi' import { warnSlowApi } from '../utils/warnSlowApi' import { expectNoFatal } from '../utils/expectNoFatal' import { addPersistedStorage, clearPersistedStorage } from '../utils/storage' -import { password, privateKeyUnlockedState } from '../utils/test-inputs' +import { password, privateKeyUnlockedState } from '../../src/utils/__fixtures__/test-inputs' import { RootState } from '../../src/types/RootState' test.beforeEach(async ({ context, page }) => { diff --git a/playwright/tests/paraTimes.spec.ts b/playwright/tests/paraTimes.spec.ts index b97910ee31..bd79932448 100644 --- a/playwright/tests/paraTimes.spec.ts +++ b/playwright/tests/paraTimes.spec.ts @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test' -import { privateKey, privateKeyAddress } from '../utils/test-inputs' +import { privateKey, privateKeyAddress } from '../../src/utils/__fixtures__/test-inputs' import { fillPrivateKeyWithoutPassword } from '../utils/fillPrivateKey' import { warnSlowApi } from '../utils/warnSlowApi' import { mockApi } from '../utils/mockApi' diff --git a/playwright/tests/persist.spec.ts b/playwright/tests/persist.spec.ts index 669acb1ee5..6dfa11f322 100644 --- a/playwright/tests/persist.spec.ts +++ b/playwright/tests/persist.spec.ts @@ -12,7 +12,7 @@ import { privateKey2, password, wrongPassword, -} from '../utils/test-inputs' +} from '../../src/utils/__fixtures__/test-inputs' import { fillPrivateKeyWithoutPassword, fillPrivateKeyAndPassword } from '../utils/fillPrivateKey' test.beforeEach(async ({ context, page }) => { diff --git a/playwright/tests/preventSavingInputsToDisk/chromium.spec.ts b/playwright/tests/preventSavingInputsToDisk/chromium.spec.ts index d429564c70..3cb2d338da 100644 --- a/playwright/tests/preventSavingInputsToDisk/chromium.spec.ts +++ b/playwright/tests/preventSavingInputsToDisk/chromium.spec.ts @@ -1,5 +1,5 @@ import { expect, chromium } from '@playwright/test' -import { mnemonic, password, privateKey } from '../../utils/test-inputs' +import { mnemonic, password, privateKey } from '../../../src/utils/__fixtures__/test-inputs' import { warnSlowApi } from '../../utils/warnSlowApi' import { mockApi } from '../../utils/mockApi' import { diff --git a/playwright/tests/preventSavingInputsToDisk/firefox.spec.ts b/playwright/tests/preventSavingInputsToDisk/firefox.spec.ts index ee194a4e61..aae5f12fdc 100644 --- a/playwright/tests/preventSavingInputsToDisk/firefox.spec.ts +++ b/playwright/tests/preventSavingInputsToDisk/firefox.spec.ts @@ -1,5 +1,5 @@ import { expect, firefox } from '@playwright/test' -import { mnemonic, password, privateKey } from '../../utils/test-inputs' +import { mnemonic, password, privateKey } from '../../../src/utils/__fixtures__/test-inputs' import { warnSlowApi } from '../../utils/warnSlowApi' import { mockApi } from '../../utils/mockApi' import { diff --git a/playwright/tests/refreshing-balance.spec.ts b/playwright/tests/refreshing-balance.spec.ts index e4de4886ce..01c16fa138 100644 --- a/playwright/tests/refreshing-balance.spec.ts +++ b/playwright/tests/refreshing-balance.spec.ts @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test' -import { privateKey, privateKeyAddress } from '../utils/test-inputs' +import { privateKey, privateKeyAddress } from '../../src/utils/__fixtures__/test-inputs' import { fillPrivateKeyWithoutPassword } from '../utils/fillPrivateKey' import { warnSlowApi } from '../utils/warnSlowApi' import { mockApi } from '../utils/mockApi' diff --git a/playwright/tests/syncTabs.spec.ts b/playwright/tests/syncTabs.spec.ts index 5ec646177d..9468e28600 100644 --- a/playwright/tests/syncTabs.spec.ts +++ b/playwright/tests/syncTabs.spec.ts @@ -9,7 +9,7 @@ import { privateKey2, privateKey2AddressPretty, mnemonic, -} from '../utils/test-inputs' +} from '../../src/utils/__fixtures__/test-inputs' import { addPersistedStorage, clearPersistedStorage } from '../utils/storage' import { fillPrivateKeyWithoutPassword, fillPrivateKeyAndPassword } from '../utils/fillPrivateKey' import type { AccountsRow } from '../../src/vendors/oasisscan/index' diff --git a/playwright/tests/toolbar.spec.ts b/playwright/tests/toolbar.spec.ts index 8826289c40..eb7aa0c0f0 100644 --- a/playwright/tests/toolbar.spec.ts +++ b/playwright/tests/toolbar.spec.ts @@ -1,5 +1,11 @@ import { test, expect, Page } from '@playwright/test' -import { mnemonic, mnemonicAddress0, password, privateKey, privateKeyAddress } from '../utils/test-inputs' +import { + mnemonic, + mnemonicAddress0, + password, + privateKey, + privateKeyAddress, +} from '../../src/utils/__fixtures__/test-inputs' import { fillPrivateKeyAndPassword } from '../utils/fillPrivateKey' import { warnSlowApi } from '../utils/warnSlowApi' import { mockApi } from '../utils/mockApi' diff --git a/playwright/tests/validators.spec.ts b/playwright/tests/validators.spec.ts index 6916d603d7..40c892ffd5 100644 --- a/playwright/tests/validators.spec.ts +++ b/playwright/tests/validators.spec.ts @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test' -import { privateKey, privateKeyAddress } from '../utils/test-inputs' +import { privateKey, privateKeyAddress } from '../../src/utils/__fixtures__/test-inputs' import { fillPrivateKeyWithoutPassword } from '../utils/fillPrivateKey' import { warnSlowApi } from '../utils/warnSlowApi' import { mockApi } from '../utils/mockApi' diff --git a/playwright/utils/fillPrivateKey.ts b/playwright/utils/fillPrivateKey.ts index 54e1534e91..3f647dba45 100644 --- a/playwright/utils/fillPrivateKey.ts +++ b/playwright/utils/fillPrivateKey.ts @@ -1,5 +1,5 @@ import { expect, test, Page } from '@playwright/test' -import { password, privateKey, privateKeyAddress } from './test-inputs' +import { password, privateKey, privateKeyAddress } from '../../src/utils/__fixtures__/test-inputs' export async function fillPrivateKeyWithoutPassword( page: Page, diff --git a/playwright/utils/storage.ts b/playwright/utils/storage.ts index b22d09d844..1f88559772 100644 --- a/playwright/utils/storage.ts +++ b/playwright/utils/storage.ts @@ -1,5 +1,5 @@ import type { Page } from '@playwright/test' -import { privateKeyPersistedState } from './test-inputs' +import { privateKeyPersistedState } from '../../src/utils/__fixtures__/test-inputs' export async function clearPersistedStorage(page: Page) { // Move to the right domain, but don't needlessly load HTML and JS. diff --git a/playwright/utils/test-inputs.ts b/src/utils/__fixtures__/test-inputs.ts similarity index 94% rename from playwright/utils/test-inputs.ts rename to src/utils/__fixtures__/test-inputs.ts index d90a240d03..eb4547699b 100644 --- a/playwright/utils/test-inputs.ts +++ b/src/utils/__fixtures__/test-inputs.ts @@ -1,7 +1,7 @@ -import type { ImportAccountsStep } from '../../src/app/state/importaccounts/types' -import type { TransactionFormSteps } from '../../src/app/state/paratimes/types' -import type { WalletType } from '../../src/app/state/wallet/types' -import type { RootState } from '../../src/types/RootState' +import type { ImportAccountsStep } from 'app/state/importaccounts/types' +import type { TransactionFormSteps } from 'app/state/paratimes/types' +import type { WalletType } from 'app/state/wallet/types' +import type { RootState } from 'types' export const mnemonicAddress0 = 'oasis1qqca0gplrfn63ljg9c833te7em36lkz0cv8djffh' export const mnemonicAddress0Pretty = 'oasis1 qqca 0gpl rfn6 3ljg 9c83 3te7 em36 lkz0 cv8d jffh' @@ -132,5 +132,4 @@ export const privateKeyUnlockedState = { }), enteredWrongPassword: false, }, - // TODO: this doesn't check types?! } satisfies RootState diff --git a/src/utils/webextension.test.ts b/src/utils/__tests__/webextension.test.ts similarity index 94% rename from src/utils/webextension.test.ts rename to src/utils/__tests__/webextension.test.ts index ea5e326725..e51e66b30c 100644 --- a/src/utils/webextension.test.ts +++ b/src/utils/__tests__/webextension.test.ts @@ -1,5 +1,5 @@ import browser from 'webextension-polyfill' -import { openLedgerAccessPopup } from './webextension' +import { openLedgerAccessPopup } from '../webextension' jest.mock('webextension-polyfill', () => ({ extension: { From abe01239ff358026b2c6df2c5160cb69c9a5afe8 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Wed, 15 Nov 2023 05:12:19 +0100 Subject: [PATCH 4/4] Add types for removed and accidental fields present in persisted states We "removed" some fields throughout time, but didn't add state migration steps. This should be completely fine, types just didn't match test fixtures. --- src/app/state/wallet/types.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/state/wallet/types.ts b/src/app/state/wallet/types.ts index de92dcce7f..7010feb7b1 100644 --- a/src/app/state/wallet/types.ts +++ b/src/app/state/wallet/types.ts @@ -18,7 +18,14 @@ export interface Wallet { path?: number[] pathDisplay?: string privateKey?: string - balance: BalanceDetails + balance: BalanceDetails & { + /** @deprecated This property is not reliably present */ + address?: string + /** @deprecated This property is not reliably present */ + allowances?: any[] + /** @deprecated This property is not reliably present */ + validator?: any + } name?: string } @@ -37,6 +44,8 @@ export interface OpenSelectedAccountsPayload { /* --- STATE --- */ export interface WalletState { + /** @deprecated This property was removed after 76fbf9a */ + isOpen?: boolean selectedWallet?: string wallets: { [address: string]: Wallet } }