Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E test migrating slightly older V1 state to current RootState #1755

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1755.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
E2E test migrating older V1 state to current RootState
2 changes: 1 addition & 1 deletion playwright/tests/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/fiat.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
40 changes: 40 additions & 0 deletions playwright/tests/migrating-persisted-state.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
2 changes: 1 addition & 1 deletion playwright/tests/paraTimes.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/persist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/preventSavingInputsToDisk/firefox.spec.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/refreshing-balance.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/syncTabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 7 additions & 1 deletion playwright/tests/toolbar.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/validators.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion playwright/utils/fillPrivateKey.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion playwright/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
28 changes: 0 additions & 28 deletions playwright/utils/test-inputs.ts

This file was deleted.

12 changes: 8 additions & 4 deletions src/app/pages/E2EPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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'

Check warning on line 12 in src/app/pages/E2EPage/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/pages/E2EPage/index.tsx#L12

Added line #L12 was not covered by tests
import { walletActions } from '../../state/wallet'
import { AlertBox, AlertBoxStatus } from '../../components/AlertBox'
import { Info } from 'grommet-icons/es6/icons/Info'
Expand All @@ -18,7 +18,7 @@
export function E2EPage() {
return (
<div>
<TestVendors></TestVendors>
<ExposeInternals></ExposeInternals>
<br />
<TestUnsafeInputs></TestUnsafeInputs>
<br />
Expand All @@ -33,20 +33,24 @@
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 <></>
}

Expand Down
11 changes: 10 additions & 1 deletion src/app/state/wallet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 }
}
135 changes: 135 additions & 0 deletions src/utils/__fixtures__/test-inputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
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'
export const mnemonic = 'planet believe session regular rib kiss police deposit prison hundred apart tongue'

Check warning on line 8 in src/utils/__fixtures__/test-inputs.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/__fixtures__/test-inputs.ts#L6-L8

Added lines #L6 - L8 were not covered by tests

export const privateKeyAddress = 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk'
export const privateKeyAddressPretty = 'oasis1 qz0k 5q8v jqvu 4s4n wxyj 406y lnfl kc4v rcjg huwk'
export const privateKey =

Check warning on line 12 in src/utils/__fixtures__/test-inputs.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/__fixtures__/test-inputs.ts#L10-L12

Added lines #L10 - L12 were not covered by tests
'X0jlpvskP1q8E6rHxWRJr7yTvpCuOPEKBGW8gtuVTxfnViTI0s2fBizgMxNzo75Q7w7MxdJXtOLeqDoFUGxxMg=='

export const privateKey2Address = 'oasis1qzu5y29xzw5vm0f9glcpg9ckx7lulpg69qjp4hc6'
export const privateKey2AddressPretty = 'oasis1 qzu5 y29x zw5v m0f9 glcp g9ck x7lu lpg6 9qjp 4hc6'
export const privateKey2 = `

Check warning on line 17 in src/utils/__fixtures__/test-inputs.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/__fixtures__/test-inputs.ts#L15-L17

Added lines #L15 - L17 were not covered by tests
-----BEGIN ED25519 PRIVATE KEY-----
ZqtrV0QtEY/JemfTPbOl9hgk3UxHXfZO42G4sG+XKHThZTM+GvRiqsAgc7magKNN
4MEkyO0pi7lJeunILQKiZA==
-----END ED25519 PRIVATE KEY-----`

export const password = 'Abcd1234&'
export const wrongPassword = 'wrongPassword1&'

Check warning on line 24 in src/utils/__fixtures__/test-inputs.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/__fixtures__/test-inputs.ts#L23-L24

Added lines #L23 - L24 were not covered by tests

function typedStringify<T>(obj: T): string & { stringifiedType: T } {
return JSON.stringify(obj) as any

Check warning on line 27 in src/utils/__fixtures__/test-inputs.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/__fixtures__/test-inputs.ts#L26-L27

Added lines #L26 - L27 were not covered by tests
}

export const privateKeyPersistedState = typedStringify({

Check warning on line 30 in src/utils/__fixtures__/test-inputs.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/__fixtures__/test-inputs.ts#L30

Added line #L30 was not covered by tests
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=',
},
nonce: { $Uint8Array$: 'uTf/3wnfC1PnWEoJrmULoMg0qffau4MM' },
salt: { $Uint8Array$: 'dQSGvwmyAqxs/vECZ2eIAkphq0pNKG+w69jNz/lIpKI=' },
})

export const privateKeyUnlockedState = {

Check warning on line 39 in src/utils/__fixtures__/test-inputs.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/__fixtures__/test-inputs.ts#L39

Added line #L39 was not covered by tests
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' satisfies `${ImportAccountsStep}` as ImportAccountsStep,
},
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' satisfies `${TransactionFormSteps}` as TransactionFormSteps,
},
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' satisfies `${WalletType}` as WalletType,
},
},
isOpen: true,
selectedWallet: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk',
},
persist: {
hasPersistedProfiles: true,
isPersistenceUnsupported: false,
loading: false,
stringifiedEncryptionKey: typedStringify({
// Varies
key: { $Uint8Array$: 'tZVWIC8qNX4pBAFHUBeDTHppyH1Z4uwqRilH27kx+Us=' },
salt: { $Uint8Array$: 'dQSGvwmyAqxs/vECZ2eIAkphq0pNKG+w69jNz/lIpKI=' },
}),
enteredWrongPassword: false,
},
} satisfies RootState
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import browser from 'webextension-polyfill'
import { openLedgerAccessPopup } from './webextension'
import { openLedgerAccessPopup } from '../webextension'

jest.mock('webextension-polyfill', () => ({
extension: {
Expand Down
Loading