Beispiel #1
0
    def setUp(self, wipe_all):
        self.gopath_bak = os.environ.get('GOPATH', '')
        gopath = os.path.normpath(
            os.path.join(os.path.dirname(__file__),
                         "../test/fixtures/chaincode"))

        os.environ['GOPATH'] = os.path.abspath(gopath)
        if "LOCAL_DEPLOY" in os.environ:
            LOCAL_DEPLOY = os.environ["LOCAL_DEPLOY"] == "True"
        GCP_DEPLOY = not LOCAL_DEPLOY

        self.channel_tx = \
            E2E_CONFIG[NETWORK_NAME]['channel-artifacts']['channel.tx']
        self.compose_file_path = \
            E2E_CONFIG[NETWORK_NAME]['docker']['compose_file_trustas_gcp'] if GCP_DEPLOY else \
            E2E_CONFIG[NETWORK_NAME]['docker']['compose_file_trustas_localhost']
        self.config_yaml = \
            E2E_CONFIG[NETWORK_NAME]['channel-artifacts']['config_yaml']
        self.channel_profile = \
            E2E_CONFIG[NETWORK_NAME]['channel-artifacts']['channel_profile']
        self.client =   Client('test/fixtures/trustas_net_gcp.json') if GCP_DEPLOY else \
                        Client('test/fixtures/network.json')
        # Client('test/fixtures/local-10peers.json')
        self.channel_name = "businesschannel"  # default application channel
        self.user = self.client.get_user('org1.example.com', 'Admin')
        self.assertIsNotNone(self.user, 'org1 admin should not be None')

        global ALIVE
        ALIVE = True

        # Boot up the testing network
        self.start_test_env(wipe_all)
        return HOST, NAME
 def setUp(self):
     self.gopath_bak = os.environ.get('GOPATH', '')
     gopath = os.path.normpath(os.path.join(os.path.dirname(__file__),
                                            "../../fixtures/chaincode"))
     os.environ['GOPATH'] = os.path.abspath(gopath)
     self.configtx_path = \
         E2E_CONFIG['test-network']['channel-artifacts']['channel.tx']
     self.peer0Org1_req_endpoint = E2E_CONFIG['test-network'][
         'org1.example.com']['peers']['peer0']['grpc_request_endpoint']
     self.peer0Org1_tls_certs = E2E_CONFIG['test-network'][
         'org1.example.com']['peers']['peer0']['tls_cacerts']
     self.peer0Org1_tls_hostname = E2E_CONFIG['test-network'][
         'org1.example.com']['peers']['peer0']['server_hostname']
     self.peer0Org2_req_endpoint = E2E_CONFIG['test-network'][
         'org2.example.com']['peers']['peer0']['grpc_request_endpoint']
     self.peer0Org2_tls_certs = E2E_CONFIG['test-network'][
         'org2.example.com']['peers']['peer0']['tls_cacerts']
     self.peer0Org2_tls_hostname = E2E_CONFIG['test-network'][
         'org2.example.com']['peers']['peer0']['server_hostname']
     self.compose_file_path = \
         E2E_CONFIG['test-network']['docker']['compose_file_tls']
     self.base_path = "/tmp/fabric-sdk-py"
     self.kv_store_path = os.path.join(self.base_path, "key-value-store")
     self.client = Client()
     self.start_test_env()
Beispiel #3
0
    def test_invoke(self):
        self.shutdown_test_env()
        self.start_test_env()
        time.sleep(5)
        client = Client()
        chain = client.new_channel(CHAIN_ID)
        client.set_state_store(file_key_value_store(self.kv_store_path))
        chain.add_peer(Peer())

        submitter = get_submitter()
        signing_identity = submitter.signing_identity
        # cc_invoke_req = create_invocation_proposal_req(
        #     CHAINCODE_NAME, CHAINCODE_VERSION, signing_identity,
        #     args=['move', 'a', 'b', '100'])
        queue = Queue(1)
        #
        # chain.invoke_chaincode(cc_invoke_req) \
        #     .subscribe(lambda x: queue.put(x))

        prop = queue.get(timeout=10)
        proposal_bytes = prop.proposal_bytes
        sig = prop.signature

        # verify the signature against the hash of proposal_bytes
        digest = signing_identity.msp.crypto_suite.hash(proposal_bytes)
        self.assertEqual(
            signing_identity.verify(str.encode(digest.hexdigest()), sig), True)
        self.shutdown_test_env()
Beispiel #4
0
    def test_create_new_chain(self):
        client = Client()
        test_chain = client.new_channel('test')
        self.assertEqual(test_chain, client.get_channel('test'))

        no_chain = client.get_channel('test1')
        self.assertIsNone(no_chain)
Beispiel #5
0
    def setUp(self):
        self.gopath_bak = os.environ.get('GOPATH', '')
        gopath = os.path.normpath(
            os.path.join(os.path.dirname(__file__), "../fixtures/chaincode"))
        os.environ['GOPATH'] = os.path.abspath(gopath)
        self.channel_tx = \
            E2E_CONFIG['test-network']['channel-artifacts']['channel.tx']
        self.compose_file_path = \
            E2E_CONFIG['test-network']['docker']['compose_file_mutual_tls']

        self.config_yaml = \
            E2E_CONFIG['test-network']['channel-artifacts']['config_yaml']
        self.channel_profile = \
            E2E_CONFIG['test-network']['channel-artifacts']['channel_profile']
        self.client = Client('test/fixtures/network-mutual-tls.json')

        with open('test/fixtures/network-mutual-tls.json') as f:
            self.network_info = json.load(f)

        self.channel_name = "businesschannel"  # default application channel
        self.user = self.client.get_user('org1.example.com', 'Admin')
        self.assertIsNotNone(self.user, 'org1 admin should not be None')

        # Boot up the testing network
        self.shutdown_test_env()
        self.start_test_env()
        time.sleep(1)
    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__())
Beispiel #7
0
    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)
Beispiel #8
0
    def test_create_new_chain(self):
        client = Client()
        client.set_state_store(file_key_value_store(self.kv_store_path))
        test_chain = client.new_chain('test')
        self.assertEqual(test_chain, client.get_chain('test'))

        no_chain = client.get_chain('test1')
        self.assertIsNone(no_chain)
Beispiel #9
0
    def setUp(self):
        super(ChannelEventHubTest, self).setUp()
        self.client = Client('test/fixtures/network.json')
        self.channel_name = "businesschannel"  # default application channel
        self.channel = self.client.new_channel(self.channel_name)
        self.blocks = []
        self.org = 'org1.example.com'
        self.peer = self.client.get_peer('peer0.' + self.org)
        self.org_admin = self.client.get_user(self.org, 'Admin')

        self.loop = asyncio.get_event_loop()
Beispiel #10
0
    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)
Beispiel #11
0
    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)
Beispiel #12
0
    def setUp(self):

        self.channel_tx = \
            test_network['channel-artifacts']['channel.tx']
        self.channel_name = \
            test_network['channel-artifacts']['channel_id']
        self.compose_file_path = \
            test_network['docker']['compose_file_tls']
        self.client = Client('test/fixtures/network.json')

        self.start_test_env()
 def setUp(self):
     self.configtx_path = \
         E2E_CONFIG['test-network']['channel-artifacts']['channel.tx']
     self.orderer_tls_certs = \
         E2E_CONFIG['test-network']['orderer']['tls_cacerts']
     self.orderer_tls_hostname = \
         E2E_CONFIG['test-network']['orderer']['server_hostname']
     self.compose_file_path = \
         E2E_CONFIG['test-network']['docker']['compose_file_tls']
     self.base_path = "/tmp/fabric-sdk-py"
     self.kv_store_path = os.path.join(self.base_path, "key-value-store")
     self.client = Client()
     self.start_test_env()
Beispiel #14
0
    def setUp(self):

        self.base_path = "/tmp/fabric-sdk-py"
        self.kv_store_path = os.path.join(self.base_path, "key-value-store")
        self.client = Client()
        self.client.state_store = FileKeyValueStore(self.kv_store_path)
        self.channel_tx = \
            E2E_CONFIG['test-network']['channel-artifacts']['channel.tx']
        self.channel_name = \
            E2E_CONFIG['test-network']['channel-artifacts']['channel_id']
        self.compose_file_path = \
            E2E_CONFIG['test-network']['docker']['compose_file_tls']

        self.start_test_env()
Beispiel #15
0
 def setUp(self):
     self.gopath_bak = os.environ.get('GOPATH', '')
     gopath = os.path.normpath(
         os.path.join(os.path.dirname(__file__),
                      "../../fixtures/chaincode"))
     os.environ['GOPATH'] = os.path.abspath(gopath)
     self.configtx_path = \
         E2E_CONFIG['test-network']['channel-artifacts']['channel.tx']
     self.compose_file_path = \
         E2E_CONFIG['test-network']['docker']['compose_file_tls']
     self.base_path = "/tmp/fabric-sdk-py"
     self.kv_store_path = os.path.join(self.base_path, "key-value-store")
     self.client = Client()
     self.client.state_store = FileKeyValueStore(self.kv_store_path)
     self.start_test_env()
Beispiel #16
0
    def setUp(self):
        self.gopath_bak = os.environ.get('GOPATH', '')
        gopath = os.path.normpath(
            os.path.join(os.path.dirname(__file__), "../fixtures/chaincode"))
        os.environ['GOPATH'] = os.path.abspath(gopath)
        self.channel_tx = \
            E2E_CONFIG['test-network']['channel-artifacts']['channel.tx']
        self.compose_file_path = \
            E2E_CONFIG['test-network']['docker']['compose_file_tls']

        self.client = Client('test/fixtures/network.json')
        self.channel_name = "businesschannel"  # default application channel
        self.user = self.client.get_user('org1.example.com', 'Admin')
        self.assertIsNotNone(self.user, 'org1 admin should not be None')
        self.start_test_env()
Beispiel #17
0
    def __init__(self, profile, channel_name, org_name, peer_name, user_name):
        self.client = Client(profile)
        self._channel_name = channel_name
        self._org_name = org_name
        self._peer_name = peer_name
        self._user_name = user_name

        self._user = self.client.get_user(self._org_name, self._user_name)
        endpoint = self.client.get_net_info('peers', self._peer_name, 'url')
        tlscert = self.client.get_net_info('peers', self._peer_name,
                                           'tlsCACerts', 'path')
        loop = asyncio.get_event_loop()

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

        loop.run_until_complete(
            self.client.init_with_discovery(self._user, peer,
                                            self._channel_name))

        self._channel = self.client.new_channel(self._channel_name)
Beispiel #18
0
    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
Beispiel #19
0
    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
Beispiel #20
0
    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 test_install(self):
        time.sleep(5)
        client = Client()
        chain = client.new_chain(CHAIN_ID)
        client.set_state_store(file_key_value_store(self.kv_store_path))
        chain.add_peer(Peer())
        chain.add_orderer(Orderer())

        submitter = get_submitter()

        signing_identity = submitter.signing_identity
        cc_install_req = create_installment_proposal_req(
            CHAINCODE_NAME, CHAINCODE_PATH, CHAINCODE_VERSION)
        queue = Queue(1)

        chain.install_chaincode(cc_install_req, signing_identity) \
            .subscribe(on_next=lambda x: queue.put(x),
                       on_error=lambda x: queue.put(x))

        response, _ = queue.get(timeout=5)
        # TODO: create channel not implement yet
        print(response.status)
        self.assertEqual(404, response.status)
Beispiel #22
0
    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__())
Beispiel #23
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)
Beispiel #24
0
    def setUp(self):
        self.gopath_bak = os.environ.get('GOPATH', '')
        gopath = os.path.normpath(
            os.path.join(os.path.dirname(__file__), "../fixtures/chaincode"))
        os.environ['GOPATH'] = os.path.abspath(gopath)
        self.channel_tx = \
            NET_CONFIG['channel-artifacts']['channel.tx']
        self.compose_file_path = \
            NET_CONFIG['docker']['compose_file_tls']

        self.config_yaml = \
            NET_CONFIG['channel-artifacts']['config_yaml']
        self.channel_profile = \
            NET_CONFIG['channel-artifacts']['channel_profile']
        self.client = Client('test/fixtures/trustas-net.json')
        self.channel_name = "businesschannel"  # application channel
        self.user = self.client.get_user('org1.example.com', 'Admin')
        self.assertIsNotNone(self.user, 'org1 admin should not be None')

        global ALIVE
        ALIVE = True

        # Boot up the testing network
        self.start_test_env()
import os
from hfc.fabric.client import Client
from hfc.fabric_ca.caservice import ca_service
from hfc.fabric_network import wallet
"""
이 노드(하이퍼레저 net에 접속하는 클라이언트 노드)의 네트워크 설정 정보들
"""
HLF_NET_PATH="/opt/fixtures/network.json"
cli = Client(net_profile=HLF_NET_PATH)

class UserManage():

    def __init__(self, ca_addr="localhost:7054",
                ADMIN_ID="admin", ADMIN_SECRET="adminpw"):

        if cli.CAs():
            "client 객체에 CA 서버가 등록되어 있으면 그걸 사용"
            self._ca_server = cli._CAs
        else:
            "CA 서버(컨테이너) 주소로 CA서버 객체 생성"
            if os.getenv("CA_ADDR"):
                self._ca_server = ca_service(os.getenv("CA_ADDR"))
            else:
                self._ca_server = ca_service(ca_addr)

        "관리자 계정의 사용자 등록관리 객체를 CA 서버에서 얻어옴"
        if self._ca_server:
            self._admin_enroll_x509 = self._ca_server.enroll(ADMIN_ID,ADMIN_SECRET)
        else:
            self._admin_enroll_x509 = self._ca_server.enroll("admin","adminpw")
 def setUp(self):
     self.client = Client()
Beispiel #27
0
    def test_create_client(self):
        # TODO impl

        client = Client()
        client.set_state_store(file_key_value_store(self.kv_store_path))
        self.fail()
Beispiel #28
0
 def setUp(self):
     self.client = Client('test/fixtures/network.json')
Beispiel #29
0
    def test_create_client(self):
        # TODO impl

        Client()
        self.fail()