Skip to content

Commit

Permalink
Add Playwright tests to eth key validation
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed May 7, 2024
1 parent ded5b41 commit df45cce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
38 changes: 37 additions & 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 '../../src/utils/__fixtures__/test-inputs'
import { privateKey, privateKeyAddress, ethAccount } from '../../src/utils/__fixtures__/test-inputs'
import { fillPrivateKeyWithoutPassword } from '../utils/fillPrivateKey'
import { warnSlowApi } from '../utils/warnSlowApi'
import { mockApi } from '../utils/mockApi'
Expand Down Expand Up @@ -33,4 +33,40 @@ test.describe('ParaTimes', () => {
await page.getByRole('button', { name: /Next/i }).click()
await expect(page.getByPlaceholder('0x...')).toHaveValue('')
})

test('should validate eth private key', async ({ page }) => {
const validKey = ethAccount.privateKey
const validKeyWithPrefix = `0x${validKey}`
const invalidKey = validKey.replace('c', 'g')
const invalidKeyWithPrefix = `0x${invalidKey}`

async function testPrivateKeyValidation(key, expected) {
await page.getByPlaceholder('Enter Ethereum-compatible private key').fill(key)
await page.getByRole('button', { name: 'Next' }).click()
await expect(page.getByText(expected)).toBeVisible()
}

await page.goto('/open-wallet/private-key')
await fillPrivateKeyWithoutPassword(page, {
privateKey: privateKey,
privateKeyAddress: privateKeyAddress,
persistenceCheckboxChecked: false,
persistenceCheckboxDisabled: false,
})
await page.getByTestId('nav-paratime').click()
await page.getByRole('button', { name: /Withdraw/i }).click()
await page.getByRole('button', { name: 'Select a ParaTime' }).click()
await expect(page.getByRole('listbox')).toBeVisible()
await page.getByRole('listbox').locator('button', { hasText: 'Sapphire' }).click()
await page.getByRole('button', { name: 'Next' }).click()
await page.getByPlaceholder(privateKeyAddress).fill(privateKeyAddress)
// valid eth private keys
await testPrivateKeyValidation(validKey, /enter the amount/)
await page.getByRole('button', { name: 'Back' }).click()
await testPrivateKeyValidation(validKeyWithPrefix, /enter the amount/)
await page.getByRole('button', { name: 'Back' }).click()
// invalid eth private keys
await testPrivateKeyValidation(invalidKey, /private key is invalid/)
await testPrivateKeyValidation(invalidKeyWithPrefix, /private key is invalid/)
})
})
11 changes: 8 additions & 3 deletions src/utils/__fixtures__/test-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ export const walletExtensionV0PersistedState = {
},
} satisfies WalletExtensionV0State

export const ethAccount = {
address: '0xbA1b346233E5bB5b44f5B4aC6bF224069f427b18',
privateKey: '6593a788d944bb3e25357df140fac5b0e6273f1500a3b37d6513bf9e9807afe2',
}

export const walletExtensionV0UnlockedState = {
account: {
address: 'oasis1qq30ejf9puuc6qnrazmy9dmn7f3gessveum5wnr6',
Expand All @@ -236,9 +241,9 @@ export const walletExtensionV0UnlockedState = {
},
},
evmAccounts: {
'0xbA1b346233E5bB5b44f5B4aC6bF224069f427b18': {
ethAddress: '0xbA1b346233E5bB5b44f5B4aC6bF224069f427b18',
ethPrivateKey: '6593a788d944bb3e25357df140fac5b0e6273f1500a3b37d6513bf9e9807afe2',
[ethAccount.address]: {
ethAddress: ethAccount.address,
ethPrivateKey: ethAccount.privateKey,
},
},
createWallet: { checkbox: false, mnemonic: [] },
Expand Down

0 comments on commit df45cce

Please sign in to comment.