Skip to content

Commit e36d81e

Browse files
Relax grpc-js version constraint in fabric-shim (#437)
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 <[email protected]>
1 parent 2fc48af commit e36d81e

File tree

4 files changed

+103
-69
lines changed

4 files changed

+103
-69
lines changed

.editorconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
5-
#
5+
#
66
# http://www.apache.org/licenses/LICENSE-2.0
77
#
88
# Unless required by applicable law or agreed to in writing, software
@@ -23,4 +23,8 @@ trim_trailing_whitespace = true
2323
insert_final_newline = true
2424

2525
[*.md]
26-
trim_trailing_whitespace = false
26+
trim_trailing_whitespace = false
27+
indent_size = 2
28+
29+
[*.{mj,cj,j,t}s]
30+
quote_type = single

common/config/rush/pnpm-lock.yaml

Lines changed: 34 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/fabric-shim/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
},
5555
"dependencies": {
5656
"@fidm/x509": "^1.2.1",
57-
"@grpc/grpc-js": "~1.10.9",
58-
"@hyperledger/fabric-protos": "~0.2.1",
57+
"@grpc/grpc-js": "^1.11.0",
58+
"@hyperledger/fabric-protos": "^0.2.2",
5959
"@types/node": "^16.11.1",
6060
"ajv": "^6.12.2",
6161
"fabric-contract-api": "2.5.7",

libraries/fabric-shim/test/unit/utils/statebased.js

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('KeyEndorsementPolicy', () => {
2323
const anotherEp = new KeyEndorsementPolicy(policy);
2424
expect(anotherEp.orgs).to.deep.eql({
2525
Org1MSP: 0,
26-
Org2MSP: 0
26+
Org2MSP: 0,
2727
});
2828
});
2929
});
@@ -36,11 +36,15 @@ describe('KeyEndorsementPolicy', () => {
3636
});
3737

3838
it('should throw error if role is not supported', () => {
39-
expect(() => ep.addOrgs('aDummyRole', 'org1msp')).to.throw(/role type aDummyRole does not exist/);
39+
expect(() => ep.addOrgs('aDummyRole', 'org1msp')).to.throw(
40+
/role type aDummyRole does not exist/
41+
);
4042
});
4143

4244
it('should throw error if role is missing', () => {
43-
expect(() => ep.addOrgs()).to.throw(/role type undefined does not exist/);
45+
expect(() => ep.addOrgs()).to.throw(
46+
/role type undefined does not exist/
47+
);
4448
});
4549

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

109-
const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy);
110-
const speClone = common.SignaturePolicyEnvelope.deserializeBinary(anotherEp.getPolicy());
113+
const spe =
114+
common.SignaturePolicyEnvelope.deserializeBinary(policy);
115+
const speClone = common.SignaturePolicyEnvelope.deserializeBinary(
116+
anotherEp.getPolicy()
117+
);
111118
expect(spe.toObject()).to.deep.equals(speClone.toObject());
112119
});
113120

114-
115121
it('should get policy that is semantically valid', () => {
116122
const policy = ep.getPolicy();
117-
const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy);
123+
const spe =
124+
common.SignaturePolicyEnvelope.deserializeBinary(policy);
118125

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

122-
speObject.identitiesList = spe.getIdentitiesList().map(principal => {
123-
let mapped = { principalClassification: 0 };
124-
mapped.principal = msp.MSPRole.deserializeBinary(principal.getPrincipal_asU8()).toObject();
125-
return mapped;
126-
});
127-
128-
speObject.rule.nOutOf.rulesList = spe.getRule().getNOutOf().getRulesList().map(sigRule =>{
129-
return {signedBy: sigRule.getSignedBy()}
130-
});
131-
132-
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}}]}
129+
speObject.identitiesList = spe
130+
.getIdentitiesList()
131+
.map((principal) => {
132+
let mapped = { principalClassification: 0 };
133+
mapped.principal = msp.MSPRole.deserializeBinary(
134+
principal.getPrincipal_asU8()
135+
).toObject();
136+
return mapped;
137+
});
138+
139+
speObject.rule.signedBy = spe.getRule().getSignedBy();
140+
speObject.rule.nOutOf.rulesList = spe
141+
.getRule()
142+
.getNOutOf()
143+
.getRulesList()
144+
.map((sigRule) => {
145+
return { signedBy: sigRule.getSignedBy() };
146+
});
147+
148+
const expectedPolicy = {
149+
version: 0,
150+
rule: {
151+
signedBy: 0,
152+
nOutOf: {
153+
n: 3,
154+
rulesList: [
155+
{ signedBy: 0 },
156+
{ signedBy: 1 },
157+
{ signedBy: 2 },
158+
],
159+
},
160+
},
161+
identitiesList: [
162+
{
163+
principalClassification: 0,
164+
principal: { mspIdentifier: 'Org1MSP', role: 0 },
165+
},
166+
{
167+
principalClassification: 0,
168+
principal: { mspIdentifier: 'Org2MSP', role: 0 },
169+
},
170+
{
171+
principalClassification: 0,
172+
principal: { mspIdentifier: 'Org3MSP', role: 0 },
173+
},
174+
],
175+
};
133176
expect(speObject).to.deep.equals(expectedPolicy);
134177
});
135178
});
136179
});
137-
138-

0 commit comments

Comments
 (0)