|
4 | 4 | # SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | - |
8 | | -// const rewire = require('rewire'); |
9 | | - |
| 7 | +const { msp, common } = require('@hyperledger/fabric-protos'); |
| 8 | +const { SignedProposal } = require('@hyperledger/fabric-protos/lib/peer'); |
10 | 9 | const chai = require('chai'); |
11 | 10 | const expect = chai.expect; |
12 | 11 | const KeyEndorsementPolicy = require('../../../lib/utils/statebased'); |
@@ -106,9 +105,34 @@ describe('KeyEndorsementPolicy', () => { |
106 | 105 | it('should successfully get policy', () => { |
107 | 106 | const policy = ep.getPolicy(); |
108 | 107 | const anotherEp = new KeyEndorsementPolicy(policy); |
109 | | - expect(anotherEp.orgs).to.haveOwnProperty('Org1MSP'); |
110 | | - expect(anotherEp.orgs).to.haveOwnProperty('Org2MSP'); |
111 | | - expect(anotherEp.orgs).to.haveOwnProperty('Org3MSP'); |
| 108 | + |
| 109 | + const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy); |
| 110 | + const speClone = common.SignaturePolicyEnvelope.deserializeBinary(anotherEp.getPolicy()); |
| 111 | + expect(spe.toObject()).to.deep.equals(speClone.toObject()); |
| 112 | + }); |
| 113 | + |
| 114 | + |
| 115 | + it('should get policy that is semantically valid', () => { |
| 116 | + const policy = ep.getPolicy(); |
| 117 | + const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy); |
| 118 | + |
| 119 | + // create a blank object and expand all the protobufs into it |
| 120 | + const speObject = spe.toObject(); |
| 121 | + |
| 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}}]} |
| 133 | + expect(speObject).to.deep.equals(expectedPolicy); |
112 | 134 | }); |
113 | 135 | }); |
114 | 136 | }); |
| 137 | + |
| 138 | + |
0 commit comments