-
Notifications
You must be signed in to change notification settings - Fork 11
test: add test #237
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
base: main
Are you sure you want to change the base?
test: add test #237
Changes from 14 commits
39ddfdc
5fc4b91
89b8803
a0d13e5
f86c1d9
b686822
a0aff73
4a28559
37c5e08
c1c1941
2a0046f
8f1675a
f012539
c79d402
2509060
75d4b24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Mock E2E Phishing Page</title> | ||
| </head> | ||
| <body> | ||
| <label for="url">link:</label> | ||
| <input type="text" id="url" placeholder="https://demo-nexus.vercel.app/" /> | ||
| <button onclick="loadPage()">show</button> | ||
| <br /><br /> | ||
| <iframe id="page" style="width: 100%; height: 80vh"></iframe> | ||
| <script> | ||
| function loadPage() { | ||
| document.getElementById('page').src = document.getElementById('url').value; | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>Mock E2E Phishing Page</title> | ||
| </head> | ||
| <body> | ||
| <div>Hello</div> | ||
| <iframe src="https://demo-nexus.vercel.app/" width="900" height="900"></iframe> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { DefaultTestEnv } from '../helpers'; | ||
|
|
||
| DefaultTestEnv.setupTest({ initWalletWithDefaults: true }); | ||
|
|
||
| describe('Show account details', function () { | ||
| it('should show nick name for account', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByText(testEnv.defaultE2eData.nickname).waitFor(); | ||
| }); | ||
|
|
||
| it('should show disconnected for the account', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByText('Disconnected').waitFor(); | ||
| }); | ||
| it('should show whitelist sites for the account', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByRole('button', { name: 'Whitelist Sites' }).click(); | ||
| await page.getByText('No whitelist sites found.').waitFor(); | ||
| }); | ||
| it('should show networks list for the account', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByRole('button', { name: 'Network' }).click(); | ||
| await page.getByText('Mainnet').waitFor(); | ||
| await page.getByText('Testnet').waitFor(); | ||
| }); | ||
|
|
||
| it('should show feedback for the account', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByRole('link', { name: 'Feedback' }).click(); | ||
| await page.waitForTimeout(1000); | ||
| expect(testEnv.context.pages().some((page) => page.url().includes('ckb-js/nexus/issues'))).toBe(true); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { DefaultTestEnv } from '../helpers'; | ||
|
|
||
| DefaultTestEnv.setupTest({ initWalletWithDefaults: true }); | ||
|
|
||
| describe('add network', function () { | ||
| it('should work when the add name too long', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByRole('button', { name: 'Network' }).click(); | ||
| await page.getByRole('button', { name: 'Add Network' }).click(); | ||
|
|
||
| const tooLongName = | ||
| 'too too too too too long long long long long long long long long long long long long long long long long long long long long long long long'; | ||
| await page.getByLabel('Name').fill(tooLongName); | ||
| await page.getByLabel('URL').fill('https://testnet.ckbapp.dev/'); | ||
| await page.getByRole('button', { name: 'Add' }).click(); | ||
| await page.getByText(tooLongName).waitFor(); | ||
| }); | ||
|
|
||
| it('should work when the add name exist', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByRole('button', { name: 'Network' }).click(); | ||
| await page.getByRole('button', { name: 'Add Network' }).click(); | ||
|
|
||
| const existName = 'Testnet'; | ||
| await page.getByLabel('Name').fill(existName); | ||
| await page.getByLabel('URL').fill('https://testnet.ckbapp.dev/'); | ||
| await page.getByRole('button', { name: 'Add' }).click(); | ||
| await page.getByText(existName).allInnerTexts(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should get inner tests and asset it to contain two |
||
| }); | ||
|
|
||
| it('should work when the add url is not ckb rpc', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByRole('button', { name: 'Network' }).click(); | ||
| await page.getByRole('button', { name: 'Add Network' }).click(); | ||
|
|
||
| const randName = 'rand test name'; | ||
| await page.getByLabel('Name').fill(randName); | ||
| await page.getByLabel('URL').fill('https://www.baidu.com'); | ||
| await page.getByRole('button', { name: 'Add' }).click(); | ||
| await page.getByText(randName).allInnerTexts(); | ||
| }); | ||
|
|
||
| it('should work when the add url is ckb rpc', async () => { | ||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await page.getByRole('button', { name: 'Network' }).click(); | ||
| await page.getByRole('button', { name: 'Add Network' }).click(); | ||
|
|
||
| const randName = 'rand name'; | ||
| await page.getByLabel('Name').fill(randName); | ||
| await page.getByLabel('URL').fill('https://testnet.ckbapp.dev/'); | ||
| await page.getByRole('button', { name: 'Add' }).click(); | ||
| await page.getByText(randName).allInnerTexts(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { DefaultTestEnv } from '../helpers'; | ||
| import { asyncSleep } from '@nexus-wallet/utils'; | ||
|
|
||
| DefaultTestEnv.setupTest({ initWalletWithDefaults: true }); | ||
|
|
||
| describe('add whitelist site', function () { | ||
| it('should request failed before add whitelist', async () => { | ||
| try { | ||
| await ckb.request({ method: 'wallet_fullOwnership_getOffChainLocks' }); | ||
| } catch (error) { | ||
| expect(`${error}`).toMatch(/not in the whitelist/); | ||
| return; | ||
| } | ||
| expect('').toBe('failed'); | ||
| }); | ||
|
|
||
| it('should get networkChange that the url is not in whitelist', async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems this test case should be moved to "change-network.test.ts"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a duplicate test, I will remove it. |
||
| await page.evaluate(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the purpose of this patch watching current nexus network? maybe use |
||
| // @ts-ignore | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not need it anymore. |
||
| window.ckbNetworkName = ''; | ||
| window.ckb.on('networkChanged', (networkName: string) => { | ||
| // @ts-ignore | ||
| window.ckbNetworkName = networkName; | ||
| }); | ||
| }); | ||
| const extensionIdPage = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await extensionIdPage.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await extensionIdPage.getByRole('button', { name: 'Network' }).click(); | ||
| await extensionIdPage.getByText('Mainnet').click(); | ||
| let ckbNetworkName = await page.evaluate(() => { | ||
| // @ts-ignore | ||
| return window.ckbNetworkName; | ||
| }); | ||
| expect(ckbNetworkName).toBe('ckb'); | ||
| await extensionIdPage.getByText('Testnet').click(); | ||
| ckbNetworkName = await page.evaluate(() => { | ||
| // @ts-ignore | ||
| return window.ckbNetworkName; | ||
| }); | ||
| expect(ckbNetworkName).toBe('ckb_testnet'); | ||
| }); | ||
|
|
||
| /** | ||
| * TODO: impl localhost can be visited | ||
| */ | ||
| it.todo('should work that add localhost url'); | ||
| /** | ||
| * TODO: impl 192.168 can be visited | ||
| */ | ||
| it.todo('should work that add 192.168.. url'); | ||
|
|
||
| it('should work that add url is http', async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should wallet_enable work that add url prefix is http |
||
| const httpUrl = 'http://info.cern.ch'; | ||
| await page.goto(httpUrl); | ||
| const enableTask = ckb.request({ method: 'wallet_enable' }); | ||
|
|
||
| const notificationPage = await testEnv.getNotificationPage(); | ||
| await notificationPage.getByRole('button', { name: 'Connect' }).click(); | ||
|
|
||
| const res = await enableTask; | ||
| expect(res.nickname).toBe(testEnv.defaultE2eData.nickname); | ||
| }); | ||
|
|
||
| it('should work that add url is https', async () => { | ||
| const httpsUrl = 'https://github.com'; | ||
| await page.goto(httpsUrl); | ||
| const enableTask = ckb.request({ method: 'wallet_enable' }); | ||
|
|
||
| const notificationPage = await testEnv.getNotificationPage(); | ||
| await notificationPage.getByRole('button', { name: 'Connect' }).click(); | ||
|
|
||
| const res = await enableTask; | ||
| expect(res.nickname).toBe(testEnv.defaultE2eData.nickname); | ||
| }); | ||
|
|
||
| /** | ||
| * skip reason :TODO: check url is in the box | ||
| */ | ||
| it.skip('should work that add url is too long', async () => { | ||
| const tooLongUrl = 'https://mememmememememmemememmememememmemememmememememme.bit.cc/'; | ||
| await page.goto(tooLongUrl); | ||
| const enableTask = ckb.request({ method: 'wallet_enable' }); | ||
|
|
||
| const notificationPage = await testEnv.getNotificationPage(); | ||
| await notificationPage.getByRole('button', { name: 'Connect' }).click(); | ||
|
|
||
| const res = await enableTask; | ||
| expect(res.nickname).toBe(testEnv.defaultE2eData.nickname); | ||
| }); | ||
|
|
||
| it('should request work after add whitelist ', async () => { | ||
| const enableTask = ckb.request({ method: 'wallet_enable' }); | ||
|
|
||
| await asyncSleep(1000); | ||
| const notificationPage = await testEnv.getNotificationPage(); | ||
| await notificationPage.getByRole('button', { name: 'Connect' }).click(); | ||
|
|
||
| const res = await enableTask; | ||
| expect(res.nickname).toBe(testEnv.defaultE2eData.nickname); | ||
|
|
||
| await ckb.request({ method: 'wallet_fullOwnership_getOffChainLocks', params: {} }); | ||
| }); | ||
|
|
||
| it('should find url in whitelist after add whitelist', async () => { | ||
| const enableTask = ckb.request({ method: 'wallet_enable' }); | ||
|
|
||
| const notificationPage = await testEnv.getNotificationPage(); | ||
| await notificationPage.getByRole('button', { name: 'Connect' }).click(); | ||
|
|
||
| const res = await enableTask; | ||
| expect(res.nickname).toBe(testEnv.defaultE2eData.nickname); | ||
|
|
||
| const page = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await page.goto(`chrome-extension://${extensionId}/popup.html`); | ||
|
|
||
| await page.getByRole('button', { name: 'Whitelist Sites' }).click(); | ||
| // await page.getByRole('').fill(urlTransferDomainName(testEnv.defaultE2eData.localServerUrl)) | ||
| await page.getByText(urlTransferDomainName(testEnv.defaultE2eData.localServerUrl)); | ||
| }); | ||
| }); | ||
|
|
||
| export function urlTransferDomainName(url: string): string { | ||
| const match = url.match(/^https?:\/\/([^/]+)/); | ||
| return match ? match[1] : ''; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { DefaultTestEnv } from '../helpers'; | ||
|
|
||
| DefaultTestEnv.setupTest({ initWalletWithDefaults: true }); | ||
|
|
||
| describe('Change network', function () { | ||
| it('should get networkChanged when network change', async () => { | ||
| await page.evaluate(() => { | ||
| // @ts-ignore | ||
| window.ckbNetworkName = ''; | ||
| window.ckb.on('networkChanged', (networkName: string) => { | ||
| // @ts-ignore | ||
| window.ckbNetworkName = networkName; | ||
| }); | ||
| }); | ||
| const extensionIdPage = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await extensionIdPage.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await extensionIdPage.getByRole('button', { name: 'Network' }).click(); | ||
| await extensionIdPage.getByText('Mainnet').click(); | ||
| let ckbNetworkName = await page.evaluate(() => { | ||
| // @ts-ignore | ||
| return window.ckbNetworkName; | ||
| }); | ||
| expect(ckbNetworkName).toBe('ckb'); | ||
| await extensionIdPage.getByText('Testnet').click(); | ||
| ckbNetworkName = await page.evaluate(() => { | ||
| // @ts-ignore | ||
| return window.ckbNetworkName; | ||
| }); | ||
| expect(ckbNetworkName).toBe('ckb_testnet'); | ||
| }); | ||
| it('should get ckb name that change network is user added', async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like a composed test case for "add network" and "change network", is it necessary? |
||
| const extensionIdPage = await testEnv.context.newPage(); | ||
| const extensionId = testEnv.extensionId; | ||
| await extensionIdPage.goto(`chrome-extension://${extensionId}/popup.html`); | ||
| await extensionIdPage.getByRole('button', { name: 'Network' }).click(); | ||
| await extensionIdPage.getByRole('button', { name: 'Add Network' }).click(); | ||
|
|
||
| const randName = 'user test net name'; | ||
| await extensionIdPage.getByLabel('Name').fill(randName); | ||
| await extensionIdPage.getByLabel('URL').fill('https://testnet.ckbapp.dev/'); | ||
| await extensionIdPage.getByRole('button', { name: 'Add' }).click(); | ||
| await extensionIdPage.getByText(randName).allInnerTexts(); | ||
|
|
||
| await extensionIdPage.getByRole('button', { name: 'Add Network' }).click(); | ||
| const notCkbName = 'user add not ckb test net name'; | ||
| await extensionIdPage.getByLabel('Name').fill(notCkbName); | ||
| await extensionIdPage.getByLabel('URL').fill('https://github.com'); | ||
| await extensionIdPage.getByRole('button', { name: 'Add' }).click(); | ||
| await extensionIdPage.getByText(notCkbName).allInnerTexts(); | ||
| await page.evaluate(() => { | ||
| // @ts-ignore | ||
| window.ckbNetworkName = ''; | ||
| window.ckb.on('networkChanged', (networkName: string) => { | ||
| // @ts-ignore | ||
| window.ckbNetworkName = networkName; | ||
| }); | ||
| }); | ||
| await extensionIdPage.getByText(randName).click(); | ||
| let ckbNetworkName = await page.evaluate(() => { | ||
| // @ts-ignore | ||
| return window.ckbNetworkName; | ||
| }); | ||
| expect(ckbNetworkName).toBe(randName); | ||
|
|
||
| await extensionIdPage.getByText(notCkbName).click(); | ||
|
|
||
| ckbNetworkName = await page.evaluate(() => { | ||
| // @ts-ignore | ||
| return window.ckbNetworkName; | ||
| }); | ||
|
|
||
| expect(ckbNetworkName).toBe(notCkbName); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not use word
accountas a term on UTXO wallet.