public void TestListOrgs() { byte[] initEPBytes = StateBasedEndorsementUtils.SignedByFabricEntity("Org1", MSPRole.Types.MSPRoleType.Peer).ToByteString().ToByteArray(); StateBasedEndorsement ep = new StateBasedEndorsement(initEPBytes); List <String> listOrgs = ep.ListOrgs(); Assert.IsNotNull(listOrgs); Assert.AreEqual(listOrgs.Count, 1); CollectionAssert.Contains(listOrgs, "Org1"); }
public override Response Invoke(IChaincodeStub stub) { string aKey = stub.StringArgs[1]; byte[] epBytes = stub.GetStateValidationParameter(aKey); StateBasedEndorsement stateBasedEndorsement = new StateBasedEndorsement(epBytes); Assert.AreEqual(stateBasedEndorsement.ListOrgs().Count, 2); stub.SetStateValidationParameter(aKey, stateBasedEndorsement.Policy()); return(NewSuccessResponse("OK response2")); }
public void TestDelOrgs() { byte[] initEPBytes = StateBasedEndorsementUtils.SignedByFabricEntity("Org1", MSPRole.Types.MSPRoleType.Peer).ToByteString().ToByteArray(); StateBasedEndorsement ep = new StateBasedEndorsement(initEPBytes); List <string> listOrgs = ep.ListOrgs(); Assert.IsNotNull(listOrgs); CollectionAssert.Contains(listOrgs, "Org1"); Assert.AreEqual(listOrgs.Count, 1); ep.AddOrgs(RoleType.RoleTypeMember, "Org2"); ep.DelOrgs("Org1"); byte[] epBytes = ep.Policy(); Assert.IsNotNull(epBytes); Assert.IsTrue(epBytes.Length > 0); byte[] expectedEPBytes = StateBasedEndorsementUtils.SignedByFabricEntity("Org2", MSPRole.Types.MSPRoleType.Member).ToByteString().ToByteArray(); CollectionAssert.AreEqual(expectedEPBytes, epBytes); }
/** * Check incoming message * If message type is PUT_STATE_METADATA and payload match to passed in constructor * @param msg message from chaincode * @return */ public bool Expected(ChaincodeMessage msg) { orgMsg = msg; PutStateMetadata psm; try { psm = PutStateMetadata.Parser.ParseFrom(msg.Payload); } catch (InvalidProtocolBufferException) { return(false); } StateBasedEndorsement msgSbe = new StateBasedEndorsement(psm.Metadata.Value.ToByteArray()); return(msg.Type == ChaincodeMessage.Types.Type.PutStateMetadata && ChaincodeStub.VALIDATION_PARAMETER.Equals(psm.Metadata.Metakey) && msgSbe.ListOrgs().Count == val.ListOrgs().Count); }