Esempio n. 1
0
#

import os
import asyncio
from hfc.fabric import Client
from hfc.fabric.channel.channel import SYSTEM_CHANNEL_NAME

CONNECTION_PROFILE_PATH = 'test/fixtures/network.json'
CONFIG_YAML_PATH = 'test/fixtures/e2e_cli/'
CHAINCODE_PATH = 'test/fixtures/chaincode'
CC_PATH = 'github.com/example_cc_with_event'
CC_NAME = 'example_cc_with_event'
CC_VERSION = '1.0'

if __name__ == "__main__":
    cli = Client(net_profile=CONNECTION_PROFILE_PATH)
    loop = asyncio.get_event_loop()

    print(cli.organizations)  # orgs in the network
    print(cli.peers)  # peers in the network
    print(cli.orderers)  # orderers in the network
    print(cli.CAs)  # ca nodes in the network, TODO

    # get the admin user from local path
    org1_admin = cli.get_user(org_name='org1.example.com', name='Admin')

    # Create a New Channel, the response should be true if succeed
    response = loop.run_until_complete(
        cli.channel_create(orderer='orderer.example.com',
                           channel_name='businesschannel',
                           requestor=org1_admin,
Esempio n. 2
0
import asyncio
from hfc.fabric import Client

loop = asyncio.get_event_loop()

cli = Client(net_profile="test/fixtures/network.json")
org1_admin = cli.get_user(org_name='org1.example.com', name='Admin')

# Create a New Channel, the response should be true if succeed
response = loop.run_until_complete(
    cli.channel_create(orderer='orderer.example.com',
                       channel_name='businesschannel',
                       requestor=org1_admin,
                       config_yaml='test/fixtures/e2e_cli/',
                       channel_profile='TwoOrgsChannel'))
print(response == True)
Esempio n. 3
0
# -*- coding: utf-8 -*-
"""
    Fabric v1.4 API Server (Using Fabric Python SDK)
    ~~~~~~~~

    Automatic Transaction Generator

    :author: Jason Liu
"""
from hfc.fabric import Client
import asyncio
import time

loop = asyncio.get_event_loop()
cli = Client(net_profile="./network.json")

print(cli.organizations)  # orgs in the network
print(cli.peers)  # peers in the network
print(cli.orderers)  # orderers in the network
print(cli.CAs)  # ca nodes in the network
cli.new_channel('mychannel')
org1_admin = cli.get_user(org_name='org1.example.com', name='Admin') # get the admin user from local path
args = ["212344", "red", "202", "Jack"]
#args2 = ["GetBlockByTxID", "mychannel", "64caff9786483d0d56f6d7ba738ece33328c2559b7b4093547018bcd22e42986"]
# The response should be true if succeed
response = loop.run_until_complete(cli.query_instantiated_chaincodes(
               requestor=org1_admin,
               channel_name='mychannel',
               peers=['peer0.org1.example.com'],
               decode=True
               ))
from example_chaincode import OperateChaincode
from hfc.fabric import Client

cli = Client(net_profile="example_server_network.json")
org1_admin = cli.get_user('org1.example.com', 'Admin')

# definition operator and chaincode
OC = OperateChaincode(org1_admin, 'mychannel', ['peer0.org1.example.com'],
                      'mycc')

#transactionID := args[0]
args = ("0000000000100000")
# response the query
resp = OC.groupbuyBlocked_failed([*args])
print(resp)
Esempio n. 5
0
    def test_discovery(self):
        loop = asyncio.get_event_loop()

        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)

        # Channel create
        response = loop.run_until_complete(
            self.client.channel_create('orderer.example.com',
                                       self.channel_name,
                                       self.user,
                                       config_yaml=self.config_yaml,
                                       channel_profile=self.channel_profile))
        logger.debug(response)
        self.assertTrue(response)

        # Channel join
        channel = self.client.get_channel(self.channel_name)
        self.assertIsNotNone(channel)

        response = loop.run_until_complete(
            self.client.channel_join(requestor=self.user,
                                     channel_name=self.channel_name,
                                     peers=['peer0.' + org1, 'peer1.' + org1],
                                     orderer='orderer.example.com'))
        self.assertTrue(response)

        # CC install
        responses = loop.run_until_complete(
            self.client.chaincode_install(
                requestor=self.user,
                peers=['peer0.' + org1, 'peer1.' + org1],
                cc_path=CC_PATH,
                cc_name=CC_NAME,
                cc_version=CC_VERSION))
        self.assertTrue(responses)

        # CC instantiate
        args = ['a', '200', 'b', '300']
        response = loop.run_until_complete(
            self.client.chaincode_instantiate(requestor=self.user,
                                              channel_name=self.channel_name,
                                              peers=['peer0.' + org1],
                                              args=args,
                                              cc_name=CC_NAME,
                                              cc_version=CC_VERSION,
                                              wait_for_event=True))
        logger.debug(response)
        self.assertTrue(response)

        # Query instantiated cc
        responses = loop.run_until_complete(
            self.client.query_instantiated_chaincodes(
                requestor=self.user,
                channel_name=self.channel_name,
                peers=['peer0.' + org1, 'peer1.' + org1]))
        logger.debug(responses)
        self.assertEqual(len(responses), 2)
        '''[chaincodes {
           name: "example_cc"
           version: "1.0"
           path: "github.com/example_cc"
           input: "<nil>"
           escc: "escc"
           vscc: "vscc"
        }
        , chaincodes {
           name: "example_cc"
           version: "1.0"
           path: "github.com/example_cc"
           input: "<nil>"
           escc: "escc"
           vscc: "vscc"
        }
        ]'''

        # sleep 3 seconds for having all peers for discovery
        loop.run_until_complete(sleep(3))

        # TEST: config
        # this one contain 3 queries
        response = loop.run_until_complete(
            channel._discovery(requestor=self.user,
                               target=peer,
                               config=True,
                               interests=[{
                                   'chaincodes': [{
                                       'name': CC_NAME
                                   }]
                               }]))

        self.assertEqual(
            response.results[1].config_result.msps['OrdererMSP'].name,
            'OrdererMSP')
        self.assertEqual(
            list(response.results[0].members.peers_by_org.keys())[0],
            'Org1MSP')
        self.assertEqual(response.results[2].cc_query_res.content[0].chaincode,
                         CC_NAME)

        # TEST: query_peer
        results = loop.run_until_complete(
            self.client.query_peers(self.user, peer))
        self.assertEqual(len(results['local_peers']['Org1MSP']['peers']), 2)
        self.assertEqual(
            results['local_peers']['Org1MSP']['peers'][0]['endpoint'],
            'peer0.org1.example.com:7051')
        self.assertEqual(
            results['local_peers']['Org1MSP']['peers'][1]['endpoint'],
            'peer1.org1.example.com:7051')

        # Test init with discovery

        client_discovery = Client()

        loop.run_until_complete(
            client_discovery.init_with_discovery(self.user, peer,
                                                 self.channel_name))

        self.assertEqual(len(client_discovery._orderers), 1)
        self.assertEqual(len(client_discovery._peers), 3)
        self.assertEqual(len(client_discovery._organizations), 3)
Esempio n. 6
0
import os
import asyncio
from hfc.fabric import Client

loop = asyncio.get_event_loop()

cli = Client(net_profile="../connection-profile/network.json")
org1_admin = cli.get_user('org1.example.com', 'Admin')
org2_admin = cli.get_user('org2.example.com', 'Admin')

# Make the client know there is a channel in the network
cli.new_channel('channel1')

# Install Example Chaincode to Peers
# GOPATH setting is only needed to use the example chaincode inside sdk
gopath_bak = os.environ.get('GOPATH', '')
gopath = os.path.normpath(os.path.join(
    os.path.dirname(os.path.realpath('__file__')),
    '../chaincode'
))
os.environ['GOPATH'] = os.path.abspath(gopath)

print("gopath", gopath)

# The response should be true if succeed
responses = loop.run_until_complete(cli.chaincode_install(
    requestor=org1_admin,
    peers=['peer0.org1.example.com'],
    cc_path='github.com/base_cc',
    cc_name='base_cc',
    cc_version='v1.0'
Esempio n. 7
0
import asyncio
from hfc.fabric import Client

loop = asyncio.get_event_loop()

cli = Client(net_profile="test-network.json")

print(cli.organizations)  # orgs in the network
print(cli.peers)  # peers in the network
print(cli.orderers)  # orderers in the network
print(cli.CAs)  # ca nodes in the network

org1_admin = cli.get_user(org_name='org1.example.com', name='Admin')
orderer_admin = cli.get_user(org_name='orderer.example.com', name='Admin')

#cli.new_channel('mychannel')

responses = loop.run_until_complete(
    cli.channel_join(requestor=org1_admin,
                     channel_name='mychannel',
                     peers=[
                         'peer0.org1.example.com', 'peer1.org1.example.com',
                         'peer0.org2.example.com', 'peer1.org2.example.com'
                     ],
                     orderer='orderer.example.com'))
print(responses)