aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/base.conf.js2
-rw-r--r--test/e2e/func.js18
-rw-r--r--test/e2e/metamask.spec.js122
-rw-r--r--test/unit/migrations/023-test.js99
-rw-r--r--test/unit/tx-state-manager-test.js6
5 files changed, 244 insertions, 3 deletions
diff --git a/test/base.conf.js b/test/base.conf.js
index adb5357e8..e2e9d44ba 100644
--- a/test/base.conf.js
+++ b/test/base.conf.js
@@ -19,11 +19,13 @@ module.exports = function(config) {
'test/integration/jquery-3.1.0.min.js',
{ pattern: 'dist/chrome/images/**/*.*', watched: false, included: false, served: true },
{ pattern: 'dist/chrome/fonts/**/*.*', watched: false, included: false, served: true },
+ { pattern: 'dist/chrome/_locales/**/*.*', watched: false, included: false, served: true },
],
proxies: {
'/images/': '/base/dist/chrome/images/',
'/fonts/': '/base/dist/chrome/fonts/',
+ '/_locales/': '/base/dist/chrome/_locales/',
},
// test results reporter to use
diff --git a/test/e2e/func.js b/test/e2e/func.js
new file mode 100644
index 000000000..733225565
--- /dev/null
+++ b/test/e2e/func.js
@@ -0,0 +1,18 @@
+require('chromedriver')
+const webdriver = require('selenium-webdriver')
+
+exports.delay = function delay (time) {
+ return new Promise(resolve => setTimeout(resolve, time))
+}
+
+
+exports.buildWebDriver = function buildWebDriver (extPath) {
+ return new webdriver.Builder()
+ .withCapabilities({
+ chromeOptions: {
+ args: [`load-extension=${extPath}`],
+ },
+ })
+ .forBrowser('chrome')
+ .build()
+}
diff --git a/test/e2e/metamask.spec.js b/test/e2e/metamask.spec.js
new file mode 100644
index 000000000..c73ba2b41
--- /dev/null
+++ b/test/e2e/metamask.spec.js
@@ -0,0 +1,122 @@
+const path = require('path')
+const assert = require('assert')
+const webdriver = require('selenium-webdriver')
+const By = webdriver.By
+const { delay, buildWebDriver } = require('./func')
+
+describe('Metamask popup page', function () {
+ let driver
+ this.seedPhase
+ this.accountAddress
+ this.timeout(0)
+
+ before(async function () {
+ const extPath = path.resolve('dist/chrome')
+ driver = buildWebDriver(extPath)
+ await driver.get('chrome://extensions-frame')
+ const elems = await driver.findElements(By.className('extension-list-item-wrapper'))
+ const extensionId = await elems[1].getAttribute('id')
+ await driver.get(`chrome-extension://${extensionId}/popup.html`)
+ await delay(500)
+ })
+
+ after(async function () {
+ await driver.quit()
+ })
+
+ describe('#onboarding', () => {
+ it('should open Metamask.io', async function () {
+ const tabs = await driver.getAllWindowHandles()
+ await driver.switchTo().window(tabs[0])
+ await delay(300)
+ })
+
+ it('should match title', async () => {
+ const title = await driver.getTitle()
+ assert.equal(title, 'MetaMask Plugin', 'title matches MetaMask Plugin')
+ })
+
+ it('should show privacy notice', async () => {
+ const privacy = await driver.findElement(By.className(
+ 'terms-header'
+ )).getText()
+ assert.equal(privacy, 'PRIVACY NOTICE', 'shows privacy notice')
+ driver.findElement(By.css(
+ 'button'
+ )).click()
+ })
+
+ it('should show terms of use', async () => {
+ await delay(300)
+ const terms = await driver.findElement(By.className(
+ 'terms-header'
+ )).getText()
+ assert.equal(terms, 'TERMS OF USE', 'shows terms of use')
+ })
+
+ it('should be unable to continue without scolling throught the terms of use', async () => {
+ const button = await driver.findElement(By.css(
+ 'button'
+ )).isEnabled()
+ assert.equal(button, false, 'disabled continue button')
+ const element = driver.findElement(By.linkText(
+ 'Attributions'
+ ))
+ await driver.executeScript('arguments[0].scrollIntoView(true)', element)
+ })
+
+ it('should be able to continue when scrolled to the bottom of terms of use', async () => {
+ const button = await driver.findElement(By.css('button'))
+ const buttonEnabled = await button.isEnabled()
+ await delay(500)
+ assert.equal(buttonEnabled, true, 'enabled continue button')
+ await button.click()
+ })
+
+ it('should accept password with length of eight', async () => {
+ await delay(300)
+ const passwordBox = await driver.findElement(By.id('password-box'))
+ const passwordBoxConfirm = await driver.findElement(By.id('password-box-confirm'))
+ const button = driver.findElement(By.css('button'))
+
+ passwordBox.sendKeys('123456789')
+ passwordBoxConfirm.sendKeys('123456789')
+ await delay(500)
+ await button.click()
+ })
+
+ it('should show value was created and seed phrase', async () => {
+ await delay(700)
+ this.seedPhase = await driver.findElement(By.className('twelve-word-phrase')).getText()
+ const continueAfterSeedPhrase = await driver.findElement(By.css('button'))
+ await continueAfterSeedPhrase.click()
+ })
+
+ it('should show lock account', async () => {
+ await delay(300)
+ await driver.findElement(By.className('sandwich-expando')).click()
+ await delay(500)
+ await driver.findElement(By.xpath('//*[@id="app-content"]/div/div[3]/span/div/li[2]')).click()
+ })
+
+ it('should accept account password after lock', async () => {
+ await delay(500)
+ await driver.findElement(By.id('password-box')).sendKeys('123456789')
+ await driver.findElement(By.css('button')).click()
+ await delay(500)
+ })
+
+ it('should show QR code', async () => {
+ await delay(300)
+ await driver.findElement(By.className('fa-ellipsis-h')).click()
+ await driver.findElement(By.xpath('//*[@id="app-content"]/div/div[4]/div/div/div[1]/flex-column/div[1]/div/span/i/div/div/li[2]')).click()
+ await delay(300)
+ })
+
+ it('should show the account address', async () => {
+ this.accountAddress = await driver.findElement(By.className('ellip-address')).getText()
+ await driver.findElement(By.className('fa-arrow-left')).click()
+ await delay(500)
+ })
+ })
+})
diff --git a/test/unit/migrations/023-test.js b/test/unit/migrations/023-test.js
new file mode 100644
index 000000000..be432d9fa
--- /dev/null
+++ b/test/unit/migrations/023-test.js
@@ -0,0 +1,99 @@
+const assert = require('assert')
+const migration23 = require('../../../app/scripts/migrations/023')
+const properTime = (new Date()).getTime()
+const storage = {
+ "meta": {},
+ "data": {
+ "TransactionController": {
+ "transactions": [
+ ]
+ },
+ },
+}
+
+const transactions = []
+const transactions40 = []
+const transactions20 = []
+
+const txStates = [
+ 'unapproved',
+ 'approved',
+ 'signed',
+ 'submitted',
+ 'confirmed',
+ 'rejected',
+ 'failed',
+ 'dropped',
+]
+
+const deletableTxStates = [
+ 'confirmed',
+ 'rejected',
+ 'failed',
+ 'dropped',
+]
+
+let nonDeletableCount = 0
+
+let status
+while (transactions.length <= 100) {
+ status = txStates[Math.floor(Math.random() * Math.floor(txStates.length - 1))]
+ if (!deletableTxStates.find((s) => s === status)) nonDeletableCount++
+ transactions.push({status})
+}
+
+while (transactions40.length < 40) {
+ status = txStates[Math.floor(Math.random() * Math.floor(txStates.length - 1))]
+ transactions40.push({status})
+}
+
+while (transactions20.length < 20) {
+ status = txStates[Math.floor(Math.random() * Math.floor(txStates.length - 1))]
+ transactions20.push({status})
+}
+
+
+
+storage.data.TransactionController.transactions = transactions
+
+describe('storage is migrated successfully and the proper transactions are remove from state', () => {
+ it('should remove transactions that are unneeded', (done) => {
+ migration23.migrate(storage)
+ .then((migratedData) => {
+ let leftoverNonDeletableTxCount = 0
+ const migratedTransactions = migratedData.data.TransactionController.transactions
+ migratedTransactions.forEach((tx) => {
+ if (!deletableTxStates.find((s) => s === tx.status)) {
+ leftoverNonDeletableTxCount++
+ }
+ })
+ assert.equal(leftoverNonDeletableTxCount, nonDeletableCount, 'migration shouldnt delete transactions we want to keep')
+ assert((migratedTransactions.length >= 40), `should be equal or greater to 40 if they are non deletable states got ${migratedTransactions.length} transactions`)
+ done()
+ }).catch(done)
+ })
+
+ it('should not remove any transactions because 40 is the expectable limit', (done) => {
+ storage.meta.version = 22
+ storage.data.TransactionController.transactions = transactions40
+ migration23.migrate(storage)
+ .then((migratedData) => {
+ const migratedTransactions = migratedData.data.TransactionController.transactions
+
+ assert.equal(migratedTransactions.length, 40, 'migration shouldnt delete when at limit')
+ done()
+ }).catch(done)
+ })
+
+ it('should not remove any transactions because 20 txs is under the expectable limit', (done) => {
+ storage.meta.version = 22
+ storage.data.TransactionController.transactions = transactions20
+ migration23.migrate(storage)
+ .then((migratedData) => {
+ const migratedTransactions = migratedData.data.TransactionController.transactions
+ assert.equal(migratedTransactions.length, 20, 'migration shouldnt delete when under limit')
+ done()
+ }).catch(done)
+ })
+
+})
diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js
index 220bf501f..a5ac13664 100644
--- a/test/unit/tx-state-manager-test.js
+++ b/test/unit/tx-state-manager-test.js
@@ -240,12 +240,12 @@ describe('TransactionStateManager', function () {
})
describe('#wipeTransactions', function () {
-
+
const specificAddress = '0xaa'
const otherAddress = '0xbb'
it('should remove only the transactions from a specific address', function () {
-
+
const txMetas = [
{ id: 0, status: 'unapproved', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: currentNetworkId },
{ id: 1, status: 'confirmed', txParams: { from: otherAddress, to: specificAddress }, metamaskNetworkId: currentNetworkId },
@@ -268,7 +268,7 @@ describe('TransactionStateManager', function () {
{ id: 1, status: 'confirmed', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: otherNetworkId },
{ id: 2, status: 'confirmed', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: otherNetworkId },
]
-
+
txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop))
txStateManager.wipeTransactions(specificAddress)