From d037d04e011a39efb880dfd25c615da3429f25bc Mon Sep 17 00:00:00 2001 From: Arnaud97234 Date: Wed, 19 Sep 2018 15:31:29 +0200 Subject: [PATCH] Update sync test --- .gitignore | 2 + package.json | 1 + test-e2e/README.md | 15 +++++ ...sCheck.spec.js => enable-dev-mode.spec.js} | 4 +- .../{helpers/test_helpers.js => helpers.js} | 0 test-e2e/sync/.DS_Store | Bin 0 -> 10244 bytes test-e2e/sync/data/.DS_Store | Bin 0 -> 6148 bytes test-e2e/sync/data/empty-app.json | 1 + test-e2e/sync/data/expected-app.json | 1 + test-e2e/sync/launch.sh | 49 ++++++++++++++++ test-e2e/sync/sync-accounts.js | 53 ++++++++++++++++++ test-e2e/sync/wait-sync.js | 48 ++++++++++++++++ 12 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 test-e2e/README.md rename test-e2e/{skipOnboarding_GeneralSettingsCheck.spec.js => enable-dev-mode.spec.js} (96%) rename test-e2e/{helpers/test_helpers.js => helpers.js} (100%) create mode 100644 test-e2e/sync/.DS_Store create mode 100644 test-e2e/sync/data/.DS_Store create mode 100644 test-e2e/sync/data/empty-app.json create mode 100644 test-e2e/sync/data/expected-app.json create mode 100644 test-e2e/sync/launch.sh create mode 100644 test-e2e/sync/sync-accounts.js create mode 100644 test-e2e/sync/wait-sync.js diff --git a/.gitignore b/.gitignore index 40e58245..c76923df 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ /build/linux/arch/src /build/linux/arch/*.tar.gz /build/linux/arch/*.tar.xz + +/test-e2e/sync/data/actual_app.json diff --git a/package.json b/package.json index a617fc23..942552b7 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "flow": "flow", "test": "jest src", "test-e2e": "jest test-e2e", + "test-sync": "bash test-e2e/sync/launch.sh", "prettier": "prettier --write \"{src,webpack,.storybook,test-e2e}/**/*.{js,json}\"", "ci": "yarn lint && yarn flow && yarn prettier && yarn test", "storybook": "NODE_ENV=development STORYBOOK_ENV=1 start-storybook -s ./static -p 4444", diff --git a/test-e2e/README.md b/test-e2e/README.md new file mode 100644 index 00000000..bd772167 --- /dev/null +++ b/test-e2e/README.md @@ -0,0 +1,15 @@ +# ledgerLive-QA +Automated tests for Ledger Live Desktop application. +Start Ledger Live Desktop application with accounts for the supported coin. Operations history removed from db. Then sync to retrieve account balance and transactions history. + + +## Accounts setup and sync +#### Launch test +yarn test-sync + +#### Test description +Clean Ledger Live Application settings directory. +Copy app.json init file for testing in a new Ledger Live Application settings directory. +Start Ledger Live Desktop app. +Wait for sync OK. +Compare new app.json with expected app.json file. diff --git a/test-e2e/skipOnboarding_GeneralSettingsCheck.spec.js b/test-e2e/enable-dev-mode.spec.js similarity index 96% rename from test-e2e/skipOnboarding_GeneralSettingsCheck.spec.js rename to test-e2e/enable-dev-mode.spec.js index b55b1657..bff4bebb 100644 --- a/test-e2e/skipOnboarding_GeneralSettingsCheck.spec.js +++ b/test-e2e/enable-dev-mode.spec.js @@ -1,6 +1,6 @@ import { Application } from 'spectron' -import { waitForDisappear, waitForExpectedText } from '../test-e2e/helpers/test_helpers' +import { waitForDisappear, waitForExpectedText } from './helpers' const os = require('os') const appVersion = require('../package.json') @@ -14,7 +14,7 @@ const platform = os.platform() if (platform === 'darwin') { app_path = `./dist/mac/Ledger Live.app/Contents/MacOS/Ledger Live` } else if (platform === 'win32') { - app_path = `./dist\\win-unpacked\\Ledger Live.exe` + app_path = `.\\dist\\win-unpacked\\Ledger Live.exe` } else { app_path = `./dist/ledger-live-desktop-${appVersion.version}-linux-x86_64.AppImage` } diff --git a/test-e2e/helpers/test_helpers.js b/test-e2e/helpers.js similarity index 100% rename from test-e2e/helpers/test_helpers.js rename to test-e2e/helpers.js diff --git a/test-e2e/sync/.DS_Store b/test-e2e/sync/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c0805d2daa7f89b3d394d5b1cc431fdba5a0eca9 GIT binary patch literal 10244 zcmeHMO>h)N6n-xRGF=cdK}a&d!b*x?7g&Bnl%GvD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1vj@7m0!w@FG$0b-aXc;oFj0(}e3PQ%y>|LUNjL#Z2CF zeeX22ae~%BK(9_792ld>5d2poLxr2CtRR=A5OyB~ROnElV^)Wb3M#7rq5=s2-SV&l zNCoXG!ibDCDpv?71ZEuqbL5KR{QiIcga7}Zb?a6OQV1vn{y7A&x+BxkPUDqtCMt*K zckOX{hUwvn_nVYbm{4}t9|2V1*YV literal 0 HcmV?d00001 diff --git a/test-e2e/sync/data/.DS_Store b/test-e2e/sync/data/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 { + const aHash = getOpHash(a) + const bHash = getOpHash(b) + if (aHash < bHash) return -1 + if (aHash > bHash) return 1 + return 0 +} + +describe('sync accounts', () => { + test('should give the same app.json', () => { + const expected = getSanitized('./data/expected-app.json') + const actual = getSanitized('./data/actual-app.json') + expect(actual).toEqual(expected) + }) +}) + +function getSanitized(filePath) { + const data = require(`${filePath}`) // eslint-disable-line import/no-dynamic-require + return data.data.accounts + .map(a => a.data) + .map(a => pick(a, ACCOUNTS_FIELDS)) + .map(a => { + a.operations.sort(ALPHA_SORT) + return { + ...a, + operations: a.operations.map(o => pick(o, OPS_FIELDS)), + } + }) +} + +function getOpHash(op) { + return `${op.accountId}--${op.hash}--${op.type}` +} diff --git a/test-e2e/sync/wait-sync.js b/test-e2e/sync/wait-sync.js new file mode 100644 index 00000000..79b588af --- /dev/null +++ b/test-e2e/sync/wait-sync.js @@ -0,0 +1,48 @@ +/* eslint-disable no-console */ + +const electron = require('electron') +const fs = require('fs') +const path = require('path') +const moment = require('moment') + +const delay = ms => new Promise(f => setTimeout(f, ms)) + +const MIN_TIME_DIFF = 1 * 1000 * 90 // 1.5 minute +const PING_INTERVAL = 1 * 1000 // 1 seconds + +async function waitForSync() { + let MAX_RETRIES = 100 + const userDataDirectory = electron.app.getPath('userData') + const tmpAppJSONPath = path.resolve(userDataDirectory, 'app.json') + const appJSONPath = tmpAppJSONPath.replace('/Electron/', '/Ledger Live/') + + function check() { + const appJSONContent = fs.readFileSync(appJSONPath, 'utf-8') + const appJSONParsed = JSON.parse(appJSONContent) + const mapped = appJSONParsed.data.accounts.map(a => ({ + name: a.data.name, + lastSyncDate: a.data.lastSyncDate, + })) + const now = Date.now() + const areAllSync = mapped.every(account => { + const diff = now - new Date(account.lastSyncDate).getTime() + if (diff <= MIN_TIME_DIFF) return true + console.log(`[${account.name}] synced ${moment(account.lastSyncDate).fromNow()} (${moment(account.lastSyncDate).format('YYYY-MM-DD HH:mm:ss')})`) + return false + }) + return areAllSync + } + + while (!check()) { + MAX_RETRIES-- + if (!MAX_RETRIES) { + console.log(`x Too much retries. Exitting.`) + process.exit(1) + } + await delay(PING_INTERVAL) + } + + process.exit(0) +} + +waitForSync()