def test_build_header(self): timestamp = utils.current_timestamp() client = Client() client.state_store = FileKeyValueStore(self.kv_store_path) orderer_org_admin = get_orderer_org_admin(client) orderer_org_admin_tx_context = \ TXContext(orderer_org_admin, Ecies(), {}) client.tx_context = orderer_org_admin_tx_context orderer_org_admin_serialized = utils.create_serialized_identity( orderer_org_admin) serialized_identity = identities_pb2.SerializedIdentity() serialized_identity.ParseFromString(orderer_org_admin_serialized) proto_channel_header = utils.build_channel_header( common_pb2.HeaderType.Value('CONFIG_UPDATE'), orderer_org_admin_tx_context.tx_id, self.channel_id, timestamp ) channel_header = utils.build_header( orderer_org_admin_tx_context.identity, proto_channel_header, orderer_org_admin_tx_context.nonce ) self.assertIsInstance(channel_header, common_pb2.Header)
def test_string_to_signature(self): with open(self.channel_tx, 'rb') as f: channel_tx = f.read() channel_config = utils.extract_channel_config(channel_tx) client = Client() client.state_store = FileKeyValueStore(self.kv_store_path) orderer_org_admin = get_orderer_org_admin(client) orderer_org_admin_tx_context = \ TXContext(orderer_org_admin, Ecies(), {}) client.tx_context = orderer_org_admin_tx_context orderer_org_admin_signature = client.sign_channel_config( channel_config) orderer_org_admin_signature_bytes = \ orderer_org_admin_signature.SerializeToString() proto_signature = utils.string_to_signature( [orderer_org_admin_signature_bytes]) self.assertIsInstance(proto_signature, list) self.assertTrue( 'OrdererMSP' in proto_signature[0].signature_header.__str__())
def test_create_serialized_identity(self): client = Client() client.state_store = FileKeyValueStore(self.kv_store_path) orderer_org_admin = get_orderer_org_admin(client) orderer_org_admin_serialized = utils.create_serialized_identity( orderer_org_admin) serialized_identity = identities_pb2.SerializedIdentity() serialized_identity.ParseFromString(orderer_org_admin_serialized) self.assertEqual(serialized_identity.mspid, self.orderer_org_mspid)
def join_channel(self): # sleep 5 seconds for channel created time.sleep(5) client = Client() client.state_store = FileKeyValueStore(self.kv_store_path + 'join-channel') channel = client.new_channel(self.channel_name) logger.info("start to join channel") orgs = ["org1.example.com", "org2.example.com"] for org in orgs: request = build_join_channel_req(org, channel, client) assert (request) # result = True and channel.join_channel(request) logger.info("peers in org: %s join channel: %", org, self.channel_name) logger.info("joining channel tested succefully") client.state_store = None
def create_channel(self): client = Client() client.state_store = FileKeyValueStore(self.kv_store_path + 'build-channel') logger.info("start to create channel") request = build_channel_request(client, self.channel_tx, self.channel_name) q = Queue(1) response = client.create_channel(request) response.subscribe(on_next=lambda x: q.put(x), on_error=lambda x: q.put(x)) status, _ = q.get(timeout=5) self.assertEqual(status.status, 200) logger.info("successfully create the channel: %s", self.channel_name) client.state_store = None
def join_channel(self): # wait for channel created time.sleep(5) client = Client('test/fixtures/network.json') channel = client.new_channel(self.channel_name) logger.info("start to join channel") orgs = ["org1.example.com", "org2.example.com"] done = True for org in orgs: client.state_store = FileKeyValueStore( self.client.kv_store_path + org) request = build_join_channel_req(org, channel, client) done = done and channel.join_channel(request) if done: logger.info("peers in org: %s join channel: %s.", org, self.channel_name) if done: logger.info("joining channel tested successfully.") client.state_store = None assert(done)
def create_channel(self): client = Client('test/fixtures/network.json') logger.info("start to create channel") request = build_channel_request( client, self.channel_tx, self.channel_name) q = Queue(1) response = client._create_channel(request) response.subscribe(on_next=lambda x: q.put(x), on_error=lambda x: q.put(x)) status, _ = q.get(timeout=5) self.assertEqual(status.status, 200) logger.info("successfully create the channel: %s", self.channel_name) client.state_store = None