def test_create_serialized_identity(self): client = Client('test/fixtures/network.json') orderer_org_admin = get_orderer_org_user( state_store=client.state_store) 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 build_channel_request(client, channel_tx, channel_name): """ Args: client: the client instance channel_tx: channel config file channel_name: channel name return channel request to create a channel """ signatures = [] prop_req = TXProposalRequest() with open(channel_tx, 'rb') as f: envelope = f.read() config = utils.extract_channel_config(envelope) orderer_config = net_config['orderer'] orderer = Orderer( endpoint=orderer_config['grpc_endpoint'], tls_ca_cert_file=orderer_config['tls_cacerts'], opts=(('grpc.ssl_target_name_override', 'orderer.example.com'), ), ) orderer_admin = get_orderer_org_user(state_store=client.state_store) orderer_tx_context = TXContext(orderer_admin, ecies(), prop_req, {}) client.tx_context = orderer_tx_context orderer_admin_signature = client.sign_channel_config(config) signatures.append(orderer_admin_signature) tx_id = orderer_tx_context.tx_id nonce = orderer_tx_context.nonce org1_admin = get_peer_org_user('org1.example.com', "Admin", client.state_store) org1_tx_context = TXContext(org1_admin, ecies(), prop_req, {}) client.tx_context = org1_tx_context org1_admin_signature = client.sign_channel_config(config) signatures.append(org1_admin_signature) org2_admin = get_peer_org_user('org2.example.com', "Admin", client.state_store) org2_tx_context = TXContext(org2_admin, ecies(), prop_req, {}) client.tx_context = org2_tx_context org2_admin_signature = client.sign_channel_config(config) signatures.append(org2_admin_signature) request = { 'config': config, 'signatures': signatures, 'channel_name': channel_name, 'orderer': orderer, 'tx_id': tx_id, 'nonce': nonce } return request
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('test/fixtures/network.json') orderer_org_admin = get_orderer_org_user( state_store=client.state_store) 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) proto_signature = utils.string_to_signature( [orderer_org_admin_signature]) self.assertIsInstance(proto_signature, list) self.assertTrue( 'OrdererMSP' in proto_signature[0].signature_header.__str__())
def test_build_header(self): timestamp = utils.current_timestamp() client = Client('test/fixtures/network.json') orderer_org_admin = get_orderer_org_user( state_store=client.state_store) 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 build_join_channel_req(org, channel, client): """ For test, there is only one peer. Args: org: org channel: the channel to join client: client instance Return: return request for joining channel """ def block_event_callback(block): pass client._crypto_suite = ecies() request = {} tx_prop_req = TXProposalRequest() # add the orderer orderer_config = test_network['orderer'] endpoint = orderer_config['grpc_endpoint'] ca_root_path = orderer_config['tls_cacerts'] orderer = Orderer(endpoint=endpoint, tls_ca_cert_file=ca_root_path, opts=(('grpc.ssl_target_name_override', 'orderer.example.com'),)) channel.add_orderer(orderer) # get the genesis block orderer_admin = get_orderer_org_user(state_store=client.state_store) tx_context = TXContext(orderer_admin, ecies(), tx_prop_req) client.tx_context = tx_context genesis_block = channel.get_genesis_block().SerializeToString() # create the peer org_admin = get_peer_org_user(org, "Admin", client.state_store) client.tx_context = TXContext(org_admin, ecies(), tx_prop_req) tx_id = client.tx_context.tx_id peer_config = test_network[org]["peers"]['peer0'] ca_root = peer_config["tls_cacerts"] endpoint = peer_config["grpc_request_endpoint"] opts = (('grpc.ssl_target_name_override', peer_config['server_hostname']),) peer = Peer(endpoint=endpoint, tls_cacerts=ca_root, opts=opts) """ # connect the peer eh = EventHub() event = peer_config['grpc_event_endpoint'] tx_id = client.tx_context.tx_id eh.set_peer_addr(event) eh.connect() eh.register_block_event(block_event_callback) all_ehs.append(eh) """ request["targets"] = [peer] request["block"] = genesis_block request["tx_id"] = tx_id request["transient_map"] = {} return request