Ejemplo n.º 1
0
def invokeChaincode(context, devopsFunc, functionName, containerName, idGenAlg=None):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    # Update hte chaincodeSpec ctorMsg for invoke
    args = []
    if 'table' in context:
       # There is ctor arguments
       args = context.table[0].cells
    context.chaincodeSpec['ctorMsg']['function'] = functionName
    context.chaincodeSpec['ctorMsg']['args'] = args
    # Invoke the POST
    chaincodeInvocationSpec = {
        "chaincodeSpec" : context.chaincodeSpec
    }
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    if idGenAlg is not None:
	    chaincodeInvocationSpec['idGenerationAlg'] = idGenAlg
    request_url = buildUrl(context, ipAddress, "/devops/{0}".format(devopsFunc))
    print("{0} POSTing path = {1}".format(currentTime(), request_url))

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeInvocationSpec), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(functionName, containerName))
    print(json.dumps(context.response.json(), indent = 4))
    if 'message' in resp.json():
        transactionID = context.response.json()['message']
        context.transactionID = transactionID
Ejemplo n.º 2
0
def invokeChaincode(context, devopsFunc, functionName, containerName):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    # Update hte chaincodeSpec ctorMsg for invoke
    args = []
    if 'table' in context:
        # There is ctor arguments
        args = context.table[0].cells
    context.chaincodeSpec['ctorMsg']['function'] = functionName
    context.chaincodeSpec['ctorMsg']['args'] = args
    # Invoke the POST
    chaincodeInvocationSpec = {"chaincodeSpec": context.chaincodeSpec}
    ipAddress = bdd_test_util.ipFromContainerNamePart(
        containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress,
                           "/devops/{0}".format(devopsFunc))
    print("{0} POSTing path = {1}".format(currentTime(), request_url))

    resp = requests.post(request_url,
                         headers={'Content-type': 'application/json'},
                         data=json.dumps(chaincodeInvocationSpec),
                         verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" % (request_url,
                                                                   resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(
        functionName, containerName))
    print(json.dumps(context.response.json(), indent=4))
    if 'message' in resp.json():
        transactionID = context.response.json()['message']
        context.transactionID = transactionID
Ejemplo n.º 3
0
def invokeUsingChaincodeService(context, devopsFunc, functionName,
                                containerName):
    # Invoke the POST
    chaincodeOpPayload = createChaincodeOpPayload(devopsFunc,
                                                  context.chaincodeSpec)

    ipAddress = bdd_test_util.ipFromContainerNamePart(
        containerName, context.compose_containers)

    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("{0} POSTing path = {1}".format(currentTime(), request_url))
    print("Using attributes {0}".format(context.chaincodeSpec['attributes']))

    resp = requests.post(request_url,
                         headers={'Content-type': 'application/json'},
                         data=json.dumps(chaincodeOpPayload),
                         verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" % (request_url,
                                                                   resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(
        functionName, containerName))
    print(json.dumps(context.response.json(), indent=4))
    if 'result' in resp.json():
        result = resp.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Ejemplo n.º 4
0
def invokeUsingDevopsService(context, devopsFunc, functionName, containerName,
                             idGenAlg):
    # Invoke the POST
    chaincodeInvocationSpec = {"chaincodeSpec": context.chaincodeSpec}
    ipAddress = bdd_test_util.ipFromContainerNamePart(
        containerName, context.compose_containers)
    if idGenAlg is not None:
        chaincodeInvocationSpec['idGenerationAlg'] = idGenAlg
    request_url = buildUrl(context, ipAddress,
                           "/devops/{0}".format(devopsFunc))
    print("{0} POSTing path = {1}".format(currentTime(), request_url))

    resp = requests.post(request_url,
                         headers={'Content-type': 'application/json'},
                         data=json.dumps(chaincodeInvocationSpec),
                         verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" % (request_url,
                                                                   resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(
        functionName, containerName))
    print(json.dumps(context.response.json(), indent=4))
    if 'message' in resp.json():
        transactionID = context.response.json()['message']
        context.transactionID = transactionID
Ejemplo n.º 5
0
def step_impl(context):
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers, username, secret) not found in context"

    peerToSecretMessage = {}

    # Login to each container specified using username and secret
    for row in context.table.rows:
        peer, userName, secret = row['peer'], row['username'], row['secret']
        secretMsg = {"enrollId": userName, "enrollSecret": secret}

        ipAddress = bdd_test_util.ipFromContainerNamePart(
            peer, context.compose_containers)
        request_url = buildUrl(context, ipAddress, "/registrar")
        print("POSTing to service = {0}, path = {1}".format(peer, request_url))

        resp = requests.post(request_url,
                             headers={'Content-type': 'application/json'},
                             data=json.dumps(secretMsg),
                             verify=False)
        assert resp.status_code == 200, "Failed to POST to %s:  %s" % (
            request_url, resp.text)
        context.response = resp
        print("message = {0}".format(resp.json()))
        peerToSecretMessage[peer] = secretMsg
    context.peerToSecretMessage = peerToSecretMessage
def invokeMasterChaincode(context, devopsFunc, chaincodeName, functionName, containerName):
    args = []
    if 'table' in context:
       args = context.table[0].cells
    typeGolang = 1
    chaincodeSpec = {
        "type": typeGolang,
        "chaincodeID": {
            "name" : chaincodeName
        },
        "ctorMsg":  {
            "function" : functionName,
            "args" : args
        }
    }
    if 'userName' in context:
        chaincodeSpec["secureContext"] = context.userName

    chaincodeOpPayload = createChaincodeOpPayload(devopsFunc, chaincodeSpec)

    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("{0} POSTing path = {1}".format(currentTime(), request_url))

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeOpPayload), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(functionName, containerName))
    print(json.dumps(context.response.json(), indent = 4))
    if 'result' in resp.json():
        result = resp.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Ejemplo n.º 7
0
def invokeMasterChaincode(context, devopsFunc, chaincodeName, functionName, containerName):
    args = []
    if 'table' in context:
       args = context.table[0].cells
    args = prepend(functionName, args)
    typeGolang = 1
    chaincodeSpec = {
        "type": typeGolang,
        "chaincodeID": {
            "name" : chaincodeName
        },
        "ctorMsg":  {
            "args" : args
        }
    }
    if 'userName' in context:
        chaincodeSpec["secureContext"] = context.userName

    chaincodeOpPayload = createChaincodeOpPayload(devopsFunc, chaincodeSpec)

    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("{0} POSTing path = {1}".format(currentTime(), request_url))

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeOpPayload), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(functionName, containerName))
    print(json.dumps(context.response.json(), indent = 4))
    if 'result' in resp.json():
        result = resp.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Ejemplo n.º 8
0
def step_impl(context, containerName):
    assert 'table' in context, "table (of query parameters) not found in context"
    assert 'userName' in context, "userName not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"

    ipAddress = bdd_test_util.ipFromContainerNamePart(
        containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress,
                           "/registrar/{0}/tcert".format(context.userName))
    print("Requesting path = {0}".format(request_url))
    queryParams = {}
    for row in context.table.rows:
        key, value = row['key'], row['value']
        queryParams[key] = value

    print("Query parameters = {0}".format(queryParams))
    resp = requests.get(request_url,
                        params=queryParams,
                        headers={'Accept': 'application/json'},
                        verify=False)

    assert resp.status_code == 200, "Failed to GET to %s:  %s" % (request_url,
                                                                  resp.text)
    context.response = resp
    print("")
Ejemplo n.º 9
0
def step_impl(context, path, containerName):
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, path)
    print("Requesting path = {0}".format(request_url))
    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to GET url %s:  %s" % (request_url,resp.text)
    context.response = resp
    print("")
Ejemplo n.º 10
0
def getEndorserStubs(context, composeServices):
    stubs = []
    for composeService in composeServices:
        ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
        channel = bdd_grpc_util.getGRPCChannel(ipAddress)
        newEndorserStub = peer_pb2_grpc.EndorserStub(channel)
        stubs.append(newEndorserStub)
    return stubs
def step_impl(context, path, containerName):
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, path)
    print("Requesting path = {0}".format(request_url))
    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to GET url %s:  %s" % (request_url,resp.text)
    context.response = resp
    print("")
Ejemplo n.º 12
0
def getEndorserStubs(context, composeServices):
	stubs = []
	for composeService in composeServices:
		ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
		channel = bdd_grpc_util.getGRPCChannel(ipAddress)
		newEndorserStub = fabric_service_pb2.beta_create_Endorser_stub(channel)
		stubs.append(newEndorserStub)
	return stubs
def step_impl(context, seconds, containerName):
    assert 'transactionID' in context, "transactionID not found in context"
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/transactions/{0}".format(context.transactionID))
    print("{0} GETing path = {1}".format(currentTime(), request_url))

    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
Ejemplo n.º 14
0
def step_impl(context, enrollId, ccDeploymentSpecAlias, ccSpecAlias, devopsComposeService):
	userRegistration = bdd_test_util.getUserRegistration(context, enrollId)
	assert ccSpecAlias in userRegistration.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(ccSpecAlias, enrollId)

	ipAddress = bdd_test_util.ipFromContainerNamePart(devopsComposeService, context.compose_containers)
	channel = bdd_grpc_util.getGRPCChannel(ipAddress)
	devopsStub = devops_pb2.beta_create_Devops_stub(channel)
	deploymentSpec = devopsStub.Build(userRegistration.tags[ccSpecAlias],20)
	userRegistration.tags[ccDeploymentSpecAlias] = deploymentSpec
Ejemplo n.º 15
0
def step_impl(context, seconds, containerName):
    assert 'transactionID' in context, "transactionID not found in context"
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/transactions/{0}".format(context.transactionID))
    print("{0} GETing path = {1}".format(currentTime(), request_url))

    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
Ejemplo n.º 16
0
def getGRPCChannelAndUser(context, enrollId):
    '''Returns a tuple of GRPC channel and UserRegistration instance.  The channel is open to the composeService that the user registered with.'''
    userRegistration = bdd_test_util.getUserRegistration(context, enrollId)

    # Get the IP address of the server that the user registered on
    ipAddress = bdd_test_util.ipFromContainerNamePart(userRegistration.composeService, context.compose_containers)

    channel = getGRPCChannel(ipAddress)

    return (channel, userRegistration)
Ejemplo n.º 17
0
def step_impl(context, chaincodeName, functionName, containerName, times):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chain")
    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to get chain height %s:  %s" % (request_url,resp.text)
    context.chainheight = getAttributeFromJSON("height", resp.json(), "Height not found in response.")
    context.txcount = times
    for i in range(int(times)):
        invokeChaincode(context, "invoke", functionName, containerName)
Ejemplo n.º 18
0
def step_impl(context, chaincodeName, functionName, containerName, times):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chain")
    resp = requests.get(request_url, headers={'Accept': 'application/json'}, verify=False)
    assert resp.status_code == 200, "Failed to get chain height %s:  %s" % (request_url,resp.text)
    context.chainheight = getAttributeFromJSON("height", resp.json(), "Height not found in response.")
    context.txcount = times
    for i in range(int(times)):
        invokeChaincode(context, "invoke", functionName, containerName)
Ejemplo n.º 19
0
    def getABStubForComposeService(self, context, composeService):
		'Return a Stub for the supplied composeService, will cache'
		if composeService in self.atomicBroadcastStubsDict:
			return self.atomicBroadcastStubsDict[composeService]
		# Get the IP address of the server that the user registered on
		ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
		channel = getGRPCChannel(ipAddress)
		newABStub = ab_pb2.beta_create_AtomicBroadcast_stub(channel)
		self.atomicBroadcastStubsDict[composeService] = newABStub
		return newABStub
Ejemplo n.º 20
0
    def getABStubForComposeService(self, context, composeService):
		'Return a Stub for the supplied composeService, will cache'
		if composeService in self.atomicBroadcastStubsDict:
			return self.atomicBroadcastStubsDict[composeService]
		# Get the IP address of the server that the user registered on
		ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
		channel = getGRPCChannel(ipAddress)
		newABStub = ab_pb2.beta_create_AtomicBroadcast_stub(channel)
		self.atomicBroadcastStubsDict[composeService] = newABStub
		return newABStub
Ejemplo n.º 21
0
def step_impl(context, userName, ccDeploymentSpecAlias, ccSpecAlias, devopsComposeService):
    directory = bootstrap_util.getDirectory(context=context)
    user = directory.getUser(userName=userName)
    assert ccSpecAlias in user.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(ccSpecAlias, userName)

    ipAddress = bdd_test_util.ipFromContainerNamePart(devopsComposeService, context.compose_containers)
    channel = bdd_grpc_util.getGRPCChannel(ipAddress)
    devopsStub = devops_pb2.beta_create_Devops_stub(channel)
    deploymentSpec = devopsStub.Build(user.tags[ccSpecAlias],20)
    user.tags[ccDeploymentSpecAlias] = deploymentSpec
Ejemplo n.º 22
0
def getGRPCChannelAndUser(context, enrollId):
    '''Returns a tuple of GRPC channel and UserRegistration instance.  The channel is open to the composeService that the user registered with.'''
    userRegistration = bdd_test_util.getUserRegistration(context, enrollId)

    # Get the IP address of the server that the user registered on
    ipAddress = bdd_test_util.ipFromContainerNamePart(userRegistration.composeService, context.compose_containers)

    channel = getGRPCChannel(ipAddress)

    return (channel, userRegistration)
Ejemplo n.º 23
0
def step_impl(context, enrollId, ccDeploymentSpecAlias, ccSpecAlias,
              devopsComposeService):
    userRegistration = bdd_test_util.getUserRegistration(context, enrollId)
    assert ccSpecAlias in userRegistration.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(
        ccSpecAlias, enrollId)

    ipAddress = bdd_test_util.ipFromContainerNamePart(
        devopsComposeService, context.compose_containers)
    channel = bdd_grpc_util.getGRPCChannel(ipAddress)
    devopsStub = devops_pb2.beta_create_Devops_stub(channel)
    deploymentSpec = devopsStub.Build(userRegistration.tags[ccSpecAlias], 20)
    userRegistration.tags[ccDeploymentSpecAlias] = deploymentSpec
Ejemplo n.º 24
0
def step_impl(context, userName, ccDeploymentSpecAlias, ccSpecAlias,
              devopsComposeService):
    directory = bootstrap_util.getDirectory(context=context)
    user = directory.getUser(userName=userName)
    assert ccSpecAlias in user.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(
        ccSpecAlias, userName)

    ipAddress = bdd_test_util.ipFromContainerNamePart(
        devopsComposeService, context.compose_containers)
    channel = bdd_grpc_util.getGRPCChannel(ipAddress)
    devopsStub = devops_pb2.beta_create_Devops_stub(channel)
    deploymentSpec = devopsStub.Build(user.tags[ccSpecAlias], 20)
    user.tags[ccDeploymentSpecAlias] = deploymentSpec
Ejemplo n.º 25
0
 def getABStubForComposeService(self, context, composeService):
     'Return a Stub for the supplied composeService, will cache'
     if composeService in self.atomicBroadcastStubsDict:
         return self.atomicBroadcastStubsDict[composeService]
     # Get the IP address of the server that the user registered on
     root_certificates = self.directory.getTrustedRootsForOrdererNetworkAsPEM()
     # ipAddress = "{0}:{1}".format(*bdd_test_util.getPortHostMapping(context.compose_containers, composeService, 7050))
     ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
     print("ipAddress in getABStubForComposeService == {0}".format(ipAddress))
     channel = bdd_grpc_util.getGRPCChannel(ipAddress=ipAddress, port=7050, root_certificates=root_certificates, ssl_target_name_override=composeService)
     # channel = getGRPCChannel(*bdd_test_util.getPortHostMapping(context.compose_containers, composeService, 7050))
     newABStub = ab_pb2_grpc.AtomicBroadcastStub(channel)
     self.atomicBroadcastStubsDict[composeService] = newABStub
     return newABStub
Ejemplo n.º 26
0
def getEndorserStubs(context, composeServices, directory, nodeAdminTuple):
    stubs = []
    user = directory.getUser(nodeAdminTuple.user)
    signingOrg = directory.getOrganization(nodeAdminTuple.organization)

    for composeService in composeServices:
        ipAddress = bdd_test_util.ipFromContainerNamePart(composeService, context.compose_containers)
        # natForPeerSigner = directory.findNodeAdminTuple(userName="******".format(composeService), contextName=composeService, orgName="peerOrg0")
        # signerCert = directory.getCertAsPEM(natForPeerSigner)
        root_certificates = directory.getTrustedRootsForPeerNetworkAsPEM()
        channel = bdd_grpc_util.getGRPCChannel(ipAddress=ipAddress, port=7051, root_certificates=root_certificates,
                                               ssl_target_name_override=composeService)
        newEndorserStub = peer_pb2_grpc.EndorserStub(channel)
        stubs.append(newEndorserStub)
    return stubs
Ejemplo n.º 27
0
def deployChainCodeToContainer(context, chaincode, containerName):
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("Requesting path = {0}".format(request_url))

    chaincodeSpec = createChaincodeSpec(context, chaincode)
    chaincodeOpPayload = createChaincodeOpPayload("deploy", chaincodeSpec)

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeOpPayload), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    chaincodeName = resp.json()['result']['message']
    chaincodeSpec['chaincodeID']['name'] = chaincodeName
    context.chaincodeSpec = chaincodeSpec
    print(json.dumps(chaincodeSpec, indent=4))
    print("")
Ejemplo n.º 28
0
def deployChainCodeToContainer(context, chaincode, containerName):
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("Requesting path = {0}".format(request_url))

    chaincodeSpec = createChaincodeSpec(context, chaincode)
    chaincodeOpPayload = createChaincodeOpPayload("deploy", chaincodeSpec)

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeOpPayload), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    chaincodeName = resp.json()['result']['message']
    chaincodeSpec['chaincodeID']['name'] = chaincodeName
    context.chaincodeSpec = chaincodeSpec
    print(json.dumps(chaincodeSpec, indent=4))
    print("")
Ejemplo n.º 29
0
def getEndorserStubs(context, composeServices, directory, nodeAdminTuple):
    stubs = []
    user = directory.getUser(nodeAdminTuple.user)
    signingOrg = directory.getOrganization(nodeAdminTuple.organization)

    for composeService in composeServices:
        ipAddress = bdd_test_util.ipFromContainerNamePart(
            composeService, context.compose_containers)
        # natForPeerSigner = directory.findNodeAdminTuple(userName="******".format(composeService), contextName=composeService, orgName="peerOrg0")
        # signerCert = directory.getCertAsPEM(natForPeerSigner)
        root_certificates = directory.getTrustedRootsForPeerNetworkAsPEM()
        channel = bdd_grpc_util.getGRPCChannel(
            ipAddress=ipAddress,
            port=7051,
            root_certificates=root_certificates,
            ssl_target_name_override=composeService)
        newEndorserStub = peer_pb2_grpc.EndorserStub(channel)
        stubs.append(newEndorserStub)
    return stubs
Ejemplo n.º 30
0
def step_impl(context, containerName):
    assert 'table' in context, "table (of query parameters) not found in context"
    assert 'userName' in context, "userName not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"

    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/registrar/{0}/tcert".format(context.userName))
    bdd_log("Requesting path = {0}".format(request_url))
    queryParams = {}
    for row in context.table.rows:
        key, value = row['key'], row['value']
        queryParams[key] = value

    bdd_log("Query parameters = {0}".format(queryParams))
    resp = requests.get(request_url, params=queryParams, headers={'Accept': 'application/json'}, verify=False)

    assert resp.status_code == 200, "Failed to GET to %s:  %s" % (request_url, resp.text)
    context.response = resp
    bdd_log("")
Ejemplo n.º 31
0
def invokeUsingDevopsService(context, devopsFunc, functionName, containerName, idGenAlg):
    # Invoke the POST
    chaincodeInvocationSpec = {
        "chaincodeSpec" : context.chaincodeSpec
    }
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    if idGenAlg is not None:
	    chaincodeInvocationSpec['idGenerationAlg'] = idGenAlg
    request_url = buildUrl(context, ipAddress, "/devops/{0}".format(devopsFunc))
    print("{0} POSTing path = {1}".format(currentTime(), request_url))

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeInvocationSpec), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(functionName, containerName))
    print(json.dumps(context.response.json(), indent = 4))
    if 'message' in resp.json():
        transactionID = context.response.json()['message']
        context.transactionID = transactionID
Ejemplo n.º 32
0
def invokeUsingChaincodeService(context, devopsFunc, functionName, containerName):
    # Invoke the POST
    chaincodeOpPayload = createChaincodeOpPayload(devopsFunc, context.chaincodeSpec)

    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)

    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("{0} POSTing path = {1}".format(currentTime(), request_url))
    print("Using attributes {0}".format(context.chaincodeSpec['attributes']))

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeOpPayload), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    print("RESULT from {0} of chaincode from peer {1}".format(functionName, containerName))
    print(json.dumps(context.response.json(), indent = 4))
    if 'result' in resp.json():
        result = resp.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Ejemplo n.º 33
0
def step_impl(context, chaincodePath, ctor, containerName):
    ipAddress = bdd_test_util.ipFromContainerNamePart(
        containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/devops/deploy")
    print("Requesting path = {0}".format(request_url))
    args = []
    if 'table' in context:
        # There is ctor arguments
        args = context.table[0].cells
    typeGolang = 1

    # Create a ChaincodeSpec structure
    chaincodeSpec = {
        "type": typeGolang,
        "chaincodeID": {
            "path": chaincodePath,
            "name": ""
        },
        "ctorMsg": {
            "function": ctor,
            "args": args
        },
        #"secureContext" : "binhn"
    }
    if 'userName' in context:
        chaincodeSpec["secureContext"] = context.userName
    if 'metadata' in context:
        chaincodeSpec["metadata"] = context.metadata

    resp = requests.post(request_url,
                         headers={'Content-type': 'application/json'},
                         data=json.dumps(chaincodeSpec),
                         verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" % (request_url,
                                                                   resp.text)
    context.response = resp
    chaincodeName = resp.json()['message']
    chaincodeSpec['chaincodeID']['name'] = chaincodeName
    context.chaincodeSpec = chaincodeSpec
    print(json.dumps(chaincodeSpec, indent=4))
    print("")
Ejemplo n.º 34
0
def step_impl(context, chaincodePath, ctor, containerName):
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("Requesting path = {0}".format(request_url))
    args = []
    if 'table' in context:
          # There is ctor arguments
          args = context.table[0].cells
    typeGolang = 1

    # Create a ChaincodeSpec structure
    chaincodeSpec = {
        "type": typeGolang,
        "chaincodeID": {
            "path" : chaincodePath,
            "name" : ""
        },
        "ctorMsg":  {
            "function" : ctor,
            "args" : args
        },
        #"secureContext" : "binhn"
    }
    if 'userName' in context:
        chaincodeSpec["secureContext"] = context.userName
    if 'metadata' in context:
        chaincodeSpec["metadata"] = context.metadata

    chaincodeOpPayload = createChaincodeOpPayload("deploy", chaincodeSpec)

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeOpPayload), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    chaincodeName = resp.json()['result']['message']
    chaincodeSpec['chaincodeID']['name'] = chaincodeName
    context.chaincodeSpec = chaincodeSpec
    print(json.dumps(chaincodeSpec, indent=4))
    print("")
Ejemplo n.º 35
0
def step_impl(context):
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers, username, secret) not found in context"

    peerToSecretMessage = {}

    # Login to each container specified using username and secret
    for row in context.table.rows:
        peer, userName, secret = row['peer'], row['username'], row['secret']
        secretMsg = {
            "enrollId": userName,
            "enrollSecret" : secret
        }

        ipAddress = bdd_test_util.ipFromContainerNamePart(peer, context.compose_containers)
        request_url = buildUrl(context, ipAddress, "/registrar")
        print("POSTing to service = {0}, path = {1}".format(peer, request_url))

        resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(secretMsg), verify=False)
        assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
        context.response = resp
        print("message = {0}".format(resp.json()))
        peerToSecretMessage[peer] = secretMsg
    context.peerToSecretMessage = peerToSecretMessage
def step_impl(context, chaincodePath, chainLang, ctor, containerName):
    print("Printing chaincode language " + chainLang)
    ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    request_url = buildUrl(context, ipAddress, "/chaincode")
    print("Requesting path = {0}".format(request_url))
    args = []
    if 'table' in context:
       # There is ctor arguments
       args = context.table[0].cells
    #typeGolang =

    # Create a ChaincodeSpec structure
    chaincodeSpec = {
        "type": getChaincodeTypeValue(chainLang),
        "chaincodeID": {
            "path" : chaincodePath,
            "name" : ""
        },
        "ctorMsg":  {
            "function" : ctor,
            "args" : args
        },
    }
    if 'userName' in context:
        chaincodeSpec["secureContext"] = context.userName

    chaincodeOpPayload = createChaincodeOpPayload("deploy", chaincodeSpec)

    resp = requests.post(request_url, headers={'Content-type': 'application/json'}, data=json.dumps(chaincodeOpPayload), verify=False)
    assert resp.status_code == 200, "Failed to POST to %s:  %s" %(request_url, resp.text)
    context.response = resp
    chaincodeName = resp.json()['result']['message']
    chaincodeSpec['chaincodeID']['name'] = chaincodeName
    context.chaincodeSpec = chaincodeSpec
    print(json.dumps(chaincodeSpec, indent=4))
    print("")