Skip to content

Commit

Permalink
Upgrade to Hyperledger Fabric v1.1-rc1 (hyperledger-archives#3517)
Browse files Browse the repository at this point in the history
* Upgrade to Hyperledger Fabric v1.1-rc1

Signed-off-by: Simon Stone <[email protected]>

* Cope with new database layout (one per chaincode, not one per channel)

Signed-off-by: Simon Stone <[email protected]>
  • Loading branch information
Simon Stone authored and nklincoln committed Mar 2, 2018
1 parent ee24262 commit 80fce09
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 105 deletions.
14 changes: 7 additions & 7 deletions packages/composer-playground/e2e/fabric/hlfv1/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'

services:
ca.org1.example.com:
image: hyperledger/fabric-ca:$ARCH-1.1.0-alpha
image: hyperledger/fabric-ca:$ARCH-1.1.0-rc1
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.org1.example.com
Expand All @@ -14,7 +14,7 @@ services:
container_name: ca.org1.example.com

ca.org2.example.com:
image: hyperledger/fabric-ca:$ARCH-1.1.0-alpha
image: hyperledger/fabric-ca:$ARCH-1.1.0-rc1
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.org2.example.com
Expand All @@ -27,7 +27,7 @@ services:

orderer.example.com:
container_name: orderer.example.com
image: hyperledger/fabric-orderer:$ARCH-1.1.0-alpha
image: hyperledger/fabric-orderer:$ARCH-1.1.0-rc1
environment:
- ORDERER_GENERAL_LOGLEVEL=debug
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
Expand All @@ -45,7 +45,7 @@ services:

peer0.org1.example.com:
container_name: peer0.org1.example.com
image: hyperledger/fabric-peer:$ARCH-1.1.0-alpha
image: hyperledger/fabric-peer:$ARCH-1.1.0-rc1
environment:
- CORE_LOGGING_PEER=debug
- CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
Expand Down Expand Up @@ -74,15 +74,15 @@ services:

couchdb.org1.example.com:
container_name: couchdb.org1.example.com
image: hyperledger/fabric-couchdb:$ARCH-0.4.5
image: hyperledger/fabric-couchdb:$ARCH-0.4.6
ports:
- 5984:5984
environment:
DB_URL: http://localhost:5984/member_db

peer0.org2.example.com:
container_name: peer0.org2.example.com
image: hyperledger/fabric-peer:$ARCH-1.1.0-alpha
image: hyperledger/fabric-peer:$ARCH-1.1.0-rc1
environment:
- CORE_LOGGING_PEER=debug
- CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
Expand Down Expand Up @@ -111,7 +111,7 @@ services:

couchdb.org2.example.com:
container_name: couchdb.org2.example.com
image: hyperledger/fabric-couchdb:$ARCH-0.4.5
image: hyperledger/fabric-couchdb:$ARCH-0.4.6
ports:
- 6984:5984
environment:
Expand Down
10 changes: 5 additions & 5 deletions packages/composer-playground/e2e/fabric/scripts/setupFabric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export COMPOSER_TIMEOUT_SECS=500

DOCKER_FILE=${DIR}/hlfv1/docker-compose.yml

docker pull hyperledger/fabric-peer:$ARCH-1.1.0-alpha
docker pull hyperledger/fabric-ca:$ARCH-1.1.0-alpha
docker pull hyperledger/fabric-ccenv:$ARCH-1.1.0-alpha
docker pull hyperledger/fabric-orderer:$ARCH-1.1.0-alpha
docker pull hyperledger/fabric-couchdb:$ARCH-0.4.5
docker pull hyperledger/fabric-peer:$ARCH-1.1.0-rc1
docker pull hyperledger/fabric-ca:$ARCH-1.1.0-rc1
docker pull hyperledger/fabric-ccenv:$ARCH-1.1.0-rc1
docker pull hyperledger/fabric-orderer:$ARCH-1.1.0-rc1
docker pull hyperledger/fabric-couchdb:$ARCH-0.4.6

if [ -d ./hlfv1/crypto-config ]; then
rm -rf ./hlfv1/crypto-config
Expand Down
8 changes: 8 additions & 0 deletions packages/composer-runtime-pouchdb/lib/pouchdbdataservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ class PouchDBDataService extends DataService {
const method = 'executeQuery';
LOG.entry(method, queryString);
const query = JSON.parse(queryString);
// PouchDB doesn't deal with $class in the same way that CouchDB does, so
// we need to adapt the selector slightly.
['$class', '$registryType', '$registryId'].forEach((prop) => {
if (query.selector[`\\${prop}`]) {
query.selector[prop] = query.selector[`\\${prop}`];
delete query.selector[`\\${prop}`];
}
});
return this.db.find(query)
.then((response) => {
const docs = response.docs.map((doc) => {
Expand Down
81 changes: 75 additions & 6 deletions packages/composer-runtime-pouchdb/test/pouchdbdataservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,34 @@ describe('PouchDBDataService', () => {
{
_id: pouchCollate.toIndexableString(['doges1', 'thing1']),
thingId: 1,
colour: 'red'
colour: 'red',
$class: 'org.acme.Foo1',
$registryType: 'Asset',
$registryId: 'org.acme.Foo1'
},
{
_id: pouchCollate.toIndexableString(['doges1', 'thing2']),
thingId: 2,
colour: 'black'
colour: 'black',
$class: 'org.acme.Foo1',
$registryType: 'Asset',
$registryId: 'DogesBagOfFoos'
},
{
_id: pouchCollate.toIndexableString(['doges1', 'thing3']),
thingId: 3,
colour: 'red'
colour: 'red',
$class: 'org.acme.Foo2',
$registryType: 'Participant',
$registryId: 'org.acme.Foo2'
},
{
_id: pouchCollate.toIndexableString(['doges1', 'thing4']),
thingId: 4,
colour: 'green'
colour: 'green',
$class: 'org.acme.Foo2',
$registryType: 'Participant',
$registryId: 'DogesBagOfFoos'
}
]);
});
Expand All @@ -269,10 +281,67 @@ describe('PouchDBDataService', () => {
return dataService.executeQuery('{"selector":{"colour":{"$eq":"red"}}}')
.should.eventually.be.deep.equal([{
thingId: 1,
colour: 'red'
colour: 'red',
$class: 'org.acme.Foo1',
$registryType: 'Asset',
$registryId: 'org.acme.Foo1'
}, {
thingId: 3,
colour: 'red'
colour: 'red',
$class: 'org.acme.Foo2',
$registryType: 'Participant',
$registryId: 'org.acme.Foo2'
}]);
});

it('should return the query results after transforming the $class variable', () => {
return dataService.executeQuery('{"selector":{"\\\\$class":"org.acme.Foo1"}}')
.should.eventually.be.deep.equal([{
thingId: 1,
colour: 'red',
$class: 'org.acme.Foo1',
$registryType: 'Asset',
$registryId: 'org.acme.Foo1'
}, {
thingId: 2,
colour: 'black',
$class: 'org.acme.Foo1',
$registryType: 'Asset',
$registryId: 'DogesBagOfFoos'
}]);
});

it('should return the query results after transforming the $registryType variable', () => {
return dataService.executeQuery('{"selector":{"\\\\$registryType":"Participant"}}')
.should.eventually.be.deep.equal([{
thingId: 3,
colour: 'red',
$class: 'org.acme.Foo2',
$registryType: 'Participant',
$registryId: 'org.acme.Foo2'
}, {
thingId: 4,
colour: 'green',
$class: 'org.acme.Foo2',
$registryType: 'Participant',
$registryId: 'DogesBagOfFoos'
}]);
});

it('should return the query results after transforming the $registryId variable', () => {
return dataService.executeQuery('{"selector":{"\\\\$registryId":"DogesBagOfFoos"}}')
.should.eventually.be.deep.equal([{
thingId: 2,
colour: 'black',
$class: 'org.acme.Foo1',
$registryType: 'Asset',
$registryId: 'DogesBagOfFoos'
}, {
thingId: 4,
colour: 'green',
$class: 'org.acme.Foo2',
$registryType: 'Participant',
$registryId: 'DogesBagOfFoos'
}]);
});

Expand Down
14 changes: 8 additions & 6 deletions packages/composer-runtime/lib/querycompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,29 @@ class QueryCompiler {
const query = {
selector: {}
};
query.selector.$class = resource;

// The \\ escape for $class is required to avoid CouchDB treating it as an operator.
query.selector['\\$class'] = resource;

// Look up the type for this resource.
const modelManager = select.getQuery().getQueryFile().getModelManager();
const classDeclaration = modelManager.getType(resource);
if (classDeclaration instanceof AssetDeclaration) {
query.selector.$registryType = 'Asset';
query.selector['\\$registryType'] = 'Asset';
} else if (classDeclaration instanceof ParticipantDeclaration) {
query.selector.$registryType = 'Participant';
query.selector['\\$registryType'] = 'Participant';
} else if (classDeclaration instanceof TransactionDeclaration) {
query.selector.$registryType = 'Transaction';
query.selector['\\$registryType'] = 'Transaction';
} else {
throw new Error('The query compiler does not support resources of this type');
}

// Handle the from clause, if it exists.
const registry = select.getRegistry();
if (registry) {
query.selector.$registryId = registry;
query.selector['\\$registryId'] = registry;
} else {
query.selector.$registryId = resource;
query.selector['\\$registryId'] = resource;
}

// Handle the where clause, if it exists.
Expand Down
6 changes: 3 additions & 3 deletions packages/composer-runtime/test/compiledquerybundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const sinon = require('sinon');

describe('CompiledQueryBundle', () => {

const fakeQueryString = '{"selector":{"$class":"org.acme.sample.SampleAsset","value":{"$eq":"Green hat"}}}';
const fakeQueryString = '{"selector":{"\\\\$class":"org.acme.sample.SampleAsset","value":{"\\\\$eq":"Green hat"}}}';
const fakeQueryResults = [{ such: 'things' }, { much: 'wow '}];

let queryCompiler;
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('CompiledQueryBundle', () => {
return compiledQueryBundle.execute(mockDataService, identifier)
.then((result) => {
sinon.assert.calledOnce(mockDataService.executeQuery);
sinon.assert.calledWith(mockDataService.executeQuery, '{"selector":{"$class":"org.acme.sample.SampleAsset","$registryType":"Asset","$registryId":"org.acme.sample.SampleAsset"}}');
sinon.assert.calledWith(mockDataService.executeQuery, '{"selector":{"\\\\$class":"org.acme.sample.SampleAsset","\\\\$registryType":"Asset","\\\\$registryId":"org.acme.sample.SampleAsset"}}');
result.should.deep.equal(fakeQueryResults);
});
});
Expand All @@ -149,7 +149,7 @@ describe('CompiledQueryBundle', () => {
return compiledQueryBundle.execute(mockDataService, identifier, { foo: 'bar' })
.then((result) => {
sinon.assert.calledOnce(mockDataService.executeQuery);
sinon.assert.calledWith(mockDataService.executeQuery, '{"selector":{"$class":"org.acme.sample.SampleAsset","$registryType":"Asset","$registryId":"org.acme.sample.SampleAsset","value":{"$eq":"bar"}}}');
sinon.assert.calledWith(mockDataService.executeQuery, '{"selector":{"\\\\$class":"org.acme.sample.SampleAsset","\\\\$registryType":"Asset","\\\\$registryId":"org.acme.sample.SampleAsset","value":{"$eq":"bar"}}}');
result.should.deep.equal(fakeQueryResults);
});
});
Expand Down
Loading

0 comments on commit 80fce09

Please sign in to comment.