示例#1
0
        public void TestLoadFromConfigFileYamlNOOverridesButSet()
        {
            // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration
            string        f      = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate());
            NetworkConfig config = NetworkConfig.FromYamlFile(f);

            //HFClient client = HFClient.loadFromConfig(f);
            Assert.IsNotNull(config);

            HFClient client = HFClient.Create();

            client.CryptoSuite = Factory.Instance.GetCryptoSuite();
            client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID);


            Channel channel = client.LoadChannelFromConfig("foo", config);

            Assert.IsNotNull(channel);

            Assert.IsTrue(channel.Orderers.Count != 0);

            foreach (Orderer orderer in channel.Orderers)
            {
                Properties properties = orderer.Properties;
                string     str        = properties.Get("grpc.keepalive_time_ms");
                Assert.AreEqual(long.Parse(str), 360000L);

                str = properties.Get("grpc.keepalive_timeout_ms");
                Assert.AreEqual(long.Parse(str), 180000L);
            }
        }
示例#2
0
        public void TestLoadFromConfigFileYamlNOOverrides()
        {
            // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration
            string        f      = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate());
            NetworkConfig config = NetworkConfig.FromYamlFile(f);

            //HFClient client = HFClient.loadFromConfig(f);
            Assert.IsNotNull(config);
            HFClient client = HFClient.Create();

            client.CryptoSuite = Factory.Instance.GetCryptoSuite();
            client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID);

            Channel channel = client.LoadChannelFromConfig("foo", config);

            Assert.IsNotNull(channel);

            Assert.IsTrue(channel.Peers.Count != 0);

            foreach (Peer peer in channel.Peers)
            {
                Properties properties = peer.Properties;

                Assert.IsNotNull(properties);
                //Assert.IsNull(properties.Get("grpc.keepalive_time_ms"));
                Assert.IsNull(properties.Get("grpc.keepalive_timeout_ms"));
                //Assert.IsNull(properties.Get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls"));
            }
        }
示例#3
0
        public void TestNewChannel()
        {
            // Should be able to instantiate a new instance of "Channel" with the definition in the network configuration'
            JObject jsonConfig = GetJsonConfig(1, 0, 1);

            NetworkConfig config = NetworkConfig.FromJsonObject(jsonConfig);

            HFClient client = HFClient.Create();

            TestHFClient.SetupClient(client);

            Channel channel = client.LoadChannelFromConfig(CHANNEL_NAME, config);

            Assert.IsNotNull(channel);
            Assert.AreEqual(CHANNEL_NAME, channel.Name);
            Assert.AreEqual(channel.GetPeers(PeerRole.SERVICE_DISCOVERY).Count, 1);
        }
示例#4
0
        public void TestLoadFromConfigFileYaml()
        {
            // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration
            string        f      = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate());
            NetworkConfig config = NetworkConfig.FromYamlFile(f);

            Assert.IsNotNull(config);

            HFClient client = HFClient.Create();

            client.CryptoSuite = Factory.Instance.GetCryptoSuite();
            client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID);

            Channel channel = client.LoadChannelFromConfig("foo", config);

            Assert.IsNotNull(channel);
        }
示例#5
0
        public void TestGetChannel()
        {
            // Should be able to instantiate a new instance of "Channel" with orderer, org and peer defined in the network configuration
            JObject jsonConfig = GetJsonConfig(4, 1, 1);

            NetworkConfig config = NetworkConfig.FromJsonObject(jsonConfig);

            HFClient client = HFClient.Create();

            TestHFClient.SetupClient(client);

            Channel channel = client.LoadChannelFromConfig(CHANNEL_NAME, config);

            //HFClient client = HFClient.loadFromConfig(jsonConfig);
            //TestHFClient.setupClient(client);

            //Channel channel = client.getChannel(CHANNEL_NAME);
            Assert.IsNotNull(channel);
            Assert.AreEqual(CHANNEL_NAME, channel.Name);

            IReadOnlyList <Orderer> orderers = channel.Orderers;

            Assert.IsNotNull(orderers);
            Assert.AreEqual(1, orderers.Count);

            Orderer orderer = orderers.First();

            Assert.AreEqual("orderer1.example.com", orderer.Name);

            IReadOnlyList <Peer> peers = channel.Peers;

            Assert.IsNotNull(peers);
            Assert.AreEqual(1, peers.Count);

            Peer peer = peers.First();

            Assert.AreEqual("peer0.org1.example.com", peer.Name);
        }
示例#6
0
文件: VeroChain.cs 项目: tgspn/Vero2
        private string chaincode = "vero";//"fabcar";

        public VeroChain(string username)
        {
            var user = SampleUser.Load(username, @"D:\Projetos\Hyperledger\fabcar\hfc-key-store\");

            client = Hyperledger.Fabric.SDK.HFClient.Create();
            var crypto = new Hyperledger.Fabric.SDK.Security.CryptoPrimitives();

            crypto.Store.AddCertificate(user.Enrollment.Cert);
            crypto.Init();
            client.CryptoSuite = crypto;

            client.UserContext = user;

            channel = client.NewChannel("mychannel");
            var peer = client.NewPeer("p1", $"grpc://{Program.ServerIP}:7051");

            channel.AddPeer(peer);

            var ordered = client.NewOrderer("o1", $"grpc://{Program.ServerIP}:7050");

            channel.AddOrderer(ordered);

            channel.Initialize();
        }
示例#7
0
        public void TestLoadFromConfigFileYamlOverrides()
        {
            // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration
            string        f      = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate());
            NetworkConfig config = NetworkConfig.FromYamlFile(f);

            foreach (string peerName in config.PeerNames)
            {
                Properties peerProperties = config.GetPeerProperties(peerName);

                //example of setting keepAlive to avoid timeouts on inactive http2 connections.
                // Under 5 minutes would require changes to server side to accept faster ping rates.
                peerProperties.Set("grpc.keepalive_time_ms", 5 * 60 * 1000);
                peerProperties.Set("grpc.keepalive_timeout_ms", 8 * 1000);
//            peerProperties.Set("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", "true");
                config.SetPeerProperties(peerName, peerProperties);
            }

            foreach (string orderName in config.OrdererNames)
            {
                Properties ordererProperties = config.GetOrdererProperties(orderName);
                ordererProperties.Set("grpc.max_receive_message_length", 9000000);
                //ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[] {false});
                config.SetOrdererProperties(orderName, ordererProperties);
            }

            //HFClient client = HFClient.loadFromConfig(f);
            Assert.IsNotNull(config);

            HFClient client = HFClient.Create();

            client.CryptoSuite = Factory.Instance.GetCryptoSuite();
            client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID);

            Channel channel = client.LoadChannelFromConfig("foo", config);

            Assert.IsNotNull(channel);

            Assert.IsTrue(channel.Peers.Count > 0);

            foreach (Peer peer in channel.Peers)
            {
                Properties properties = peer.Properties;

                Assert.IsNotNull(properties);
                Assert.IsNotNull(properties.Get("grpc.keepalive_time_ms"));
                Assert.IsNotNull(properties.Get("grpc.keepalive_timeout_ms"));
                //Assert.IsNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls"));

                Endpoint      ep               = new Endpoint(peer.Url, properties);
                ChannelOption keepalive        = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.keepalive_time_ms");
                ChannelOption keepalivetimeout = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.keepalive_timeout_ms");
                Assert.IsNotNull(keepalive);
                Assert.IsNotNull(keepalivetimeout);
                Assert.AreEqual(5 * 60 * 1000, keepalive.IntValue);
                Assert.AreEqual(8 * 1000, keepalivetimeout.IntValue);
            }

            foreach (Orderer orderer in channel.Orderers)
            {
                Properties properties = orderer.Properties;

                Assert.IsNotNull(properties);
                Assert.IsNotNull(properties.Get("grpc.max_receive_message_length"));
                //Assert.IsNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls"));

                Endpoint      ep    = new Endpoint(orderer.Url, properties);
                ChannelOption msize = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.max_receive_message_length");
                Assert.IsNotNull(msize);
                Assert.AreEqual(9000000, msize.IntValue);
            }
        }