-
Notifications
You must be signed in to change notification settings - Fork 11
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
test: add test #237
Open
gpBlockchain
wants to merge
16
commits into
ckb-js:main
Choose a base branch
from
gpBlockchain:test/add-e2e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+735
−6
Open
test: add test #237
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
39ddfdc
test: add create wallet && import wallet test
gpBlockchain 5fc4b91
test: add account-detail test
gpBlockchain 89b8803
test: add add-network test && add-whitelist-site test
gpBlockchain a0d13e5
test: add network change test
gpBlockchain f86c1d9
Merge branch 'ckb-js:main' into test/add-e2e
gpBlockchain b686822
test: change https url
gpBlockchain a0aff73
test: click btn with exact
gpBlockchain 4a28559
test: click btn with exact
gpBlockchain 37c5e08
test: add search todo
gpBlockchain c1c1941
test: add ckb get blockchain info test
gpBlockchain 2a0046f
Merge branch 'ckb-js:main' into test/add-e2e
gpBlockchain 8f1675a
test: remove todo func
gpBlockchain f012539
Merge remote-tracking branch 'origin/test/add-e2e' into test/add-e2e
gpBlockchain c79d402
Merge branch 'ckb-js:main' into test/add-e2e
gpBlockchain 2509060
Pr/gp blockchain/237 (#6)
IronLu233 75d4b24
Merge branch 'main' into test/add-e2e
gpBlockchain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { DefaultTestEnv } from '../helpers'; | ||
|
||
DefaultTestEnv.setupTest({ initWalletWithDefaults: true }); | ||
|
||
describe('Show wallet details', function () { | ||
it('should show nick name for wallet', 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 wallet', 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 wallet', 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 wallet', 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 wallet', 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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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'); | ||
}); | ||
|
||
/** | ||
* 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 wallet_enable work that add url protocol is HTTP', async () => { | ||
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 wallet_enable work that add url protocol 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] : ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { DefaultTestEnv } from '../helpers'; | ||
|
||
DefaultTestEnv.setupTest({ initWalletWithDefaults: true }); | ||
|
||
describe('Change network', function () { | ||
it('should get networkChanged when network change', async () => { | ||
await page.evaluate(() => { | ||
window.ckbNetworkName = ''; | ||
window.ckb.on('networkChanged', (networkName: string) => { | ||
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(() => { | ||
return window.ckbNetworkName; | ||
}); | ||
expect(ckbNetworkName).toBe('ckb'); | ||
await extensionIdPage.getByText('Testnet').click(); | ||
ckbNetworkName = await page.evaluate(() => { | ||
return window.ckbNetworkName; | ||
}); | ||
expect(ckbNetworkName).toBe('ckb_testnet'); | ||
}); | ||
it('should get ckb name that change network is user added', async () => { | ||
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(() => { | ||
window.ckbNetworkName = ''; | ||
window.ckb.on('networkChanged', (networkName: string) => { | ||
window.ckbNetworkName = networkName; | ||
}); | ||
}); | ||
await extensionIdPage.getByText(randName).click(); | ||
let ckbNetworkName = await page.evaluate(() => { | ||
return window.ckbNetworkName; | ||
}); | ||
expect(ckbNetworkName).toBe(randName); | ||
|
||
await extensionIdPage.getByText(notCkbName).click(); | ||
|
||
ckbNetworkName = await page.evaluate(() => { | ||
return window.ckbNetworkName; | ||
}); | ||
|
||
expect(ckbNetworkName).toBe(notCkbName); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 get inner tests and asset it to contain two
Testnet