Exemple #1
0
    def test_instantiate_chaincode(self):

        channel = self.client.new_channel(self.channel_name)
        org1 = 'org1.example.com'
        peer_config = test_network['org1.example.com']['peers']['peer0']
        tls_cacerts = peer_config['tls_cacerts']
        opts = (('grpc.ssl_target_name_override',
                 peer_config['server_hostname']), )
        endpoint = peer_config['grpc_request_endpoint']

        peer = create_peer(endpoint=endpoint,
                           tls_cacerts=tls_cacerts,
                           opts=opts)

        org1_admin = get_peer_org_user(org1, 'Admin', self.client.state_store)
        crypto = ecies()

        # for chain code install
        tran_prop_req_in = create_tx_prop_req(prop_type=CC_INSTALL,
                                              cc_path=CC_PATH,
                                              cc_type=CC_TYPE_GOLANG,
                                              cc_name=CC_NAME,
                                              cc_version=CC_VERSION)

        # install chain code
        tx_context_in = create_tx_context(org1_admin, crypto, tran_prop_req_in)

        # for chain code deploy
        args = ['a', '100', 'b', '40']
        tran_prop_req_dep = create_tx_prop_req(prop_type=CC_INSTANTIATE,
                                               cc_type=CC_TYPE_GOLANG,
                                               cc_name=CC_NAME,
                                               cc_version=CC_VERSION,
                                               args=args,
                                               fcn='init')

        # deploy the chain code
        tx_context_dep = create_tx_context(org1_admin, crypto,
                                           tran_prop_req_dep)

        # create a channel
        request = build_channel_request(self.client, self.channel_tx,
                                        self.channel_name)

        self.client._create_channel(request)

        # join channel
        join_req = build_join_channel_req(org1, channel, self.client)
        channel.join_channel(join_req)

        self.client.send_install_proposal(tx_context_in, [peer])

        # send the transaction to the channel
        res = channel.send_instantiate_proposal(tx_context_dep, [peer])
        tran_req = build_tx_req(res)

        tx_context = create_tx_context(org1_admin, crypto, TXProposalRequest())
        response = send_transaction(channel.orderers, tran_req, tx_context)

        self.assertEqual(response[0].status, 200)
Exemple #2
0
    def test_instantiate_chaincode(self):

        peer_config = test_network['org1.example.com']['peers']['peer0']
        tls_cacerts = peer_config['tls_cacerts']
        endpoint = peer_config['grpc_request_endpoint']

        opts = (('grpc.ssl_target_name_override',
                 peer_config['server_hostname']), )

        peer = create_peer(endpoint=endpoint,
                           tls_cacerts=tls_cacerts,
                           opts=opts)

        tran_prop_req_in = create_tx_prop_req(prop_type=CC_INSTALL,
                                              cc_path=CC_PATH,
                                              cc_type=CC_TYPE_GOLANG,
                                              cc_name=CC_NAME,
                                              cc_version=CC_VERSION)
        args = ['a', '100', 'b', '40']
        tran_prop_req_dep = create_tx_prop_req(prop_type=CC_INSTANTIATE,
                                               cc_type=CC_TYPE_GOLANG,
                                               cc_name=CC_NAME,
                                               cc_version=CC_VERSION,
                                               fcn='init',
                                               args=args)

        org1 = 'org1.example.com'
        crypto = ecies()
        org1_admin = get_peer_org_user(org1, 'Admin', self.client.state_store)
        tx_context_in = create_tx_context(org1_admin, crypto, tran_prop_req_in)

        request = build_channel_request(self.client, self.channel_tx,
                                        self.channel_name)

        res = self.client._create_channel(request)
        q = Queue(1)
        res.subscribe(on_next=lambda x: q.put(x), on_error=lambda x: q.put(x))
        status, _ = q.get(timeout=5)
        if status.status == 200:
            logger.info("create channel successfully")

        time.sleep(5)
        channel = self.client.new_channel(self.channel_name)
        join_req = build_join_channel_req(org1, channel, self.client)
        channel.join_channel(join_req)

        res = self.client.send_install_proposal(tx_context_in, [peer])
        res.subscribe(on_next=lambda x: q.put(x), on_error=lambda x: q.put(x))
        status, _ = q.get(timeout=5)[0][0]
        if status.response.status == 200:
            logger.info("chaincode installed successfully")

        time.sleep(5)
        tx_context_dep = create_tx_context(org1_admin, crypto,
                                           tran_prop_req_dep)
        res = channel.send_instantiate_proposal(tx_context_dep, [peer])
        assert (res)
    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
Exemple #4
0
    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)
Exemple #5
0
    def test_invoke_chaincode_sucess(self):

        channel = self.client.new_channel(self.channel_name)
        org1 = "org1.example.com"
        peer_config = test_network['org1.example.com']['peers']['peer0']
        tls_cacerts = peer_config['tls_cacerts']
        opts = (('grpc.ssl_target_name_override',
                 peer_config['server_hostname']), )
        endpoint = peer_config['grpc_request_endpoint']
        org1_peer = create_peer(endpoint=endpoint,
                                tls_cacerts=tls_cacerts,
                                opts=opts)
        org1_admin = get_peer_org_user(org1, "Admin", self.client.state_store)

        crypto = ecies()
        tran_prop_req_install = create_tx_prop_req(prop_type=CC_INSTALL,
                                                   cc_path=CC_PATH,
                                                   cc_type=CC_TYPE_GOLANG,
                                                   cc_name=CC_NAME,
                                                   cc_version=CC_VERSION)
        tx_context_install = create_tx_context(org1_admin, crypto,
                                               tran_prop_req_install)

        args_dep = ['a', '200', 'b', '300']
        tran_prop_req_dep = create_tx_prop_req(prop_type=CC_INSTANTIATE,
                                               cc_type=CC_TYPE_GOLANG,
                                               cc_name=CC_NAME,
                                               cc_version=CC_VERSION,
                                               args=args_dep,
                                               fcn='init')

        tx_context_dep = create_tx_context(org1_admin, crypto,
                                           tran_prop_req_dep)

        args = ['a', 'b', '100']
        tran_prop_req = create_tx_prop_req(prop_type=CC_INVOKE,
                                           cc_type=CC_TYPE_GOLANG,
                                           cc_name=CC_NAME,
                                           cc_version=CC_VERSION,
                                           fcn='invoke',
                                           args=args)
        tx_context = create_tx_context(org1_admin, crypto, tran_prop_req)

        request = build_channel_request(self.client, self.channel_tx,
                                        self.channel_name)
        self.client._create_channel(request)
        sleep(5)

        join_req = build_join_channel_req(org1, channel, self.client)
        channel.join_channel(join_req)
        sleep(5)

        self.client.send_install_proposal(tx_context_install, [org1_peer])
        sleep(5)

        res = channel.send_instantiate_proposal(tx_context_dep, [org1_peer])
        sleep(5)

        tran_req = build_tx_req(res)
        send_transaction(channel.orderers, tran_req, tx_context)
        sleep(5)

        tx_context_tx = create_tx_context(org1_admin, crypto,
                                          TXProposalRequest())
        res = channel.send_tx_proposal(tx_context, [org1_peer])

        tran_req = build_tx_req(res)
        response = send_transaction(channel.orderers, tran_req, tx_context_tx)
        q = Queue(1)
        response.subscribe(on_next=lambda x: q.put(x),
                           on_error=lambda x: q.put(x))
        res, _ = q.get(timeout=5)
        self.assertEqual(res.status, 200)
    def test_invoke_chaincode_sucess(self):
        loop = asyncio.get_event_loop()

        channel = self.client.new_channel(self.channel_name)
        org1 = "org1.example.com"
        peer_config = test_network['org1.example.com']['peers']['peer0']
        tls_cacerts = peer_config['tls_cacerts']
        opts = (('grpc.ssl_target_name_override',
                 peer_config['server_hostname']), )
        endpoint = peer_config['grpc_request_endpoint']
        org1_peer = create_peer(endpoint=endpoint,
                                tls_cacerts=tls_cacerts,
                                opts=opts)
        org1_admin = get_peer_org_user(org1, "Admin", self.client.state_store)

        crypto = ecies()
        tran_prop_req_install = create_tx_prop_req(prop_type=CC_INSTALL,
                                                   cc_path=CC_PATH,
                                                   cc_type=CC_TYPE_GOLANG,
                                                   cc_name=CC_NAME,
                                                   cc_version=CC_VERSION)
        tx_context_install = create_tx_context(org1_admin, crypto,
                                               tran_prop_req_install)

        args_dep = ['a', '200', 'b', '300']
        tran_prop_req_dep = create_tx_prop_req(prop_type=CC_INSTANTIATE,
                                               cc_type=CC_TYPE_GOLANG,
                                               cc_name=CC_NAME,
                                               cc_version=CC_VERSION,
                                               args=args_dep,
                                               fcn='init')

        tx_context_dep = create_tx_context(org1_admin, crypto,
                                           tran_prop_req_dep)

        args = ['a', 'b', '100']
        tran_prop_req = create_tx_prop_req(prop_type=CC_INVOKE,
                                           cc_type=CC_TYPE_GOLANG,
                                           cc_name=CC_NAME,
                                           fcn='invoke',
                                           args=args)
        tx_context = create_tx_context(org1_admin, crypto, tran_prop_req)

        request = build_channel_request(self.client, self.channel_tx,
                                        self.channel_name)
        loop.run_until_complete(self.client._create_or_update_channel(request))

        join_req = loop.run_until_complete(
            build_join_channel_req(org1, channel, self.client))
        responses = channel.join_channel(join_req)
        res = loop.run_until_complete(asyncio.gather(*responses))
        self.assertTrue(all([x.response.status == 200 for x in res]))

        responses, proposal, header = self.client.send_install_proposal(
            tx_context_install, [org1_peer])
        loop.run_until_complete(asyncio.gather(*responses))

        responses, proposal, header = channel.send_instantiate_proposal(
            tx_context_dep, [org1_peer])
        res = loop.run_until_complete(asyncio.gather(*responses))

        tran_req = build_tx_req((res, proposal, header))
        send_transaction(channel.orderers, tran_req, tx_context)
        loop.run_until_complete(
            get_stream_result(
                send_transaction(channel.orderers, tran_req, tx_context)))

        tx_context_tx = create_tx_context(org1_admin, crypto,
                                          TXProposalRequest())
        responses, proposal, header = channel.send_tx_proposal(
            tx_context, [org1_peer])
        res = loop.run_until_complete(asyncio.gather(*responses))

        tran_req = build_tx_req((res, proposal, header))

        responses = loop.run_until_complete(
            get_stream_result(
                send_transaction(channel.orderers, tran_req, tx_context_tx)))

        self.assertTrue(all([x.status == 200 for x in responses]))
Exemple #7
0
    def invoke_chaincode(self):

        self.channel = self.client.new_channel(self.channel_name)
        org1 = "org1.example.com"
        peer_config = test_network['org1.example.com']['peers']['peer0']
        tls_cacerts = peer_config['tls_cacerts']
        opts = (('grpc.ssl_target_name_override',
                 peer_config['server_hostname']), )
        endpoint = peer_config['grpc_request_endpoint']
        self.org1_peer = create_peer(endpoint=endpoint,
                                     tls_cacerts=tls_cacerts,
                                     opts=opts)
        self.org1_admin = get_peer_org_user(org1, "Admin",
                                            self.client.state_store)

        crypto = ecies()
        tran_prop_req_install = create_tx_prop_req(prop_type=CC_INSTALL,
                                                   cc_path=CC_PATH,
                                                   cc_type=CC_TYPE_GOLANG,
                                                   cc_name=CC_NAME,
                                                   cc_version=CC_VERSION)
        tx_context_install = create_tx_context(self.org1_admin, crypto,
                                               tran_prop_req_install)

        args_dep = ['a', '200', 'b', '300']
        tran_prop_req_dep = create_tx_prop_req(prop_type=CC_INSTANTIATE,
                                               cc_type=CC_TYPE_GOLANG,
                                               cc_name=CC_NAME,
                                               cc_version=CC_VERSION,
                                               args=args_dep,
                                               fcn='init')

        tx_context_dep = create_tx_context(self.org1_admin, crypto,
                                           tran_prop_req_dep)

        args = ['a', 'b', '100']
        tran_prop_req = create_tx_prop_req(prop_type=CC_INVOKE,
                                           cc_type=CC_TYPE_GOLANG,
                                           cc_name=CC_NAME,
                                           cc_version=CC_VERSION,
                                           fcn='invoke',
                                           args=args)
        tx_context = create_tx_context(self.org1_admin, crypto, tran_prop_req)

        request = build_channel_request(self.client, self.channel_tx,
                                        self.channel_name)
        self.client._create_channel(request)

        join_req = build_join_channel_req(org1, self.channel, self.client)
        self.channel.join_channel(join_req)

        self.client.send_install_proposal(tx_context_install, [self.org1_peer])

        res = self.channel.send_instantiate_proposal(tx_context_dep,
                                                     [self.org1_peer])
        tran_req = build_tx_req(res)
        send_transaction(self.channel.orderers, tran_req, tx_context)

        tx_context_tx = create_tx_context(self.org1_admin, crypto,
                                          TXProposalRequest())

        res = self.channel.send_tx_proposal(tx_context, [self.org1_peer])

        tran_req = build_tx_req(res)

        res = send_transaction(self.channel.orderers, tran_req, tx_context_tx)

        tx_id = tx_context_dep.tx_id

        return tx_id