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");
        }
示例#2
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);
        }
示例#3
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);
        }