This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: selector issues, useless timeouts, reorganise tests (#145)
* fix: update ganache, fix test depending on goerli * fix: bugs in selectors, less timeout, reorganise structure * update yarn * chore: improve root hooks * try to increase timeout * better ci * add screenshot uploading to ci * fix screenshot name * run screenshot on failed test * fix lint * change viewport * fix tests * fix#123124 * fix tests * whyyyyyyyyyyyyyyyyyyyyyyyyy * please * fix testing dapp * dunno anymore * fix lint * fix typo in selector * update dapp loading * refactor script fetching for `index.html` * fix dam sing test Co-authored-by: Bernard <bero4net@gmail.com>
- Loading branch information
Showing
24 changed files
with
676 additions
and
613 deletions.
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ dist | |
/metamask | ||
.idea | ||
*.log | ||
test/dapp/data.js | ||
test/dapp/data.js | ||
*.png |
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 @@ | ||
parallel: false | ||
recursive: true | ||
color: true | ||
timeout: 20000 | ||
exit: true | ||
require: | ||
- 'ts-node/register' | ||
- 'test/global.ts' | ||
spec: | ||
- 'test/**/*.spec.ts' |
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
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
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
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
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,126 @@ | ||
import { expect, use } from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { Page } from 'puppeteer'; | ||
|
||
import * as dappeteer from '../src'; | ||
import { clickOnLogo, openProfileDropdown } from '../src/helpers'; | ||
|
||
import { PASSWORD, TestContext } from './global'; | ||
import { clickElement } from './utils/utils'; | ||
|
||
use(chaiAsPromised); | ||
|
||
describe('basic interactions', async function () { | ||
let metamask: dappeteer.Dappeteer; | ||
let testPage: Page; | ||
|
||
before(async function (this: TestContext) { | ||
testPage = await this.browser.newPage(); | ||
await testPage.goto('http://localhost:8080/', { waitUntil: 'networkidle0' }); | ||
metamask = this.metamask; | ||
try { | ||
await clickElement(testPage, '.connect-button'); | ||
await metamask.approve(); | ||
} catch (e) { | ||
//ignored | ||
} | ||
}); | ||
|
||
after(async function () { | ||
await testPage.close(); | ||
}); | ||
|
||
it('should be able to sign', async () => { | ||
await clickElement(testPage, '.sign-button'); | ||
|
||
await metamask.sign(); | ||
|
||
await testPage.waitForSelector('#signed'); | ||
}); | ||
|
||
it('should switch network', async () => { | ||
await metamask.switchNetwork('localhost'); | ||
|
||
const selectedNetwork = await metamask.page.evaluate( | ||
() => (document.querySelector('.network-display > span:nth-child(2)') as HTMLSpanElement).innerHTML, | ||
); | ||
expect(selectedNetwork).to.be.equal('Localhost 8545'); | ||
}); | ||
|
||
it('should return eth balance', async () => { | ||
await metamask.switchNetwork('localhost'); | ||
const tokenBalance: number = await metamask.helpers.getTokenBalance('ETH'); | ||
expect(tokenBalance).to.be.greaterThan(0); | ||
}); | ||
|
||
it('should return 0 token balance when token not found', async () => { | ||
const tokenBalance: number = await metamask.helpers.getTokenBalance('FARTBUCKS'); | ||
expect(tokenBalance).to.be.equal(0); | ||
}); | ||
|
||
// TODO: cover more cases | ||
it('should add token', async () => { | ||
await metamask.switchNetwork('kovan'); | ||
await metamask.addToken({ | ||
tokenAddress: '0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa', | ||
symbol: 'KAKI', | ||
}); | ||
await metamask.switchNetwork('local'); | ||
}); | ||
|
||
it('should add network with required params', async () => { | ||
await metamask.addNetwork({ | ||
networkName: 'Binance Smart Chain', | ||
rpc: 'https://data-seed-prebsc-1-s1.binance.org:8545/', | ||
chainId: 97, | ||
symbol: 'BNB', | ||
}); | ||
|
||
const selectedNetwork = await metamask.page.evaluate( | ||
() => (document.querySelector('.network-display > span:nth-child(2)') as HTMLSpanElement).innerHTML, | ||
); | ||
expect(selectedNetwork).to.be.equal('Binance Smart Chain'); | ||
await metamask.switchNetwork('local'); | ||
}); | ||
|
||
it('should fail to add network with wrong chain ID', async () => { | ||
await expect( | ||
metamask.addNetwork({ | ||
networkName: 'Optimistic Ethereum Testnet Kovan', | ||
rpc: 'https://kovan.optimism.io/', | ||
chainId: 420, | ||
symbol: 'KUR', | ||
}), | ||
).to.be.rejectedWith(SyntaxError); | ||
|
||
await clickOnLogo(metamask.page); | ||
}); | ||
|
||
it('should import private key', async () => { | ||
const countAccounts = async (): Promise<number> => { | ||
await openProfileDropdown(metamask.page); | ||
const container = await metamask.page.$('.account-menu__accounts'); | ||
const count = (await container.$$('.account-menu__account')).length; | ||
await openProfileDropdown(metamask.page); | ||
return count; | ||
}; | ||
|
||
const beforeImport = await countAccounts(); | ||
await metamask.importPK('4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b10'); | ||
const afterImport = await countAccounts(); | ||
|
||
expect(beforeImport + 1).to.be.equal(afterImport); | ||
await metamask.helpers.deleteAccount(2); | ||
}); | ||
|
||
it('should throw error on wrong key', async () => { | ||
await expect( | ||
metamask.importPK('4f3edf983ac636a65a$@!ce7c78d9aa706d3b113bce9c46f30d7d21715b23b10'), | ||
).to.be.rejectedWith(SyntaxError); | ||
}); | ||
|
||
it('should lock and unlock', async () => { | ||
await metamask.lock(); | ||
await metamask.unlock(PASSWORD); | ||
}); | ||
}); |
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,60 @@ | ||
import { expect } from 'chai'; | ||
import { Page } from 'puppeteer'; | ||
|
||
import { Dappeteer } from '../src'; | ||
|
||
import { Contract } from './deploy'; | ||
import { TestContext } from './global'; | ||
import { clickElement, pause } from './utils/utils'; | ||
|
||
describe('contract interactions', async function () { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let contract: Contract; | ||
let testPage: Page; | ||
let metamask: Dappeteer; | ||
|
||
before(async function (this: TestContext) { | ||
testPage = await this.browser.newPage(); | ||
await testPage.goto('http://localhost:8080/', { waitUntil: 'load' }); | ||
metamask = this.metamask; | ||
contract = this.contract; | ||
try { | ||
await clickElement(testPage, '.connect-button'); | ||
await metamask.approve(); | ||
} catch (e) { | ||
//ignored | ||
} | ||
}); | ||
|
||
after(async function (this: TestContext) { | ||
await testPage.close(); | ||
}); | ||
|
||
it('should have increased count', async () => { | ||
await metamask.switchAccount(1); | ||
await metamask.switchNetwork('local'); | ||
await pause(1); | ||
const counterBefore = await getCounterNumber(contract); | ||
// click increase button | ||
await clickElement(testPage, '.increase-button'); | ||
await pause(1); | ||
// submit tx | ||
await metamask.confirmTransaction(); | ||
await testPage.waitForSelector('#txSent'); | ||
await pause(1); | ||
|
||
const counterAfter = await getCounterNumber(contract); | ||
|
||
expect(counterAfter).to.be.equal(counterBefore + 1); | ||
await metamask.switchNetwork('main'); | ||
}); | ||
}); | ||
|
||
function getCounterNumber(contract): Promise<number> { | ||
return contract.methods | ||
.count() | ||
.call() | ||
.then((res) => { | ||
return Number(res); | ||
}); | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.