public void testLoadFromConfigFileJsonBasic()
        {
            ChaincodeCollectionConfiguration configYAML = ChaincodeCollectionConfiguration.FromYamlFile("fixture/collectionProperties/testCollection.yaml".Locate());

            Assert.IsNotNull(configYAML);
            byte[] configAsBytesYAML = configYAML.GetAsBytes();
            Assert.IsNotNull(configAsBytesYAML);
            Assert.AreEqual(configAsBytesYAML.Length, 137);
            ChaincodeCollectionConfiguration configJson = ChaincodeCollectionConfiguration.FromJsonFile("fixture/collectionProperties/testCollection.json".Locate());

            Assert.IsNotNull(configJson);
            byte[] configAsBytesJson = configYAML.GetAsBytes();
            Assert.IsNotNull(configAsBytesJson);
            Assert.AreEqual(configAsBytesJson.Length, 137);
            CollectionAssert.AreEqual(configAsBytesYAML, configAsBytesJson);
        }
        public void TestLoadFromConfigFileYamlBasic()
        {
            ChaincodeCollectionConfiguration config = ChaincodeCollectionConfiguration.FromYamlFile("Fixture/collectionProperties/testCollection.yaml".Locate());

            Assert.IsNotNull(config);
            byte[] configAsBytes = config.GetAsBytes();
            Assert.IsNotNull(configAsBytes);
            Assert.AreEqual(configAsBytes.Length, 137);
            CollectionConfigPackage collectionConfigPackage = CollectionConfigPackage.Parser.ParseFrom(configAsBytes);

            Assert.AreEqual(collectionConfigPackage.Config.Count, 1);
            CollectionConfig colConfig = collectionConfigPackage.Config.FirstOrDefault();

            Assert.IsNotNull(colConfig);
            StaticCollectionConfig staticCollectionConfig = colConfig.StaticCollectionConfig;

            Assert.IsNotNull(staticCollectionConfig);
            Assert.AreEqual(staticCollectionConfig.BlockToLive, (ulong)3);
            Assert.AreEqual(staticCollectionConfig.Name, "rick");
            Assert.AreEqual(staticCollectionConfig.MaximumPeerCount, 9);
            Assert.AreEqual(staticCollectionConfig.RequiredPeerCount, 7);
            CollectionPolicyConfig memberOrgsPolicy = staticCollectionConfig.MemberOrgsPolicy;

            Assert.IsNotNull(memberOrgsPolicy);
            SignaturePolicyEnvelope signaturePolicy = memberOrgsPolicy.SignaturePolicy;

            Assert.IsNotNull(signaturePolicy);
            Assert.AreEqual(signaturePolicy.Version, 0);
            SignaturePolicy rule = signaturePolicy.Rule;

            Assert.IsNotNull(rule);
            Assert.AreEqual(rule.TypeCase, SignaturePolicy.TypeOneofCase.NOutOf);
            SignaturePolicy.Types.NOutOf nOutOf = rule.NOutOf;
            Assert.IsNotNull(nOutOf);
            Assert.AreEqual(2, nOutOf.N);
            List <MSPPrincipal> identitiesList = signaturePolicy.Identities?.ToList();

            Assert.IsNotNull(identitiesList);
            Assert.AreEqual(3, identitiesList.Count);
        }
        public void TestLoadFromConfigYamlFileNotExists()
        {
            // Should not be able to instantiate a new instance of "Client" without an actual configuration file

            ChaincodeCollectionConfiguration.FromYamlFile("FileDoesNotExist.yaml");
        }
        public void TestLoadFromConfigNullYamlFile()
        {
            // Should not be able to instantiate a new instance of "Client" without a valid path to the configuration');

            ChaincodeCollectionConfiguration.FromYamlFile(null);
        }
Esempio n. 5
0
        // Disable MethodLength as this method is for instructional purposes and hence
        // we don't want to split it into smaller pieces
        // CHECKSTYLE:OFF: MethodLength
        private void RunChannel(HFClient client, Channel channel, SampleOrg sampleOrg, int delta)
        {
            string channelName = channel.Name;

            try
            {
                client.UserContext = sampleOrg.GetUser(TESTUSER_1_NAME);

                Util.COut("Running Channel %s with a delta %d", channelName, delta);

                Util.COut("ChaincodeID: ", chaincodeID);

                client.UserContext = sampleOrg.PeerAdmin;
                ///////////////
                ////
                InstallProposalRequest installProposalRequest = client.NewInstallProposalRequest();
                installProposalRequest.SetChaincodeID(chaincodeID);
                ////For GO language and serving just a single user, chaincodeSource is mostly likely the users GOPATH
                installProposalRequest.SetChaincodeSourceLocation(Path.Combine(TEST_FIXTURES_PATH, CHAIN_CODE_FILEPATH).Locate());
                installProposalRequest.SetChaincodeVersion(CHAIN_CODE_VERSION);
                installProposalRequest.SetProposalWaitTime(testConfig.GetProposalWaitTime());
                installProposalRequest.SetChaincodeLanguage(CHAIN_CODE_LANG);

                Util.COut("Sending install proposal for channel: %s", channel.Name);

                ////////////////////////////
                // only a client from the same org as the peer can issue an install request
                int numInstallProposal = 0;

                List <ProposalResponse> responses;
                List <ProposalResponse> successful   = new List <ProposalResponse>();
                List <ProposalResponse> failed       = new List <ProposalResponse>();
                List <Peer>             peersFromOrg = channel.Peers.ToList();
                numInstallProposal = numInstallProposal + peersFromOrg.Count;

                responses = client.SendInstallProposal(installProposalRequest, peersFromOrg);

                foreach (ProposalResponse response in responses)
                {
                    if (response.Status == ChaincodeResponse.ChaincodeResponseStatus.SUCCESS)
                    {
                        Util.COut("Successful install proposal response Txid: %s from peer %s", response.TransactionID, response.Peer.Name);
                        successful.Add(response);
                    }
                    else
                    {
                        failed.Add(response);
                    }
                }

                Util.COut("Received %d install proposal responses. Successful+verified: %d . Failed: %d", numInstallProposal, successful.Count, failed.Count);

                if (failed.Count > 0)
                {
                    ProposalResponse first = failed.First();
                    Assert.Fail("Not enough endorsers for install :" + successful.Count + ".  " + first.Message);
                }

                InstantiateProposalRequest instantiateProposalRequest = client.NewInstantiationProposalRequest();
                instantiateProposalRequest.SetChaincodeID(chaincodeID);
                instantiateProposalRequest.SetProposalWaitTime(DEPLOYWAITTIME);
                instantiateProposalRequest.SetFcn("init");
                instantiateProposalRequest.SetArgs(new string[] { });
                instantiateProposalRequest.SetChaincodeCollectionConfiguration(ChaincodeCollectionConfiguration.FromYamlFile("fixture/collectionProperties/PrivateDataIT.yaml".Locate()));

                Util.COut("Sending instantiate proposal");

                List <ProposalResponse> responses2;

                responses2 = channel.SendInstantiationProposal(instantiateProposalRequest);

                successful.Clear();
                failed.Clear();
                foreach (ProposalResponse response in responses2)
                {
                    if (response.Status == ChaincodeResponse.ChaincodeResponseStatus.SUCCESS)
                    {
                        Util.COut("Successful upgrade proposal response Txid: %s from peer %s", response.TransactionID, response.Peer.Name);
                        successful.Add(response);
                    }
                    else
                    {
                        failed.Add(response);
                    }
                }

                Util.COut("Received %d upgrade proposal responses. Successful+verified: %d . Failed: %d", channel.Peers.Count, successful.Count, failed.Count);

                if (failed.Count > 0)
                {
                    ProposalResponse first = failed.First();
                    Assert.Fail("Not enough endorsers for upgrade :" + successful.Count + ".  " + first.Message);
                }

                Util.COut("Sending instantiate proposal to orderer.");
                channel.SendTransaction(successful, sampleOrg.PeerAdmin);
                Util.COut("instantiate proposal completed.");

                //Now lets run the new chaincode which should *double* the results we asked to move.
                // return setAmount(client, channel, chaincodeID, "50", null).get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS);
                SetAmount(client, channel, chaincodeID, 50, null);
                Util.COut("Got back acknowledgement from setAmount from all peers.");
                WaitOnFabric(10000);

                Util.COut("delta is %s", delta);
                QueryChaincodeForExpectedValue(client, channel, "" + 250, chaincodeID);
                //Now lets run the new chaincode which should *double* the results we asked to move.
                MoveAmount(client, channel, chaincodeID, "50", null);
            }
            catch (TransactionEventException e)
            {
                TransactionEvent te = e.TransactionEvent;
                Assert.Fail($"Transaction with txid %s failed. %s", te.TransactionID, e.Message);
            }

            catch (System.Exception e)
            {
                Assert.Fail($"Test failed with {e.Message} exception {e}");
            }

            QueryChaincodeForExpectedValue(client, channel, "" + 300, chaincodeID);

            Util.COut("Running for Channel %s done", channelName);
        }