From 81b7ca774935a4b49c27841b059f56984d611d77 Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 5 Feb 2018 17:32:24 +0100 Subject: [PATCH 01/14] fix spectron always starting dev tools --- app/src/main/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/index.js b/app/src/main/index.js index 90ca808b39..2389e24d4c 100644 --- a/app/src/main/index.js +++ b/app/src/main/index.js @@ -126,7 +126,7 @@ function createWindow () { } else { startVueApp() } - if (DEV || process.env.COSMOS_DEVTOOLS) { + if (DEV || JSON.parse(process.env.COSMOS_DEVTOOLS || 'false')) { mainWindow.webContents.openDevTools() } @@ -155,6 +155,9 @@ function createWindow () { function startProcess (name, args, env) { let binPath + if (process.env.BINARY_PATH) { + binPath = process.env.BINARY_PATH + } else if (DEV || TEST) { // in dev mode or tests, use binaries installed in GOPATH let GOPATH = process.env.GOPATH @@ -323,11 +326,13 @@ if (!TEST) { process.on('exit', shutdown) process.on('uncaughtException', async function (err) { logError('[Uncaught Exception]', err) + console.error('[Uncaught Exception]', err) await shutdown() process.exit(1) }) process.on('unhandledRejection', async function (err) { logError('[Unhandled Promise Rejection]', err) + console.error('[Unhandled Promise Rejection]', err) await shutdown() process.exit(1) }) From d21d2a1efe103619c30db028c455b2b6ff696d20 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 7 Feb 2018 14:33:33 +0000 Subject: [PATCH 02/14] updated config files for localhost --- test/e2e/localtestnet/config.toml | 36 +++++++++++---------------- test/e2e/localtestnet/gaiaversion.txt | 1 + 2 files changed, 16 insertions(+), 21 deletions(-) create mode 100644 test/e2e/localtestnet/gaiaversion.txt diff --git a/test/e2e/localtestnet/config.toml b/test/e2e/localtestnet/config.toml index 7406759d24..b264ba46d5 100644 --- a/test/e2e/localtestnet/config.toml +++ b/test/e2e/localtestnet/config.toml @@ -2,33 +2,27 @@ # For more information, see https://github.com/toml-lang/toml proxy_app = "tcp://127.0.0.1:46658" -moniker = "local" +moniker = "localhost" fast_sync = true -db_backend = "memdb" -#log_level = "mempool:error,*:debug" + +db_backend = "leveldb" log_level = "state:info,*:error" +#log_level = "*:debug" + [rpc] -laddr = "tcp://127.0.0.1:46657" +laddr = "tcp://0.0.0.0:46657" -#[mempool] -#recheck = false -#broadcast = false -#wal_dir = "" [consensus] -#max_block_size_txs = 10000 -#create_empty_blocks = false -#timeout_propose = 10000 -#skip_timeout_commit = true -#timeout_commit = 1 -#wal_light = true -#block_part_size = 262144 -create_empty_blocks_interval = 1 +create_empty_blocks_interval = 60 + +[tx_index] +index_all_tags = true + [p2p] -#max_msg_packet_payload_size=65536 -#send_rate=51200000 # 50 MB/s -#recv_rate=51200000 # 50 MB/s -laddr = "tcp://127.0.0.1:46656" -seeds = "" +max_num_peers = 300 +pex = true +laddr = "tcp://0.0.0.0:46656" +seeds = "localhost:46656" diff --git a/test/e2e/localtestnet/gaiaversion.txt b/test/e2e/localtestnet/gaiaversion.txt new file mode 100644 index 0000000000..48080b4cf2 --- /dev/null +++ b/test/e2e/localtestnet/gaiaversion.txt @@ -0,0 +1 @@ +v0.5.0 \ No newline at end of file From 623b3e5de6475fdc1b2b4e596837a79a1fc141d8 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 7 Feb 2018 14:33:43 +0000 Subject: [PATCH 03/14] removed main process tests --- test/e2e/main.js | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 test/e2e/main.js diff --git a/test/e2e/main.js b/test/e2e/main.js deleted file mode 100644 index fc532ce33a..0000000000 --- a/test/e2e/main.js +++ /dev/null @@ -1,39 +0,0 @@ -let { join } = require('path') -let test = require('tape-promise/tape') -let proxyquire = require('proxyquire') -let { newTempDir } = require('./common.js') - -let home = newTempDir() -console.error(`ui home: ${home}`) - -Object.assign(process.env, { - COSMOS_TEST: 'true', - COSMOS_HOME: home, - COSMOS_NETWORK: join(__dirname, 'gaia-1') -}) - -test('main', async function (t) { - let main = proxyquire('../../app/dist/main', { - electron: { - app: { - on: () => {}, - quit: () => {} - } - } - }).default - - main - .then(() => { - t.ok(true, 'main function is running') - cleanUp(t, main) - }) - .catch(e => { - t.fail(e) - cleanUp(t, main) - }) -}) - -function cleanUp (t, main) { - main.shutdown() - t.end() -} From 9cd7568c7897101d9fd6e7cbd4b3a8e27eb76b05 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 7 Feb 2018 14:34:15 +0000 Subject: [PATCH 04/14] fix launching of app --- test/e2e/launch.js | 157 +++++++++++++++++++++++++++++++++------------ 1 file changed, 117 insertions(+), 40 deletions(-) diff --git a/test/e2e/launch.js b/test/e2e/launch.js index e1e4c36f64..d979c88cdd 100644 --- a/test/e2e/launch.js +++ b/test/e2e/launch.js @@ -4,53 +4,78 @@ let { Application } = require('spectron') let test = require('tape-promise/tape') let electron = require('electron') let { join } = require('path') +let { spawn } = require('child_process') let { newTempDir } = require('./common.js') // re-use app instance -let app - -module.exports = async function launch (t) { - if (app) return app - - let home = newTempDir() - console.error(`ui home: ${home}`) - - app = new Application({ - path: electron, - args: [ - join(__dirname, '../../app/dist/main.js'), - '--disable-gpu', - '--no-sandbox' - ], - startTimeout: 10000, - waitTimeout: 10000, - env: { - COSMOS_UI_ONLY: 'true', - COSMOS_TEST: 'true', - COSMOS_HOME: home, - COSMOS_NETWORK: join(__dirname, 'gaia-1') - } - }) +let app, home, cliHome, started +let binary = process.env.BINARY_PATH - await app.start() +module.exports = function launch (t) { + if (!started) { + started = new Promise(async (resolve, reject) => { + console.log('using binary', binary) + + // TODO cleanup + home = newTempDir() + cliHome = join(newTempDir(), 'baseserver') + console.error(`ui home: ${home}`) + console.error(`node home: ${cliHome}`) + + await startLocalNode() + + app = new Application({ + path: electron, + args: [ + join(__dirname, '../../app/dist/main.js'), + '--disable-gpu', + '--no-sandbox' + ], + startTimeout: 10000, + waitTimeout: 10000, + env: { + // COSMOS_UI_ONLY: 'true', + // COSMOS_TEST: 'true', + COSMOS_NODE: 'localhost', + NODE_ENV: 'production', + PREVIEW: 'true', + COSMOS_DEVTOOLS: 0, // open devtools will cause issues with spectron, you can open them later manually + COSMOS_HOME: home, + COSMOS_NETWORK: 'test/e2e/localtestnet' + } + }) - t.test('launch app', function (t) { - t.ok(app.isRunning(), 'app is running') - t.end() - }) + await startApp(app) + t.ok(app.isRunning(), 'app is running') - t.test('wait for app to load', async function (t) { - await app.client.waitForExist('.header-item-logo', 5000) - .then(() => t.pass('app loaded')) - .catch(e => { - printAppLog(app) - t.fail() - throw e - }) - t.end() - }) + console.log('stopping app to test consecutive run') + await app.stop() - return app + await new Promise((resolve, reject) => { + let child = spawn(binary, [ + 'client', 'keys', 'recover', 'testkey', + '--home', join(home, 'baseserver') + ]) + child.stdin.write('1234567890\n') + child.stdin.write('chair govern physical divorce tape movie slam field gloom process pen universe allow pyramid private ability\n') + child.stderr.pipe(process.stdout) + child.once('exit', (code) => { + if (code === 0) resolve() + reject() + }) + }) + console.log('restored test account') + + await startApp(app) + t.ok(app.isRunning(), 'app is running') + + await login(app) + + resolve(app) + }) + } + + return started } test.onFinish(() => app ? app.stop() : null) @@ -69,3 +94,55 @@ function printAppLog (app) { }) }) } + +async function login (app) { + await app.client.$('#sign-in-password').setValue('1234567890') + await app.client.$('.ni-session-footer button').click() + await app.client.waitForExist('#app-content', 5000) +} + +async function startApp (app) { + await app.start() + + await app.client.waitForExist('.ni-session', 5000) + .catch(e => { + printAppLog(app) + throw e + }) +} + +async function startLocalNode () { + await new Promise((resolve, reject) => { + let child = spawn(binary, [ + 'node', 'init', + '3F52AFC4FB737A0296EFE331885FCC476980B3BD', + '--home', cliHome, + '--chain-id' , 'localtestnet' + ]) + child.once('exit', (code) => { + if (code === 0) resolve() + reject() + }) + }) + console.log('inited local node') + + await new Promise((resolve, reject) => { + // TODO cleanup + let localnodeProcess = spawn(binary, [ + 'node', 'start', + '--home', cliHome + ]) + localnodeProcess.stderr.pipe(process.stderr) + localnodeProcess.stdout.once('data', data => { + let msg = data.toString() + if (!msg.includes('Failed') && !msg.includes('Error')) { + resolve() + } + reject() + }) + localnodeProcess.once('exit', (code) => { + reject() + }) + }) + console.log('started local node') +} \ No newline at end of file From dad2ae65c47ac061894c08b36a4b4585fa039fdd Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 7 Feb 2018 14:34:34 +0000 Subject: [PATCH 05/14] fix navigation --- test/e2e/common.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/e2e/common.js b/test/e2e/common.js index 4261028abb..c1cae54f27 100644 --- a/test/e2e/common.js +++ b/test/e2e/common.js @@ -6,7 +6,15 @@ function sleep (ms) { } module.exports = { - navigate (t, client, linkText, titleText = linkText) { + async navigate (t, client, linkText, titleText = linkText) { + // close notifications as they overlay the menu button + while (await client.isExisting(`.ni-notification`)) { + await client.$(`.ni-notification`).click() + } + // open menu + await client.$('#app-menu-button').click() + t.test(await client.$('.app-menu').isVisible(), 'menu opened') + // click link t.test(`navigate to "${linkText}"`, async function (t) { await client.$(`a*=${linkText}`).click() await client.waitUntilTextExists('.ni-page-header-title', titleText) From 70f62298607edf1a59b08ab04c2a5e3e28f1ed04 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 7 Feb 2018 19:22:55 +0000 Subject: [PATCH 06/14] improved async behaviour of navigate --- test/e2e/common.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/e2e/common.js b/test/e2e/common.js index c1cae54f27..951b0d8da5 100644 --- a/test/e2e/common.js +++ b/test/e2e/common.js @@ -13,22 +13,19 @@ module.exports = { } // open menu await client.$('#app-menu-button').click() - t.test(await client.$('.app-menu').isVisible(), 'menu opened') + await client.$('.app-menu').isVisible() // click link - t.test(`navigate to "${linkText}"`, async function (t) { - await client.$(`a*=${linkText}`).click() - await client.waitUntilTextExists('.ni-page-header-title', titleText) - t.pass(`navigated to "${linkText}"`) - t.end() - }) + await client.$(`a*=${linkText}`).click() + await client.waitUntilTextExists('.ni-page-header-title', titleText) + console.log(`navigated to "${linkText}"`) }, newTempDir () { return join(tmpdir(), Math.random().toString(36).slice(2)) }, sleep, - async waitForText (el, text, timeout = 5000) { + async waitForText (elGetterFn, text, timeout = 5000) { let start = Date.now() - while (await el().getText() !== text) { + while (await elGetterFn().getText() !== text) { if (Date.now() - start >= timeout) { throw Error('Timed out waiting for text') } From d92dde33422a12fbd63726672fbc83dad10beb56 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 7 Feb 2018 19:23:21 +0000 Subject: [PATCH 07/14] made wallet send tests work --- test/e2e/launch.js | 4 +- test/e2e/wallet.js | 166 +++++++++++++++++++++------------------------ 2 files changed, 78 insertions(+), 92 deletions(-) diff --git a/test/e2e/launch.js b/test/e2e/launch.js index d979c88cdd..7a8e32437d 100644 --- a/test/e2e/launch.js +++ b/test/e2e/launch.js @@ -71,7 +71,7 @@ module.exports = function launch (t) { await login(app) - resolve(app) + resolve({app, home}) }) } @@ -115,7 +115,7 @@ async function startLocalNode () { await new Promise((resolve, reject) => { let child = spawn(binary, [ 'node', 'init', - '3F52AFC4FB737A0296EFE331885FCC476980B3BD', + 'D0718DDFF62D301626B428A182F830CBB0AD21FC', '--home', cliHome, '--chain-id' , 'localtestnet' ]) diff --git a/test/e2e/wallet.js b/test/e2e/wallet.js index 4291b5bdeb..57ff5c552e 100644 --- a/test/e2e/wallet.js +++ b/test/e2e/wallet.js @@ -3,40 +3,11 @@ let test = require('tape-promise/tape') let launchApp = require('./launch.js') let { navigate, newTempDir, waitForText, sleep } = require('./common.js') -function cliInit (t, home) { - t.test('basecli init', function (t) { - let child = spawn('basecli', [ - 'init', - '--home', home, - '--chain-id', 'localtestnet', - '--node', 'localhost:46657' - ]) - child.stdout.once('data', () => { - child.stdin.write('y\n') - child.once('exit', (code) => { - t.equal(code, 0, 'exited with exit code 0') - t.end() - }) - }) - }) - - t.test('recover basecli test key', function (t) { - let child = spawn('basecli', [ - 'keys', 'recover', 'testkey', - '--home', home - ]) - child.stdin.write('1234567890\n') - child.stdin.write('chair govern physical divorce tape movie slam field gloom process pen universe allow pyramid private ability\n') - child.once('exit', (code) => { - t.equal(code, 0, 'exited with exit code 0') - t.end() - }) - }) -} +let binary = process.env.BINARY_PATH function cliSendCoins (home, to, amount) { - let child = spawn('basecli', [ - 'tx', 'send', + let child = spawn(binary, [ + 'client', 'tx', 'send', '--name', 'testkey', '--to', to, '--amount', amount, @@ -50,107 +21,122 @@ function cliSendCoins (home, to, amount) { } test('wallet', async function (t) { - let app, client + let {app, home} = await launchApp(t) + let client = app.client let $ = (...args) => client.$(...args) - app = await launchApp(t) - client = app.client - - let cliHome = newTempDir() - console.error(`basecli home: ${cliHome}`) - cliInit(t, cliHome) - + let balanceEl = (denom) => - $(`div=${denom.toUpperCase()}`) + $(`//div[contains(text(), "${denom.toUpperCase()}")]`) .$('..') .$('div.ni-li-dd') - t.test('receive', async function (t) { - navigate(t, client, 'Balances') + // t.test('receive', async function (t) { + // await navigate(t, client, 'Balances') + + // let address + // t.test('address', async function (t) { + // let addressEl = $('//div[contains(text(), "Your Address")]').$('..').$('..').$('..').$('.ni-li-copy .value') + // address = await addressEl.getText() + // t.ok(address, `address: ${address}`) + // t.equal(address.length, 40, 'address is correct length') + // t.end() + // }) + + // t.test('fermion balance before receiving', async function (t) { + // let mycoinEl = balanceEl('fermion') + // let balance = await mycoinEl.getText() + // t.equal(balance, '9007199254740992', 'fermion balance is greater 0') + // t.end() + // }) + + // t.test('receive mycoin', async function (t) { + // await cliSendCoins(home, address, '1000mycoin') + // t.end() + // }) + + // t.test('mycoin balance after receiving', async function (t) { + // let mycoinEl = () => balanceEl('mycoin') + // await waitForText(mycoinEl, '1000', 8000) + // t.pass('received mycoin transaction') + // t.end() + // }) + + // t.end() + // }) - let address - t.test('address', async function (t) { - let addressEl = $('div=Address').$('..').$('div.ni-li-dd') - address = await addressEl.getText() - t.ok(address, `address: ${address}`) - t.equal(address.length, 40, 'address is correct length') - t.end() - }) + t.test('send', async function (t) { + async function goToSendPage () { + await navigate(t, client, 'Balances') + await $('.ni-li-dt=FERMION').$('..').$('..').click() + } - t.test('mycoin balance before receiving', async function (t) { - let mycoinEl = balanceEl('mycoin') - let balance = await mycoinEl.getText() - t.equal(balance, '0', 'mycoin balance is 0') - t.end() - }) + await navigate(t, client, 'Balances') - t.test('receive mycoin', async function (t) { - await cliSendCoins(cliHome, address, '1000mycoin') - t.end() - }) + let sendBtn = () => $('.ni-form-footer button') + let addressInput = () => $('#send-address') + let amountInput = () => $('#send-amount') + let denomBtn = (denom) => $(`option=${denom.toUpperCase()}`) - t.test('mycoin balance after receiving', async function (t) { - let mycoinEl = () => balanceEl('mycoin') - await waitForText(mycoinEl, '1000', 8000) - t.pass('received mycoin transaction') + t.test('fermion balance before sending', async function (t) { + let fermionEl = balanceEl('fermion') + let balance = await fermionEl.getText() + t.equal(balance, '9007199254740992', 'fermion balance is correct') t.end() }) - t.end() - }) - - t.test('send', async function (t) { - navigate(t, client, 'Send', 'Send Coins') - - let sendBtn = () => $('button=Send Now') - let addressInput = () => $('#send-address') - let amountInput = () => $('#send-amount') - let denomBtn = (denom) => $(`button=${denom.toUpperCase()}`) - t.test('hit send with empty form', async function (t) { + await goToSendPage() await sendBtn().click() - t.equal(await sendBtn().getText(), 'Send Now', 'not sending') + t.equal(await sendBtn().getText(), 'Send Tokens', 'not sending') t.end() }) t.test('address w/ less than 40 chars', async function (t) { + await goToSendPage() await addressInput().setValue('012345') await $('div=Address must be exactly 40 characters').waitForExist() t.pass('got correct error message') await sendBtn().click() - t.equal(await sendBtn().getText(), 'Send Now', 'not sending') + t.equal(await sendBtn().getText(), 'Send Tokens', 'not sending') t.end() }) t.test('address w/ 40 chars', async function (t) { + await goToSendPage() await addressInput().setValue('0'.repeat(40)) t.notOk(await client.isExisting('div=Address must be exactly 40 characters'), 'no error message') await sendBtn().click() - t.equal(await sendBtn().getText(), 'Send Now', 'not sending') + t.equal(await sendBtn().getText(), 'Send Tokens', 'not sending') t.end() }) t.test('amount set', async function (t) { + await goToSendPage() await amountInput().setValue('100') await sendBtn().click() - t.equal(await sendBtn().getText(), 'Send Now', 'not sending') - // await $('div=Denomination is required').waitForExist() - // t.pass('got correct error message') + t.equal(await sendBtn().getText(), 'Send Tokens', 'not sending') + t.end() }) - t.test('denom set', async function (t) { - await denomBtn('mycoin').click() - await sleep(100) + t.test('send', async function (t) { + await goToSendPage() + await amountInput().setValue('100') + await addressInput().setValue('3F52AFC4FB737A0296EFE331885FCC476980B3BD') await sendBtn().click() + await client.waitForExist('.ni-notification', 5000) + let msg = await client.$('.ni-notification .body').getText() + t.ok(msg.includes('Success'), 'Send successful') + t.end() }) - navigate(t, client, 'Balances') - t.test('own balance updated', async function (t) { - let mycoinEl = () => balanceEl('mycoin') - await waitForText(mycoinEl, '900') - t.pass('balance is now 900') + await navigate(t, client, 'Balances') + + let mycoinEl = () => balanceEl('fermion') + await waitForText(mycoinEl, '9007199254740892') + t.pass('balance is reduced by 100') t.end() }) From 6713c703076722a18bd585d5ec79f2d9b5b19803 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 7 Feb 2018 19:33:43 +0000 Subject: [PATCH 08/14] fix test for not refrshing balance --- test/e2e/wallet.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/e2e/wallet.js b/test/e2e/wallet.js index 57ff5c552e..e8ee15fd23 100644 --- a/test/e2e/wallet.js +++ b/test/e2e/wallet.js @@ -134,6 +134,10 @@ test('wallet', async function (t) { t.test('own balance updated', async function (t) { await navigate(t, client, 'Balances') + // TODO should not be necessary + await sleep(1000) + await client.$('.material-icons=refresh').click() + let mycoinEl = () => balanceEl('fermion') await waitForText(mycoinEl, '9007199254740892') t.pass('balance is reduced by 100') From fd8ced4847f30d5c4bff82df284216859c9646cd Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 9 Feb 2018 11:42:04 +0000 Subject: [PATCH 09/14] receive works --- test/e2e/common.js | 43 ++++++++++++++++++++++++++++++++++++-- test/e2e/launch.js | 43 +++++++++++++++++++------------------- test/e2e/wallet.js | 51 +++++++++++++++------------------------------- 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/test/e2e/common.js b/test/e2e/common.js index 951b0d8da5..2590685936 100644 --- a/test/e2e/common.js +++ b/test/e2e/common.js @@ -6,14 +6,16 @@ function sleep (ms) { } module.exports = { - async navigate (t, client, linkText, titleText = linkText) { + async openMenu (client) { // close notifications as they overlay the menu button while (await client.isExisting(`.ni-notification`)) { await client.$(`.ni-notification`).click() } - // open menu await client.$('#app-menu-button').click() await client.$('.app-menu').isVisible() + }, + async navigate (t, client, linkText, titleText = linkText) { + await module.exports.openMenu(client) // click link await client.$(`a*=${linkText}`).click() await client.waitUntilTextExists('.ni-page-header-title', titleText) @@ -31,5 +33,42 @@ module.exports = { } await sleep(100) } + }, + async login (client, account = 'testkey') { + console.log('logging into ' + account) + let accountsSelect = '#sign-in-name select' + + await selectOption(client, accountsSelect, account) + + await client.$('#sign-in-password').setValue('1234567890') + await client.$('.ni-session-footer button').click() + await client.waitForExist('#app-content', 5000) + + // let address = await client.$('.ni-li-copy .value').getText() + // TODO check if correct account logged in + }, + async logout (client) { + console.log('logging out') + await module.exports.openMenu(client) + + await client.$('.ni-li-user').click() + await client.$('.material-icons=exit_to_app').$('..').click() + } +} + +// only sending keyboard arrows worked for selecting options +async function selectOption (client, selectSelector, text) { + // go up to the first option + await client.$(selectSelector).click() + await client.keys(['\uE013', '\uE013', '\uE013', '\uE013', '\uE013', '\uE013']) // TODO calc options length + // then go down until we have the option we want + let found = false + while (!found) { + let value = (await client.$(selectSelector).getValue()).trim() + found = text === value + if (!found) { + await client.$(selectSelector).click() + await client.keys(['\uE015']) + } } } diff --git a/test/e2e/launch.js b/test/e2e/launch.js index 7a8e32437d..582e3de1c9 100644 --- a/test/e2e/launch.js +++ b/test/e2e/launch.js @@ -5,7 +5,7 @@ let test = require('tape-promise/tape') let electron = require('electron') let { join } = require('path') let { spawn } = require('child_process') -let { newTempDir } = require('./common.js') +let { newTempDir, login } = require('./common.js') // re-use app instance let app, home, cliHome, started @@ -51,25 +51,14 @@ module.exports = function launch (t) { console.log('stopping app to test consecutive run') await app.stop() - await new Promise((resolve, reject) => { - let child = spawn(binary, [ - 'client', 'keys', 'recover', 'testkey', - '--home', join(home, 'baseserver') - ]) - child.stdin.write('1234567890\n') - child.stdin.write('chair govern physical divorce tape movie slam field gloom process pen universe allow pyramid private ability\n') - child.stderr.pipe(process.stdout) - child.once('exit', (code) => { - if (code === 0) resolve() - reject() - }) - }) - console.log('restored test account') + await createAccount('testkey', 'chair govern physical divorce tape movie slam field gloom process pen universe allow pyramid private ability') + await createAccount('testreceiver', 'crash ten rug mosquito cart south allow pluck shine island broom deputy hungry photo drift absorb') + console.log('restored test accounts') await startApp(app) t.ok(app.isRunning(), 'app is running') - await login(app) + await login(app.client) resolve({app, home}) }) @@ -95,12 +84,6 @@ function printAppLog (app) { }) } -async function login (app) { - await app.client.$('#sign-in-password').setValue('1234567890') - await app.client.$('.ni-session-footer button').click() - await app.client.waitForExist('#app-content', 5000) -} - async function startApp (app) { await app.start() @@ -145,4 +128,20 @@ async function startLocalNode () { }) }) console.log('started local node') +} + +async function createAccount (name, seed) { + await new Promise((resolve, reject) => { + let child = spawn(binary, [ + 'client', 'keys', 'recover', name, + '--home', join(home, 'baseserver') + ]) + child.stdin.write('1234567890\n') + child.stdin.write(seed + '\n') + child.stderr.pipe(process.stdout) + child.once('exit', (code) => { + if (code === 0) resolve() + reject() + }) + }) } \ No newline at end of file diff --git a/test/e2e/wallet.js b/test/e2e/wallet.js index e8ee15fd23..785c7ec7dd 100644 --- a/test/e2e/wallet.js +++ b/test/e2e/wallet.js @@ -1,7 +1,7 @@ let { spawn } = require('child_process') let test = require('tape-promise/tape') let launchApp = require('./launch.js') -let { navigate, newTempDir, waitForText, sleep } = require('./common.js') +let { navigate, newTempDir, waitForText, sleep, login, logout } = require('./common.js') let binary = process.env.BINARY_PATH @@ -30,40 +30,6 @@ test('wallet', async function (t) { .$('..') .$('div.ni-li-dd') - // t.test('receive', async function (t) { - // await navigate(t, client, 'Balances') - - // let address - // t.test('address', async function (t) { - // let addressEl = $('//div[contains(text(), "Your Address")]').$('..').$('..').$('..').$('.ni-li-copy .value') - // address = await addressEl.getText() - // t.ok(address, `address: ${address}`) - // t.equal(address.length, 40, 'address is correct length') - // t.end() - // }) - - // t.test('fermion balance before receiving', async function (t) { - // let mycoinEl = balanceEl('fermion') - // let balance = await mycoinEl.getText() - // t.equal(balance, '9007199254740992', 'fermion balance is greater 0') - // t.end() - // }) - - // t.test('receive mycoin', async function (t) { - // await cliSendCoins(home, address, '1000mycoin') - // t.end() - // }) - - // t.test('mycoin balance after receiving', async function (t) { - // let mycoinEl = () => balanceEl('mycoin') - // await waitForText(mycoinEl, '1000', 8000) - // t.pass('received mycoin transaction') - // t.end() - // }) - - // t.end() - // }) - t.test('send', async function (t) { async function goToSendPage () { await navigate(t, client, 'Balances') @@ -147,5 +113,20 @@ test('wallet', async function (t) { t.end() }) + t.test('receive', async function (t) { + t.test('fermion balance after receiving', async function (t) { + await logout(client) + await login(client, 'testreceiver') + await navigate(t, client, 'Balances') + + let fermionEl = () => balanceEl('fermion') + await waitForText(fermionEl, '100', 5000) + t.pass('received mycoin transaction') + t.end() + }) + + t.end() + }) + t.end() }) From 9a1385dd5a2e74faeb22009f60f13b5954f16daf Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 9 Feb 2018 19:49:46 +0000 Subject: [PATCH 10/14] fixed logging in --- test/e2e/common.js | 22 +++++++--------------- test/e2e/launch.js | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/test/e2e/common.js b/test/e2e/common.js index 2590685936..1c024810b0 100644 --- a/test/e2e/common.js +++ b/test/e2e/common.js @@ -44,8 +44,12 @@ module.exports = { await client.$('.ni-session-footer button').click() await client.waitForExist('#app-content', 5000) - // let address = await client.$('.ni-li-copy .value').getText() - // TODO check if correct account logged in + // checking if user is logged in + await module.exports.openMenu(client) + let activeUser = await client.$('.ni-li-user .ni-li-title').getText() + if (account !== activeUser) { + throw new Error('Incorrect user logged in') + } }, async logout (client) { console.log('logging out') @@ -56,19 +60,7 @@ module.exports = { } } -// only sending keyboard arrows worked for selecting options async function selectOption (client, selectSelector, text) { - // go up to the first option await client.$(selectSelector).click() - await client.keys(['\uE013', '\uE013', '\uE013', '\uE013', '\uE013', '\uE013']) // TODO calc options length - // then go down until we have the option we want - let found = false - while (!found) { - let value = (await client.$(selectSelector).getValue()).trim() - found = text === value - if (!found) { - await client.$(selectSelector).click() - await client.keys(['\uE015']) - } - } + await client.keys(text.split()) } diff --git a/test/e2e/launch.js b/test/e2e/launch.js index 582e3de1c9..519a90009e 100644 --- a/test/e2e/launch.js +++ b/test/e2e/launch.js @@ -58,7 +58,7 @@ module.exports = function launch (t) { await startApp(app) t.ok(app.isRunning(), 'app is running') - await login(app.client) + await login(app.client, 'testkey') resolve({app, home}) }) From 6c6b8be02caabd5ca7a53b096532050b45981986 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 9 Feb 2018 21:15:13 +0000 Subject: [PATCH 11/14] refactoring --- test/e2e/common.js | 7 +++++-- test/e2e/wallet.js | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/test/e2e/common.js b/test/e2e/common.js index 1c024810b0..80a49512c3 100644 --- a/test/e2e/common.js +++ b/test/e2e/common.js @@ -7,14 +7,17 @@ function sleep (ms) { module.exports = { async openMenu (client) { + if (await client.isExisting('.app-menu')) { + return + } // close notifications as they overlay the menu button while (await client.isExisting(`.ni-notification`)) { await client.$(`.ni-notification`).click() } await client.$('#app-menu-button').click() - await client.$('.app-menu').isVisible() + await client.waitForExist('.app-menu', 1000) }, - async navigate (t, client, linkText, titleText = linkText) { + async navigate (client, linkText, titleText = linkText) { await module.exports.openMenu(client) // click link await client.$(`a*=${linkText}`).click() diff --git a/test/e2e/wallet.js b/test/e2e/wallet.js index 785c7ec7dd..86fae0912b 100644 --- a/test/e2e/wallet.js +++ b/test/e2e/wallet.js @@ -32,11 +32,11 @@ test('wallet', async function (t) { t.test('send', async function (t) { async function goToSendPage () { - await navigate(t, client, 'Balances') + await navigate(client, 'Balances') await $('.ni-li-dt=FERMION').$('..').$('..').click() } - await navigate(t, client, 'Balances') + await navigate(client, 'Balances') let sendBtn = () => $('.ni-form-footer button') let addressInput = () => $('#send-address') @@ -98,7 +98,7 @@ test('wallet', async function (t) { }) t.test('own balance updated', async function (t) { - await navigate(t, client, 'Balances') + await navigate(client, 'Balances') // TODO should not be necessary await sleep(1000) @@ -117,7 +117,7 @@ test('wallet', async function (t) { t.test('fermion balance after receiving', async function (t) { await logout(client) await login(client, 'testreceiver') - await navigate(t, client, 'Balances') + await navigate(client, 'Balances') let fermionEl = () => balanceEl('fermion') await waitForText(fermionEl, '100', 5000) From 7c8abf3e680e5f3d9e3f08e57cae5b272ddc6c16 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 9 Feb 2018 21:15:56 +0000 Subject: [PATCH 12/14] tests for create account and seed import --- test/e2e/signin.js | 151 +++++++++++++++++++++++++++++++++------------ 1 file changed, 111 insertions(+), 40 deletions(-) diff --git a/test/e2e/signin.js b/test/e2e/signin.js index 933480d0ad..bb72b764f3 100644 --- a/test/e2e/signin.js +++ b/test/e2e/signin.js @@ -1,66 +1,137 @@ let test = require('tape-promise/tape') let launchApp = require('./launch.js') -let { navigate } = require('./common.js') +let { navigate, logout, openMenu } = require('./common.js') test('sign in', async function (t) { - let app, client + let {app, home} = await launchApp(t) + let client = app.client let el = (...args) => client.$(...args) + let continueButton = () => el('.ni-btn__value=Next').$('..') + + t.test('agreement', async function (t) { + await logout(client) + // go to login selection + await client.$('i=arrow_back').$('..').click() + await client.waitForExist('.ni-li-session', 1000) + // go to new account + await client.$('.ni-li-session-title=Create new account').$('..').$('..').click() - app = await launchApp(t) - console.log('app launched') - client = app.client + let accountName = () => el('#sign-up-name') + let password = () => el('#sign-in-password') + let warning = () => el('#sign-up-warning') + let backedup = () => el('#sign-up-backup') - navigate(t, client, 'Sign In', 'Welcome to Cosmos') + t.test('did check warning', async function (t) { + await continueButton().click() + t.ok(await warning().$('..').$('..').$('..').isExisting('.ni-form-msg--error'), 'shows error') + await warning().click() + t.ok(!(await warning().$('..').$('..').$('..').isExisting('.ni-form-msg--error')), 'hides error') + t.end() + }) - t.test('agreement', async function (t) { - let input = 'input[placeholder="Enter here"]' - let continueButton = 'button=Continue' - let errorText = 'div*=Agreement must match' - - t.test('input incorrect agreement text', async function (t) { - await el(input).setValue('lol i don\'t understand the risks') - await el(continueButton).click() - await client.waitForVisible(errorText) - t.pass('error text is shown') + t.test('did check backup note', async function (t) { + await continueButton().click() + t.ok(await backedup().$('..').$('..').$('..').isExisting('.ni-form-msg--error'), 'shows error') + await backedup().click() + t.ok(!(await backedup().$('..').$('..').$('..').isExisting('.ni-form-msg--error')), 'hides error') t.end() }) - t.test('input correct agreement text', async function (t) { - await el(input).setValue('I understand the risks') - await el(continueButton).click() - try { - await el(errorText).isVisible() - t.fail('error text should not exist') - } catch (e) { - t.pass('no error text') - } + t.test('set account name', async function (t) { + await continueButton().click() + t.ok(await accountName().$('..').isExisting('.ni-form-msg--error'), 'shows error') + await accountName().click() + await client.keys('sign'.split()) + t.ok(await accountName().$('..').isExisting('.ni-form-msg--error'), 'shows error for too few letters') + await accountName().click() + await client.keys('in_test'.split()) + t.ok(!(await accountName().$('..').isExisting('.ni-form-msg--error')), 'hides error') t.end() }) + + t.test('set password', async function (t) { + await continueButton().click() + t.ok(await password().$('..').isExisting('.ni-form-msg--error'), 'shows error') + await password().click() + await client.keys('1234'.split()) + t.ok(await password().$('..').isExisting('.ni-form-msg--error'), 'shows error for too few letters') + await password().click() + await client.keys('567890'.split()) + t.ok(!(await password().$('..').isExisting('.ni-form-msg--error')), 'hides error') + t.end() + }) + + t.test('logs in', async function (t) { + await continueButton().click() + + // checking if user is logged in + await client.waitForExist('#app-content', 5000) + await openMenu(client) + let activeUser = await client.$('.ni-li-user .ni-li-title').getText() + t.ok('signin_test' === activeUser, 'user is logged in') + + t.end() + }) t.end() }) t.test('seed', async function (t) { - let input = 'input[placeholder="Input seed..."]' - let signInButton = 'button=Sign In' - - // TODO (after seed validation implemented) - t.skip('input incorrect seed text', async function (t) { - await el(input).setValue('seed123') - await el(signInButton).click() - let errorText = 'div*=TODO: add error message' - t.ok(await el(errorText).isVisible(), 'error is shown') + await logout(client) + // go to login selection + await client.$('i=arrow_back').$('..').click() + await client.waitForExist('.ni-li-session', 1000) + // go to import with seed + await client.$('.ni-li-session-title=Import with seed').$('..').$('..').click() + + let accountName = () => el('#import-name') + let password = () => el('#import-password') + let seed = () => el('#import-seed') + + t.test('set account name', async function (t) { + await continueButton().click() + t.ok(await accountName().$('..').isExisting('.ni-form-msg--error'), 'shows error') + await accountName().click() + await client.keys('seed'.split()) + t.ok(await accountName().$('..').isExisting('.ni-form-msg--error'), 'shows error for too few letters') + await accountName().click() + await client.keys('_test'.split()) + t.ok(!(await accountName().$('..').isExisting('.ni-form-msg--error')), 'hides error') + t.end() + }) + + t.test('set password', async function (t) { + await continueButton().click() + t.ok(await password().$('..').isExisting('.ni-form-msg--error'), 'shows error') + await password().click() + await client.keys('1234'.split()) + t.ok(await password().$('..').isExisting('.ni-form-msg--error'), 'shows error for too few letters') + await password().click() + await client.keys('567890'.split()) + t.ok(!(await password().$('..').isExisting('.ni-form-msg--error')), 'hides error') t.end() }) t.test('input correct seed text', async function (t) { - await el(input).setValue('TODO: put valid seed here') - await el(signInButton).click() - await client.waitUntilTextExists( - '.ni-page-header-title', - 'Balances') - t.pass('navigated') + await continueButton().click() + t.ok(await seed().$('..').isExisting('.ni-form-msg--error'), 'shows error') + await seed().click() + await client.keys('crash ten rug mosquito cart south allow pluck shine island broom deputy hungry photo drift absorb'.split()) + t.ok(!(await seed().$('..').isExisting('.ni-form-msg--error')), 'hides error') t.end() }) + + t.test('logs in', async function (t) { + await continueButton().click() + + // checking if user is logged in + await client.waitForExist('#app-content', 5000) + await openMenu(client) + let activeUser = await client.$('.ni-li-user .ni-li-title').getText() + t.ok('seed_test' === activeUser, 'user is logged in') + + t.end() + }) + t.end() }) t.end() From 98edf4e9d58a9edf61fc966b6b9d47ec11b2bc74 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 9 Feb 2018 21:21:21 +0000 Subject: [PATCH 13/14] fixed login issue --- package.json | 2 +- test/e2e/wallet.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e5d84a574..30ef08e690 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "pack:renderer": "cross-env NODE_ENV=production webpack --colors --config webpack.renderer.config.js", "test": "npm run lint && npm run test:unit", "test:unit": "cross-env LOGGING=false MOCK=false jest --maxWorkers=2", - "test:e2e": "tape \"test/e2e/!(main)*.js\"", + "test:e2e": "tape \"test/e2e/*.js\"", "test:exe": "node tasks/test-build.js", "vue:route": "node tasks/vue/route.js", "vuex:module": "node tasks/vuex/module.js" diff --git a/test/e2e/wallet.js b/test/e2e/wallet.js index 86fae0912b..995bbc3afb 100644 --- a/test/e2e/wallet.js +++ b/test/e2e/wallet.js @@ -25,6 +25,9 @@ test('wallet', async function (t) { let client = app.client let $ = (...args) => client.$(...args) + await logout(client) + await login(client, 'testkey') + let balanceEl = (denom) => $(`//div[contains(text(), "${denom.toUpperCase()}")]`) .$('..') From c98efed3bb9a9f9b954f6c864ae25adc1350739f Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 9 Feb 2018 21:35:04 +0000 Subject: [PATCH 14/14] fixing tests not exiting --- test/e2e/launch.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/e2e/launch.js b/test/e2e/launch.js index 519a90009e..91de194d57 100644 --- a/test/e2e/launch.js +++ b/test/e2e/launch.js @@ -68,6 +68,12 @@ module.exports = function launch (t) { } test.onFinish(() => app ? app.stop() : null) +test.onFinish(async () => { + console.log('DONE: cleaning up') + await app ? app.stop() : null + // tape doesn't finish properly because of open processes like gaia + process.exit(0) +}) function printAppLog (app) { app.client.getMainProcessLogs().then(function (logs) {