Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
[Master] Allow upgrade from 0.19.x (#4612)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Kelsey <[email protected]>
  • Loading branch information
Dave Kelsey authored Mar 7, 2019
1 parent a7b8ed3 commit ac291c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
7 changes: 0 additions & 7 deletions packages/composer-runtime/lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'use strict';

const Logger = require('composer-common').Logger;
const semver = require('semver');
const util = require('util');

const LOG = Logger.getLog('Engine');
Expand Down Expand Up @@ -208,12 +207,6 @@ class Engine {
LOG.debug(method, 'Updating metanetwork in $sysdata collection');

const newRuntimeVersion = this.container.getVersion();
// Check our new version should be greater than or equal but only a micro version change.
const range = `^${metanetwork.runtimeVersion}`;
if (!semver.satisfies(newRuntimeVersion, range)) {
throw new Error(`Cannot upgrade business network. New composer runtime version of (${newRuntimeVersion}) is not compatible with (${metanetwork.runtimeVersion}). Composer runtime has changed major or minor version and cannot be upgraded.`);
}

try {
// update the metanetwork with new identifier and version
const networkId = context.getBusinessNetworkDefinition().getIdentifier();
Expand Down
1 change: 0 additions & 1 deletion packages/composer-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"fast-json-patch": "1.1.8",
"request": "2.81.0",
"request-promise-any": "1.0.5",
"semver": "5.3.0",
"sha.js": "2.4.8",
"source-map": "0.5.6",
"uuid": "3.0.1"
Expand Down
20 changes: 12 additions & 8 deletions packages/composer-runtime/test/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,21 @@ describe('Engine', () => {
sinon.assert.calledOnce(mockContext.transactionEnd);
});

it('should throw error if upgrade not allowed', async () => {
it('should NOT throw error if upgrading from a much older version', async () => {
const sysdata = sinon.createStubInstance(DataCollection);
mockContainer.getVersion.returns('0.21.0');
await engine.upgrade(mockContext, '', sysdata, {runtimeVersion:'0.20.0'});
sinon.assert.calledOnce(sysdata.update);
sinon.assert.calledWith(sysdata.update, 'metanetwork', {
'$class': 'org.hyperledger.composer.system.Network',
'networkId': '[email protected]',
'runtimeVersion': '0.21.0'
});
sinon.assert.calledOnce(mockRegistryManager.createDefaults);
sinon.assert.calledOnce(mockContext.transactionPrepare);
sinon.assert.calledOnce(mockContext.transactionCommit);
sinon.assert.calledOnce(mockContext.transactionEnd);

try {
await engine.upgrade(mockContext, '', sysdata, {runtimeVersion:'0.20.0'});
should.fail('Expected error to be thrown');
} catch(err) {
err.message.should.match(/Cannot upgrade/);
sinon.assert.notCalled(sysdata.update);
}
});

it('should rollback if sysdata update fails', async () => {
Expand Down

0 comments on commit ac291c6

Please sign in to comment.