private static bool CheckInstalledChaincode(HFClient client, Peer peer, string ccName, string ccPath, string ccVersion) { Util.COut("Checking installed chaincode: {0}, at version: {1}, on peer: {2}", ccName, ccVersion, peer.Name); List <ChaincodeInfo> ccinfoList = client.QueryInstalledChaincodes(peer); bool found = false; foreach (ChaincodeInfo ccifo in ccinfoList) { if (ccPath != null) { found = ccName.Equals(ccifo.Name) && ccPath.Equals(ccifo.Path) && ccVersion.Equals(ccifo.Version); if (found) { break; } } found = ccName.Equals(ccifo.Name) && ccVersion.Equals(ccifo.Version); if (found) { break; } } return(found); }
public static HFClient Create() { HFClient hfclient = HFClient.Create(); SetupClient(hfclient); return(hfclient); }
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")); } }
private void QueryChaincodeForExpectedValue(HFClient client, Channel channel, string expect, ChaincodeID chaincdeID) { Util.COut("Now query chaincode {0} on channel {1} for the value of b expecting to see: {2}", chaincdeID, channel.Name, expect); QueryByChaincodeRequest queryByChaincodeRequest = client.NewQueryProposalRequest(); queryByChaincodeRequest.SetArgs("b".ToBytes()); // test using bytes as args. End2end uses Strings. queryByChaincodeRequest.SetFcn("query"); queryByChaincodeRequest.ChaincodeID = chaincdeID; List <ProposalResponse> queryProposals; queryProposals = channel.QueryByChaincode(queryByChaincodeRequest); foreach (ProposalResponse proposalResponse in queryProposals) { if (!proposalResponse.IsVerified || proposalResponse.Status != ChaincodeResponse.ChaincodeResponseStatus.SUCCESS) { Assert.Fail($"Failed query proposal from peer {proposalResponse.Peer.Name} status: {proposalResponse.Status}. Messages: {proposalResponse.Message}. Was verified : {proposalResponse.IsVerified}"); } else { string payload = proposalResponse.ProtoProposalResponse.Response.Payload.ToStringUtf8(); Util.COut("Query payload of b from peer {0} returned {1}", proposalResponse.Peer.Name, payload); Assert.AreEqual(expect, payload, $"Failed compare on channel {channel.Name} chaincode id {chaincdeID} expected value:'{expect}', but got:'{payload}'"); } } }
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); } }
public UserManager() { keyStorePath = @"D:\Projetos\Hyperledger\fabcar\hfc-key-store\"; admin = SampleUser.Load("admin", keyStorePath); fabric_client = HFClient.Create(); var crypto = new Hyperledger.Fabric.SDK.Security.CryptoPrimitives(); crypto.Init(); crypto.Store.AddCertificate(admin.Enrollment.Cert); fabric_client.CryptoSuite = crypto; fabric_client.UserContext = admin; channel = fabric_client.NewChannel("mychannel"); var peer = fabric_client.NewPeer("p1", $"grpc://{Startup.HyperleaderServer}:7051"); channel.AddPeer(peer); var ordered = fabric_client.NewOrderer("o1", $"grpc://{Startup.HyperleaderServer}:7050"); channel.AddOrderer(ordered); channel.Initialize(); fabric_ca_client = new Hyperledger.Fabric_CA.SDK.HFCAClient("", $"http://{Startup.HyperleaderServer}:7054", new Hyperledger.Fabric.SDK.Helper.Properties()); fabric_ca_client.CryptoSuite = crypto; }
/** * Just for testing remove all peers and orderers and add them back. * * @param client * @param channel */ public static void TestRemovingAddingPeersOrderers(HFClient client, Channel channel) { Dictionary <Peer, PeerOptions> perm = new Dictionary <Peer, PeerOptions>(); Assert.IsTrue(channel.IsInitialized); Assert.IsFalse(channel.IsShutdown); Thread.Sleep(1500); // time needed let channel get config block channel.Peers.ToList().ForEach(peer => { perm[peer] = channel.GetPeersOptions(peer); channel.RemovePeer(peer); }); perm.Keys.ToList().ForEach(peer => { PeerOptions value = perm[peer]; Peer newPeer = client.NewPeer(peer.Name, peer.Url, peer.Properties); channel.AddPeer(newPeer, value); }); List <Orderer> removedOrders = new List <Orderer>(); foreach (Orderer orderer in channel.Orderers.ToList()) { channel.RemoveOrderer(orderer); removedOrders.Add(orderer); } removedOrders.ForEach(orderer => { Orderer newOrderer = client.NewOrderer(orderer.Name, orderer.Url, orderer.Properties); channel.AddOrderer(newOrderer); }); }
public void RunFabricTest(SampleStore sStore) { //////////////////////////// // Setup client //Create instance of client. HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); //////////////////////////// //Reconstruct and run the channels SampleOrg sampleOrg = testConfig.GetIntegrationTestsSampleOrg("peerOrg1"); Channel fooChannel = ReconstructChannel(FOO_CHANNEL_NAME, client, sampleOrg); RunChannel(client, fooChannel, sampleOrg, 0); Assert.IsFalse(fooChannel.IsShutdown); Assert.IsTrue(fooChannel.IsInitialized); fooChannel.Shutdown(true); //clean up resources no longer needed. Assert.IsTrue(fooChannel.IsShutdown); Util.COut("\n"); sampleOrg = testConfig.GetIntegrationTestsSampleOrg("peerOrg2"); Channel barChannel = ReconstructChannel(BAR_CHANNEL_NAME, client, sampleOrg); RunChannel(client, barChannel, sampleOrg, 100); //run a newly constructed foo channel with different b value! Assert.IsFalse(barChannel.IsShutdown); Assert.IsTrue(barChannel.IsInitialized); if (!testConfig.IsRunningAgainstFabric10()) { //Peer eventing service support started with v1.1 // Now test replay feature of V1.1 peer eventing services. string json = barChannel.Serialize(); barChannel.Shutdown(true); Channel replayChannel = client.DeSerializeChannel(json); Util.COut("doing testPeerServiceEventingReplay,0,-1,false"); TestPeerServiceEventingReplay(client, replayChannel, 0L, -1L, false); replayChannel = client.DeSerializeChannel(json); Util.COut("doing testPeerServiceEventingReplay,0,-1,true"); // block 0 is import to test TestPeerServiceEventingReplay(client, replayChannel, 0L, -1L, true); //Now do it again starting at block 1 replayChannel = client.DeSerializeChannel(json); Util.COut("doing testPeerServiceEventingReplay,1,-1,false"); TestPeerServiceEventingReplay(client, replayChannel, 1L, -1L, false); //Now do it again starting at block 2 to 3 replayChannel = client.DeSerializeChannel(json); Util.COut("doing testPeerServiceEventingReplay,2,3,false"); TestPeerServiceEventingReplay(client, replayChannel, 2L, 3L, false); } Util.COut("That's all folks!"); }
internal override Channel ConstructChannel(string name, HFClient client, SampleOrg sampleOrg) { // override this method since we don't want to construct the channel that's been done. // Just get it out of the samplestore! client.UserContext = sampleOrg.PeerAdmin; return(sampleStore.GetChannel(client, name).Initialize()); }
private static void QueryChaincodeForExpectedValue(HFClient client, Channel channel, string expect, ChaincodeID chaincodeID) { Util.COut("Now query chaincode on channel {0} for the value of b expecting to see: {1}", channel.Name, expect); string value = QueryChaincodeForCurrentValue(client, channel, chaincodeID); Assert.AreEqual(expect, value); }
public void TestBadUserContextNull() { HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = null; }
public void TestBadUserNameNull() { HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); TestUtils.TestUtils.MockUser mockUser = TestUtils.TestUtils.GetMockUser(null, USER_MSP_ID); client.UserContext = mockUser; }
public void TestGoodMockUser() { HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); Orderer orderer = hfclient.NewOrderer("justMockme", "grpc://localhost:99"); // test mock should work. Assert.IsNotNull(orderer); }
public void TestBadEnrollmentNull() { HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); TestUtils.TestUtils.MockUser mockUser = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); mockUser.Enrollment = null; client.UserContext = mockUser; }
public void TestBadUserMSPIDNull() { HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); TestUtils.TestUtils.MockUser mockUser = TestUtils.TestUtils.GetMockUser(USER_NAME, null); client.UserContext = mockUser; }
public static void SetupClient(TestContext context) { try { hfclient = TestHFClient.Create(); } catch (System.Exception e) { Assert.Fail($"Unexpected Exception {e.Message}"); } }
// Returns a new client instance private static HFClient GetTheClient() { HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); IUser peerAdmin = GetAdminUser(TEST_ORG); client.UserContext = peerAdmin; return(client); }
private static Channel ConstructChannel(HFClient client, string channelName) { //Channel newChannel = client.GetChannel(channelName); Channel newChannel = client.LoadChannelFromConfig(channelName, networkConfig); if (newChannel == null) { throw new System.Exception("Channel " + channelName + " is not defined in the config file!"); } return(newChannel.Initialize()); }
public static void SetupClient(TestContext context) { try { hfclient = TestHFClient.Create(); peer = hfclient.NewPeer(PEER_NAME, "grpc://localhost:7051"); } catch (System.Exception e) { Assert.Fail($"Unexpected Exception {e.Message}"); } }
public Channel GetChannel(HFClient client, string name) { Channel ret = null; string channelHex = GetValue("channel." + name); if (channelHex != null) { ret = client.DeSerializeChannel(channelHex.FromHexString().ToUTF8String()); } return(ret); }
public void TestBadEnrollmentBadKey() { HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); TestUtils.TestUtils.MockUser mockUser = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); IEnrollment mockEnrollment = TestUtils.TestUtils.GetMockEnrollment(null, "mockCert"); mockUser.Enrollment = mockEnrollment; client.UserContext = mockUser; }
public void TestUpdate1() { // Setup client and channel instances HFClient client = GetTheClient(); Channel channel = ConstructChannel(client, FOO_CHANNEL_NAME); ChaincodeID chaincodeID = new ChaincodeID().SetName(CHAIN_CODE_NAME).SetVersion(CHAIN_CODE_VERSION).SetPath(CHAIN_CODE_PATH); string channelName = channel.Name; Util.COut("Running testUpdate1 - Channel %s", channelName); int moveAmount = 5; string originalVal = QueryChaincodeForCurrentValue(client, channel, chaincodeID); string newVal = "" + (int.Parse(originalVal) + moveAmount); Util.COut("Original value = {0}", originalVal); //user registered user client.UserContext = orgRegisteredUsers.GetOrNull("Org1"); // only using org1 // Move some assets try { MoveAmount(client, channel, chaincodeID, "a", "b", "" + moveAmount, null); QueryChaincodeForExpectedValue(client, channel, newVal, chaincodeID); MoveAmount(client, channel, chaincodeID, "b", "a", "" + moveAmount, null); QueryChaincodeForExpectedValue(client, channel, originalVal, chaincodeID); } catch (TransactionEventException t) { TransactionEvent te = t.TransactionEvent; if (te != null) { Assert.Fail($"Transaction with txid {te.TransactionID} failed. {t.Message}"); } Assert.Fail($"Transaction failed with exception message {t.Message}"); } catch (System.Exception e) { Assert.Fail($"Test failed with {e.GetType().Name} exception {e.Message}"); } channel.Shutdown(true); // Force channel to shutdown clean up resources. Util.COut("testUpdate1 - done"); Util.COut("That's all folks!"); }
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); }
// Determines whether or not the chaincode has been deployed and deploys it if necessary private static void DeployChaincodeIfRequired() { //////////////////////////// // Setup client HFClient client = GetTheClient(); Channel channel = ConstructChannel(client, FOO_CHANNEL_NAME); // Use any old peer... Peer peer = channel.Peers.First(); if (!CheckInstantiatedChaincode(channel, peer, CHAIN_CODE_NAME, CHAIN_CODE_PATH, CHAIN_CODE_VERSION)) { // The chaincode we require does not exist, so deploy it... DeployChaincode(client, channel, CHAIN_CODE_NAME, CHAIN_CODE_PATH, CHAIN_CODE_VERSION); } }
public void TestGetChannelNotExists() { // 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); client.LoadChannelFromConfig("MissingChannel", config); }
public void TestCryptoFactory() { TestUtils.TestUtils.ResetConfig(); Assert.IsNotNull(Config.Instance.GetDefaultCryptoSuiteFactory()); HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); TestUtils.TestUtils.MockUser mockUser = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); IEnrollment mockEnrollment = TestUtils.TestUtils.GetMockEnrollment(null, "mockCert"); mockUser.Enrollment = mockEnrollment; client.UserContext = mockUser; }
public static void SetupClient(TestContext context) { try { hfclient = TestHFClient.Create(); shutdownChannel = new Channel("shutdown", hfclient); shutdownChannel.AddOrderer(hfclient.NewOrderer("shutdow_orderer", "grpc://localhost:99")); shutdownChannel.IsShutdown = true; throwOrderer = new ThrowOrderer("foo", "grpc://localhost:8", null); throwChannel = new Channel("throw", hfclient); throwChannel.AddOrderer(throwOrderer); } catch (System.Exception e) { Assert.Fail($"Unexpected Exception {e.Message}"); } }
public void TestGetChannelNoPeers() { // Should not be able to instantiate a new instance of "Channel" with no peers configured JObject jsonConfig = GetJsonConfig(1, 1, 0); NetworkConfig config = NetworkConfig.FromJsonObject(jsonConfig); HFClient client = HFClient.Create(); TestHFClient.SetupClient(client); client.LoadChannelFromConfig(CHANNEL_NAME, config); //HFClient client = HFClient.loadFromConfig(jsonConfig); //TestHFClient.setupClient(client); //client.getChannel(CHANNEL_NAME); }
public void TestLoadFromConfigFileJson() { // Should be able to instantiate a new instance of "Client" with a valid path to the JSON configuration string f = TestUtils.TestUtils.RelocateFilePathsJSON("fixture/sdkintegration/network_configs/network-config.json".Locate()); NetworkConfig config = NetworkConfig.FromJsonFile(f); Assert.IsNotNull(config); //HFClient client = HFClient.loadFromConfig(f); //Assert.Assert.IsNotNull(client); HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); Channel channel = client.LoadChannelFromConfig("mychannel", config); Assert.IsNotNull(channel); }
public static void SetupClient(HFClient hfclient) { ICryptoSuite cryptoSuite = Factory.GetCryptoSuite(); string props = Path.Combine(GetHomePath(), "test.properties"); if (File.Exists(props)) { File.Delete(props); } SampleStore sampleStore = new SampleStore(props); //src/test/fixture/sdkintegration/e2e-2Orgs/channel/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/ //SampleUser someTestUSER = sampleStore.getMember("someTestUSER", "someTestORG"); SampleUser someTestUSER = sampleStore.GetMember("someTestUSER", "someTestORG", "mspid", FindFileSk("fixture/sdkintegration/e2e-2Orgs/" + TestConfig.Instance.FAB_CONFIG_GEN_VERS + "/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore"), ("fixture/sdkintegration/e2e-2Orgs/" + TestConfig.Instance.FAB_CONFIG_GEN_VERS + "/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]").Locate()); someTestUSER.MspId = "testMSPID?"; hfclient.CryptoSuite = Factory.Instance.GetCryptoSuite(); hfclient.UserContext = someTestUSER; }