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/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 new file mode 100644 index 0000000000..6ab6fc8bdd --- /dev/null +++ b/playwright/tests/migrating-persisted-state.spec.ts @@ -0,0 +1,40 @@ +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 '../../src/utils/__fixtures__/test-inputs' +import { RootState } from '../../src/types/RootState' + +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() as RootState + }) + expect(decryptedStateV1).toEqual({ + ...privateKeyUnlockedState, + persist: { + ...privateKeyUnlockedState.persist, + stringifiedEncryptionKey: expect.any(String), + }, + } satisfies RootState) + }) +}) 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/playwright/utils/test-inputs.ts deleted file mode 100644 index 5cc334040b..0000000000 --- a/playwright/utils/test-inputs.ts +++ /dev/null @@ -1,28 +0,0 @@ -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' - -export const privateKeyAddress = 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk' -export const privateKeyAddressPretty = 'oasis1 qz0k 5q8v jqvu 4s4n wxyj 406y lnfl kc4v rcjg huwk' -export const privateKey = - 'X0jlpvskP1q8E6rHxWRJr7yTvpCuOPEKBGW8gtuVTxfnViTI0s2fBizgMxNzo75Q7w7MxdJXtOLeqDoFUGxxMg==' - -export const privateKey2Address = 'oasis1qzu5y29xzw5vm0f9glcpg9ckx7lulpg69qjp4hc6' -export const privateKey2AddressPretty = 'oasis1 qzu5 y29x zw5v m0f9 glcp g9ck x7lu lpg6 9qjp 4hc6' -export const privateKey2 = ` - -----BEGIN ED25519 PRIVATE KEY----- - ZqtrV0QtEY/JemfTPbOl9hgk3UxHXfZO42G4sG+XKHThZTM+GvRiqsAgc7magKNN - 4MEkyO0pi7lJeunILQKiZA== - -----END ED25519 PRIVATE KEY-----` - -export const password = 'Abcd1234&' -export const wrongPassword = 'wrongPassword1&' - -export const privateKeyPersistedState = JSON.stringify({ - secretbox: { - $Uint8Array$: - 'lKwFkSoMsqI/hMJe5hhDh0lnRAUxdhgWw9TpnBg1LcpUkilXDYPZFLigkGxdTKgJG57OI1cBtsISb6mEtrDcIgAovjRDa+N3DaGooZnjdDJcJJ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mzP85WgFqFKyzye6iWElTy2M=', - }, - nonce: { $Uint8Array$: 'uTf/3wnfC1PnWEoJrmULoMg0qffau4MM' }, - salt: { $Uint8Array$: 'dQSGvwmyAqxs/vECZ2eIAkphq0pNKG+w69jNz/lIpKI=' }, -}) 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 (