示例#1
0
        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"));
            }
示例#3
0
        public void TestAddOrgs()
        {
            // add an org
            StateBasedEndorsement ep = new StateBasedEndorsement(null);

            ep.AddOrgs(RoleType.RoleTypePeer, "Org1");

            byte[] epBytes = ep.Policy();
            Assert.IsNotNull(epBytes);
            Assert.IsTrue(epBytes.Length > 0);
            byte[] expectedEPBytes = StateBasedEndorsementUtils.SignedByFabricEntity("Org1", MSPRole.Types.MSPRoleType.Peer).ToByteString().ToByteArray();
            CollectionAssert.AreEqual(expectedEPBytes, epBytes);
        }
        public void TestStateValidationParameter()
        {
            ChaincodeBase  cb = new Cb8();
            ChaincodeInput ci = new ChaincodeInput();

            ci.Args.AddRange(new[] { ByteString.CopyFromUtf8("init") });
            ByteString            initPayload = ci.ToByteString();
            ChaincodeMessage      initMsg     = MessageUtil.NewEventMessage(ChaincodeMessage.Types.Type.Init, "testChannel", "0", initPayload, null);
            StateBasedEndorsement sbe         = new StateBasedEndorsement(null);

            sbe.AddOrgs(RoleType.RoleTypePeer, "Org1");
            sbe.AddOrgs(RoleType.RoleTypeMember, "Org2");

            List <IScenarioStep> scenario = new List <IScenarioStep>();


            scenario.Add(new RegisterStep());
            scenario.Add(new CompleteStep());

            scenario.Add(new GetStateMetadataStep(sbe));
            scenario.Add(new PutStateMetadataStep(sbe));
            scenario.Add(new CompleteStep());
            server = ChaincodeMockPeer.StartServer(scenario);

            cb.Start(new string[] { "-a", "127.0.0.1:7052", "-i", "testId" });
            CheckScenarioStepEnded(server, 1, Timeout);

            server.Send(initMsg);
            CheckScenarioStepEnded(server, 2, Timeout);
            Assert.AreEqual(server.LastMessageSend.Type, ChaincodeMessage.Types.Type.Init);
            Assert.AreEqual(server.LastMessageRcvd.Type, ChaincodeMessage.Types.Type.Completed);
            Assert.AreEqual(Protos.Peer.ProposalResponsePackage.Response.Parser.ParseFrom(server.LastMessageRcvd.Payload).Message, "OK response1");


            ci = new ChaincodeInput();
            ci.Args.AddRange(new[] { ByteString.CopyFromUtf8("invoke"), ByteString.CopyFromUtf8("a") });
            ByteString       invokePayload = ci.ToByteString();
            ChaincodeMessage invokeMsg     = MessageUtil.NewEventMessage(ChaincodeMessage.Types.Type.Transaction, "testChannel", "0", invokePayload, null);

            server.Send(invokeMsg);
            CheckScenarioStepEnded(server, 5, Timeout);
            Assert.AreEqual(server.LastMessageSend.Type, ChaincodeMessage.Types.Type.Response);
            Assert.AreEqual(server.LastMessageRcvd.Type, ChaincodeMessage.Types.Type.Completed);
            Assert.AreEqual(Protos.Peer.ProposalResponsePackage.Response.Parser.ParseFrom(server.LastMessageRcvd.Payload).Message, "OK response2");
        }
示例#5
0
        /**
         * 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);
        }
示例#6
0
        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);
        }
示例#7
0
 public PutStateMetadataStep(StateBasedEndorsement sbe)
 {
     val = sbe;
 }
 /**
  * @param sbe StateBasedEndosement to return as one and only one metadata entry
  */
 public GetStateMetadataStep(StateBasedEndorsement sbe)
 {
     val = sbe.Policy();
 }