Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax grpc-js version constraint in fabric-shim #437

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the only actual change in this file. The rest is just formatting.

It seems newer binding defaulted the value of speObject.rule.signedBy to undefined instead of 0 when created by spe.toObject() in the test code above. This change just explicitly copies the actual value instead of relying on a default, and is probably how it should always have been done.

Note that this is just a change to how the test code collects the protobuf state before the equality test below. No change to the implementation code.

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);
});
});
});


Loading