From 169e7114fa5f04d5c669bce5ed4e5da3b6d8a4ec Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 29 Jan 2018 09:49:09 -0800 Subject: [PATCH 1/5] Download network's gaia version in testnet script --- tasks/testnet.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/testnet.js b/tasks/testnet.js index 8b05685fcd..832fc9d67e 100644 --- a/tasks/testnet.js +++ b/tasks/testnet.js @@ -31,10 +31,15 @@ async function main () { .catch(e => { throw new Error(`Can't load config.toml: ${e.message}`) }) + let gaiaVersionTxt = await get(`https://github.com/tendermint/testnets/raw/master/${network}/gaia/gaiaversion.txt`) + .catch(e => { + throw new Error(`Can't load config.toml: ${e.message}`) + }) let path = join(tmpdir(), Math.random().toString(36).slice(2)) mkdirp(path) write(join(path, 'genesis.json'), genesisJson) write(join(path, 'config.toml'), configToml) + write(join(path, 'gaiaversion.txt'), gaiaVersionTxt) runDev(path) } } From 17d8474f0694f6177d2c50083bb54af59d340078 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 29 Jan 2018 09:49:41 -0800 Subject: [PATCH 2/5] Ensure gaia version matches expected network version --- app/src/main/index.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/index.js b/app/src/main/index.js index 8480dcd3f1..e170f88828 100644 --- a/app/src/main/index.js +++ b/app/src/main/index.js @@ -222,6 +222,12 @@ async function startBaseserver (home, nodeIP) { return child } +async function getGaiaVersion () { + let child = startProcess(SERVER_BINARY, ['version']) + let data = await event(child.stdout, 'data') + return data.toString('utf8').trim() +} + function exists (path) { try { fs.accessSync(path) @@ -323,8 +329,11 @@ if (!TEST) { }) } -function consistentConfigDir (versionPath, genesisPath, configPath) { - return exists(genesisPath) && exists(versionPath) && exists(configPath) +function consistentConfigDir (appVersionPath, genesisPath, configPath, gaiaVersionPath) { + return exists(genesisPath) && + exists(appVersionPath) && + exists(configPath) && + exists(gaiaVersionPath) } function pickNode (seeds) { @@ -374,9 +383,10 @@ async function main () { return } - let versionPath = join(root, 'app_version') + let appVersionPath = join(root, 'app_version') let genesisPath = join(root, 'genesis.json') let configPath = join(root, 'config.toml') + let gaiaVersionPath = join(root, 'gaiaversion.txt') let rootExists = exists(root) await fs.ensureDir(root) @@ -389,8 +399,8 @@ async function main () { // check if the existing data came from a compatible app version // if not, backup the data and re-initialize - if (consistentConfigDir(versionPath, genesisPath, configPath)) { - let existingVersion = fs.readFileSync(versionPath, 'utf8') + if (consistentConfigDir(appVersionPath, genesisPath, configPath, gaiaVersionPath)) { + let existingVersion = fs.readFileSync(appVersionPath, 'utf8') let compatible = semver.diff(existingVersion, pkg.version) !== 'major' if (compatible) { log('configs are compatible with current app version') @@ -427,13 +437,23 @@ async function main () { fs.accessSync(networkPath) // crash if invalid path fs.copySync(networkPath, root) - fs.writeFileSync(versionPath, pkg.version) + fs.writeFileSync(appVersionPath, pkg.version) } log('starting app') log(`dev mode: ${DEV}`) log(`winURL: ${winURL}`) + + let gaiaVersion = await getGaiaVersion() + let expectedGaiaVersion = fs.readFileSync(gaiaVersionPath, 'utf8').trim() + log(`gaia version: "${gaiaVersion}", expected: "${expectedGaiaVersion}"`) + // TODO: semver check, or exact match? + if (gaiaVersion !== expectedGaiaVersion) { + throw Error(`Requires gaia ${expectedGaiaVersion}, but got ${gaiaVersion}. + Please update your gaia installation or build with a newer binary.`) + } + // read chainId from genesis.json let genesisText = fs.readFileSync(genesisPath, 'utf8') let genesis = JSON.parse(genesisText) From d834417961077a00ce40302f57c932f848935ec0 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 29 Jan 2018 10:20:35 -0800 Subject: [PATCH 3/5] Fix gaia version check in tests --- app/src/main/index.js | 5 +++-- test/unit/specs/main.spec.js | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/index.js b/app/src/main/index.js index e170f88828..7ac59622ab 100644 --- a/app/src/main/index.js +++ b/app/src/main/index.js @@ -224,7 +224,9 @@ async function startBaseserver (home, nodeIP) { async function getGaiaVersion () { let child = startProcess(SERVER_BINARY, ['version']) - let data = await event(child.stdout, 'data') + let data = await new Promise((resolve) => { + child.stdout.on('data', resolve) + }) return data.toString('utf8').trim() } @@ -444,7 +446,6 @@ async function main () { log(`dev mode: ${DEV}`) log(`winURL: ${winURL}`) - let gaiaVersion = await getGaiaVersion() let expectedGaiaVersion = fs.readFileSync(gaiaVersionPath, 'utf8').trim() log(`gaia version: "${gaiaVersion}", expected: "${expectedGaiaVersion}"`) diff --git a/test/unit/specs/main.spec.js b/test/unit/specs/main.spec.js index f8bddd4791..66853269b0 100644 --- a/test/unit/specs/main.spec.js +++ b/test/unit/specs/main.spec.js @@ -10,6 +10,7 @@ jest.mock('fs-extra', () => { let mockFs = mockFsExtra() mockFs.writeFile('./app/networks/gaia-2/config.toml', fs.readFileSync('./app/networks/gaia-2/config.toml', 'utf8')) mockFs.writeFile('./app/networks/gaia-2/genesis.json', fs.readFileSync('./app/networks/gaia-2/genesis.json', 'utf8')) + mockFs.writeFile('./app/networks/gaia-2/gaiaversion.txt', fs.readFileSync('./app/networks/gaia-2/gaiaversion.txt', 'utf8')) return mockFs }) let fs = require('fs-extra') From 9120a37f02d0ecbd2d73cf8bc101c8e4dfb101a5 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 30 Jan 2018 11:30:15 +0100 Subject: [PATCH 4/5] added mock for version command in child_process mock --- test/unit/specs/main.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/specs/main.spec.js b/test/unit/specs/main.spec.js index 66853269b0..3e9e32f8e0 100644 --- a/test/unit/specs/main.spec.js +++ b/test/unit/specs/main.spec.js @@ -28,6 +28,13 @@ childProcessMock((path, args) => ({ if (type === 'exit' && args[1] === 'init') { cb(0) } + }, + stdout: { + on: (type, cb) => { + if (args[0] === 'version' && type === 'data') { + cb({toString: () => 'v0.5.0'}) + } + } } })) @@ -430,6 +437,13 @@ function failingChildProcess (mockName, mockCmd) { cb(0) } } + }, + stdout: { + on: (type, cb) => { + if (args[0] === 'version' && type === 'data') { + cb({toString: () => 'v0.5.0'}) + } + } } })) } From 5d5a3c7a7e2fbd491200b30f54b49af4df226118 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 30 Jan 2018 07:31:11 -0800 Subject: [PATCH 5/5] Added changelog message --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d22ee2f6..9954fedbfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a changelog @jolesbi. ## [0.3.1] - 2018-01-30 +### +* Check to ensure gaia version is correct for the current network @mappum + ### Changed * Improved performance of amountBonded in LiDelegate.vue @nylira. * Prevented user from going to PageBond if they don't have any atoms/fermions @nylira.