Browse Source

Update sync test

gre-patch-1
Arnaud97234 6 years ago
parent
commit
d037d04e01
No known key found for this signature in database GPG Key ID: C77229DB9ECCFE6
  1. 2
      .gitignore
  2. 1
      package.json
  3. 15
      test-e2e/README.md
  4. 4
      test-e2e/enable-dev-mode.spec.js
  5. 0
      test-e2e/helpers.js
  6. BIN
      test-e2e/sync/.DS_Store
  7. BIN
      test-e2e/sync/data/.DS_Store
  8. 1
      test-e2e/sync/data/empty-app.json
  9. 1
      test-e2e/sync/data/expected-app.json
  10. 49
      test-e2e/sync/launch.sh
  11. 53
      test-e2e/sync/sync-accounts.js
  12. 48
      test-e2e/sync/wait-sync.js

2
.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

1
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",

15
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.

4
test-e2e/skipOnboarding_GeneralSettingsCheck.spec.js → 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`
}

0
test-e2e/helpers/test_helpers.js → test-e2e/helpers.js

BIN
test-e2e/sync/.DS_Store

Binary file not shown.

BIN
test-e2e/sync/data/.DS_Store

Binary file not shown.

1
test-e2e/sync/data/empty-app.json

File diff suppressed because one or more lines are too long

1
test-e2e/sync/data/expected-app.json

File diff suppressed because one or more lines are too long

49
test-e2e/sync/launch.sh

@ -0,0 +1,49 @@
#!/bin/bash
# get app version
ledgerLiveVersion=$(grep version package.json | cut -d : -f 2 | sed -E 's/.*"([^"]*)".*/\1/g')
# OS settings
if [[ $(uname) == 'Darwin' ]]; then \
settingsPath=~/Library/Application\ Support/Ledger\ Live/
appPath="/Applications/Ledger Live.app/Contents/MacOS/Ledger Live"
elif [[ $(uname) == 'Linux' ]]; then \
settingsPath="$HOME/.config/Ledger Live"
appPath="$HOME/apps/ledger-live-desktop-$ledgerLiveVersion-linux-x86_64.AppImage"
else \
settingsPath="%AppData\\Roaming\\Ledger Live"
appPath="C:\\Program Files\\Ledger Live\\Ledger Live.exe"
fi
# clean Ledger Live Application settings directory
rm -rf "$settingsPath"
mkdir "$settingsPath"
# rm ../data/actual_app.json
# Copy app.json init file for testing
cp test-e2e/sync/data/empty-app.json "$settingsPath/app.json"
# Start Ledger Live Desktop app
"$appPath" &
lastPid=$!
# wait for sync
electron ./test-e2e/sync/wait-sync.js
returnCode=$?
# kill Ledger Live Desktop process
kill -9 $lastPid
if [[ $returnCode = 0 ]]; then
echo "[OK] Sync finished"
else
echo "[x] Sync failed"
exit 1
fi
# Copy app.json file to test folder
cp "$settingsPath"/app.json test-e2e/sync/data/actual-app.json
# compare new app.json with expected_app.json
./node_modules/.bin/jest test-e2e/sync/sync-accounts.js

53
test-e2e/sync/sync-accounts.js

@ -0,0 +1,53 @@
const pick = require('lodash/pick')
const ACCOUNTS_FIELDS = [
'archived',
'freshAddress',
'freshAddressPath',
'id',
'index',
'isSegwit',
'name',
'path',
'xpub',
'operations',
'currencyId',
'unitMagnitude',
'balance',
]
const OPS_FIELDS = ['id', 'hash', 'accountId', 'type', 'senders', 'recipients', 'value', 'fee']
const ALPHA_SORT = (a, b) => {
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}`
}

48
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()
Loading…
Cancel
Save