Skip to content

Commit

Permalink
Relax grpc-js version constraint in fabric-shim (#437)
Browse files Browse the repository at this point in the history
When different versions of @grpc/grpc-js are resolved in the dependency
tree, the following error in the chaincode can prevent the chaincode
container from starting:

    TypeError: Channel credentials must be a ChannelCredentials object

This is typically caused by a mismatch between the versions of
@grpc/grpc-js specified by fabric-shim and @hyperledger/fabric-protos.
Provided the version constraints are loose enough to allow a single
version to satisfy both dependencies, the mismatch can be avoided by
deduping dependencies in a consuming chaincode.

This change relaxes the @grpc/grpc-js version constraint in fabric-shim
to allow compatibility with any newer minor release version specified by
@hyperledger/fabric-protos.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday authored Sep 27, 2024
1 parent 2fc48af commit e36d81e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 69 deletions.
8 changes: 6 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
Expand All @@ -23,4 +23,8 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = false
indent_size = 2

[*.{mj,cj,j,t}s]
quote_type = single
79 changes: 34 additions & 45 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions libraries/fabric-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
},
"dependencies": {
"@fidm/x509": "^1.2.1",
"@grpc/grpc-js": "~1.10.9",
"@hyperledger/fabric-protos": "~0.2.1",
"@grpc/grpc-js": "^1.11.0",
"@hyperledger/fabric-protos": "^0.2.2",
"@types/node": "^16.11.1",
"ajv": "^6.12.2",
"fabric-contract-api": "2.5.7",
Expand Down
81 changes: 61 additions & 20 deletions libraries/fabric-shim/test/unit/utils/statebased.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('KeyEndorsementPolicy', () => {
const anotherEp = new KeyEndorsementPolicy(policy);
expect(anotherEp.orgs).to.deep.eql({
Org1MSP: 0,
Org2MSP: 0
Org2MSP: 0,
});
});
});
Expand All @@ -36,11 +36,15 @@ describe('KeyEndorsementPolicy', () => {
});

it('should throw error if role is not supported', () => {
expect(() => ep.addOrgs('aDummyRole', 'org1msp')).to.throw(/role type aDummyRole does not exist/);
expect(() => ep.addOrgs('aDummyRole', 'org1msp')).to.throw(
/role type aDummyRole does not exist/
);
});

it('should throw error if role is missing', () => {
expect(() => ep.addOrgs()).to.throw(/role type undefined does not exist/);
expect(() => ep.addOrgs()).to.throw(
/role type undefined does not exist/
);
});

it('should success add multiple orgs', () => {
Expand Down Expand Up @@ -106,33 +110,70 @@ describe('KeyEndorsementPolicy', () => {
const policy = ep.getPolicy();
const anotherEp = new KeyEndorsementPolicy(policy);

const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy);
const speClone = common.SignaturePolicyEnvelope.deserializeBinary(anotherEp.getPolicy());
const spe =
common.SignaturePolicyEnvelope.deserializeBinary(policy);
const speClone = common.SignaturePolicyEnvelope.deserializeBinary(
anotherEp.getPolicy()
);
expect(spe.toObject()).to.deep.equals(speClone.toObject());
});


it('should get policy that is semantically valid', () => {
const policy = ep.getPolicy();
const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy);
const spe =
common.SignaturePolicyEnvelope.deserializeBinary(policy);

// create a blank object and expand all the protobufs into it
const speObject = spe.toObject();

speObject.identitiesList = spe.getIdentitiesList().map(principal => {
let mapped = { principalClassification: 0 };
mapped.principal = msp.MSPRole.deserializeBinary(principal.getPrincipal_asU8()).toObject();
return mapped;
});

speObject.rule.nOutOf.rulesList = spe.getRule().getNOutOf().getRulesList().map(sigRule =>{
return {signedBy: sigRule.getSignedBy()}
});

const expectedPolicy={"version":0,"rule":{"signedBy":0,"nOutOf":{"n":3,"rulesList":[{"signedBy":0},{"signedBy":1},{"signedBy":2}]}},"identitiesList":[{"principalClassification":0,"principal":{"mspIdentifier":"Org1MSP","role":0}},{"principalClassification":0,"principal":{"mspIdentifier":"Org2MSP","role":0}},{"principalClassification":0,"principal":{"mspIdentifier":"Org3MSP","role":0}}]}
speObject.identitiesList = spe
.getIdentitiesList()
.map((principal) => {
let mapped = { principalClassification: 0 };
mapped.principal = msp.MSPRole.deserializeBinary(
principal.getPrincipal_asU8()
).toObject();
return mapped;
});

speObject.rule.signedBy = spe.getRule().getSignedBy();
speObject.rule.nOutOf.rulesList = spe
.getRule()
.getNOutOf()
.getRulesList()
.map((sigRule) => {
return { signedBy: sigRule.getSignedBy() };
});

const expectedPolicy = {
version: 0,
rule: {
signedBy: 0,
nOutOf: {
n: 3,
rulesList: [
{ signedBy: 0 },
{ signedBy: 1 },
{ signedBy: 2 },
],
},
},
identitiesList: [
{
principalClassification: 0,
principal: { mspIdentifier: 'Org1MSP', role: 0 },
},
{
principalClassification: 0,
principal: { mspIdentifier: 'Org2MSP', role: 0 },
},
{
principalClassification: 0,
principal: { mspIdentifier: 'Org3MSP', role: 0 },
},
],
};
expect(speObject).to.deep.equals(expectedPolicy);
});
});
});


0 comments on commit e36d81e

Please sign in to comment.