Beispiel #1
0
def query_common(context, chaincodeName, functionName, value, failOnError):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"
    assert 'peerToSecretMessage' in context, "peerToSecretMessage map not found in context"

    # Update the chaincodeSpec ctorMsg for invoke
    context.chaincodeSpec['ctorMsg']['args'] = [functionName, value]
    # Make deep copy of chaincodeSpec as we will be changing the SecurityContext per call.
    chaincodeOpPayload = createChaincodeOpPayload("query", copy.deepcopy(context.chaincodeSpec))

    responses = []
    aliases = context.table.headings
    containers = [context.containerAliasMap[alias] for alias in aliases]
    for container in containers:
        # Change the SecurityContext per call
        chaincodeOpPayload['params']["secureContext"] = \
            context.peerToSecretMessage[container.composeService]['enrollId']

        bdd_log("Container {0} enrollID = {1}".format(container.name, container.getEnv("CORE_SECURITY_ENROLLID")))
        resp = bdd_request_util.httpPostToContainer(context, \
            container, "/chaincode", chaincodeOpPayload, expectSuccess=failOnError)
        responses.append(resp)

    context.responses = responses
Beispiel #2
0
def invokeMasterChaincode(context, devopsFunc, chaincodeName, functionName, container):
    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)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, "/chaincode", chaincodeOpPayload)

    if 'result' in context.response.json():
        result = context.response.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Beispiel #3
0
def query_common(context, chaincodeName, functionName, value, failOnError):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"
    assert 'peerToSecretMessage' in context, "peerToSecretMessage map not found in context"

    # Update the chaincodeSpec ctorMsg for invoke
    context.chaincodeSpec['ctorMsg']['args'] = [functionName, value]
    # Make deep copy of chaincodeSpec as we will be changing the SecurityContext per call.
    chaincodeOpPayload = createChaincodeOpPayload(
        "query", copy.deepcopy(context.chaincodeSpec))

    responses = []
    aliases = context.table.headings
    containers = [context.containerAliasMap[alias] for alias in aliases]
    for container in containers:
        # Change the SecurityContext per call
        chaincodeOpPayload['params']["secureContext"] = \
            context.peerToSecretMessage[container.composeService]['enrollId']

        bdd_log("Container {0} enrollID = {1}".format(
            container.name, container.getEnv("CORE_SECURITY_ENROLLID")))
        resp = bdd_request_util.httpPostToContainer(context, \
            container, "/chaincode", chaincodeOpPayload, expectSuccess=failOnError)
        responses.append(resp)

    context.responses = responses
Beispiel #4
0
def invokeMasterChaincode(context, devopsFunc, chaincodeName, functionName,
                          container):
    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)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, "/chaincode", chaincodeOpPayload)

    if 'result' in context.response.json():
        result = context.response.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Beispiel #5
0
def invokeUsingChaincodeService(context, devopsFunc, functionName, container):
    # Invoke the POST
    chaincodeOpPayload = createChaincodeOpPayload(devopsFunc, context.chaincodeSpec)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, "/chaincode", chaincodeOpPayload)

    if 'result' in context.response.json():
        result = context.response.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Beispiel #6
0
def deployChainCodeToContainer(context, chaincode, container):
    chaincodeSpec = createChaincodeSpec(context, chaincode)
    chaincodeOpPayload = createChaincodeOpPayload("deploy", chaincodeSpec)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, "/chaincode", chaincodeOpPayload)

    chaincodeName = context.response.json()['result']['message']
    chaincodeSpec['chaincodeID']['name'] = chaincodeName
    context.chaincodeSpec = chaincodeSpec
    bdd_log(json.dumps(chaincodeSpec, indent=4))
    bdd_log("")
Beispiel #7
0
def deployChainCodeToContainer(context, chaincode, container):
    chaincodeSpec = createChaincodeSpec(context, chaincode)
    chaincodeOpPayload = createChaincodeOpPayload("deploy", chaincodeSpec)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, "/chaincode", chaincodeOpPayload)

    chaincodeName = context.response.json()['result']['message']
    chaincodeSpec['chaincodeID']['name'] = chaincodeName
    context.chaincodeSpec = chaincodeSpec
    bdd_log(json.dumps(chaincodeSpec, indent=4))
    bdd_log("")
Beispiel #8
0
def invokeUsingChaincodeService(context, devopsFunc, functionName, container):
    # Invoke the POST
    chaincodeOpPayload = createChaincodeOpPayload(devopsFunc,
                                                  context.chaincodeSpec)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, "/chaincode", chaincodeOpPayload)

    if 'result' in context.response.json():
        result = context.response.json()['result']
        if 'message' in result:
            transactionID = result['message']
            context.transactionID = transactionID
Beispiel #9
0
def invokeUsingDevopsService(context, devopsFunc, functionName, container,
                             idGenAlg):
    # Invoke the POST
    chaincodeInvocationSpec = {"chaincodeSpec": context.chaincodeSpec}

    if idGenAlg is not None:
        chaincodeInvocationSpec['idGenerationAlg'] = idGenAlg

    endpoint = "/devops/{0}".format(devopsFunc)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, endpoint, chaincodeInvocationSpec)

    if 'message' in context.response.json():
        transactionID = context.response.json()['message']
        context.transactionID = transactionID
Beispiel #10
0
def invokeUsingDevopsService(context, devopsFunc, functionName, container, idGenAlg):
    # Invoke the POST
    chaincodeInvocationSpec = {
        "chaincodeSpec" : context.chaincodeSpec
    }

    if idGenAlg is not None:
	    chaincodeInvocationSpec['idGenerationAlg'] = idGenAlg

    endpoint = "/devops/{0}".format(devopsFunc)
    context.response = bdd_request_util.httpPostToContainer(context, \
        container, endpoint, chaincodeInvocationSpec)

    if 'message' in context.response.json():
        transactionID = context.response.json()['message']
        context.transactionID = transactionID
Beispiel #11
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']
        peerToSecretMessage[peer] = {
            "enrollId": userName,
            "enrollSecret" : secret
        }

        container = context.containerAliasMap[peer]
        context.response = bdd_request_util.httpPostToContainer(context, \
            container, "/registrar", peerToSecretMessage[peer])

    context.peerToSecretMessage = peerToSecretMessage
Beispiel #12
0
def step_impl(context, chaincodeName, functionName):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    # Update the chaincodeSpec ctorMsg for invoke
    args = []
    if 'table' in context:
       # There is ctor arguments
       args = context.table[0].cells
    args = prepend(functionName, args)

    context.chaincodeSpec['ctorMsg']['args'] = args #context.table[0].cells if ('table' in context) else []
    chaincodeOpPayload = createChaincodeOpPayload("query", context.chaincodeSpec)

    responses = []
    for container in context.compose_containers:
        resp = bdd_request_util.httpPostToContainer(context, \
            container, "/chaincode", chaincodeOpPayload)
        responses.append(resp)
    context.responses = responses
Beispiel #13
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']
        peerToSecretMessage[peer] = {
            "enrollId": userName,
            "enrollSecret": secret
        }

        container = context.containerAliasMap[peer]
        context.response = bdd_request_util.httpPostToContainer(context, \
            container, "/registrar", peerToSecretMessage[peer])

    context.peerToSecretMessage = peerToSecretMessage
Beispiel #14
0
def step_impl(context, chaincodeName, functionName):
    assert 'chaincodeSpec' in context, "chaincodeSpec not found in context"
    assert 'compose_containers' in context, "compose_containers not found in context"
    # Update the chaincodeSpec ctorMsg for invoke
    args = []
    if 'table' in context:
        # There is ctor arguments
        args = context.table[0].cells
    args = prepend(functionName, args)

    context.chaincodeSpec['ctorMsg'][
        'args'] = args  #context.table[0].cells if ('table' in context) else []
    chaincodeOpPayload = createChaincodeOpPayload("query",
                                                  context.chaincodeSpec)

    responses = []
    for container in context.compose_containers:
        resp = bdd_request_util.httpPostToContainer(context, \
            container, "/chaincode", chaincodeOpPayload)
        responses.append(resp)
    context.responses = responses
Beispiel #15
0
def step_impl(context, userName, secret):
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"

    secretMsg = {"enrollId": userName, "enrollSecret": secret}

    # Login to each container specified
    aliases = context.table.headings
    containers = [context.containerAliasMap[alias] for alias in aliases]
    for container in containers:
        context.response = bdd_request_util.httpPostToContainer(context, \
            container, "/registrar", secretMsg)

        # Create new User entry
        bdd_test_util.registerUser(context, secretMsg,
                                   container.composeService)

    # Store the username in the context
    context.userName = userName
    # if we already have the chaincodeSpec, change secureContext
    if 'chaincodeSpec' in context:
        context.chaincodeSpec["secureContext"] = context.userName
Beispiel #16
0
def step_impl(context, userName, secret):
    assert 'compose_containers' in context, "compose_containers not found in context"
    assert 'table' in context, "table (of peers) not found in context"

    secretMsg = {
        "enrollId": userName,
        "enrollSecret" : secret
    }

    # Login to each container specified
    aliases = context.table.headings
    containers = [context.containerAliasMap[alias] for alias in aliases]
    for container in containers:
        context.response = bdd_request_util.httpPostToContainer(context, \
            container, "/registrar", secretMsg)

        # Create new User entry
        bdd_test_util.registerUser(context, secretMsg, container.composeService)

    # Store the username in the context
    context.userName = userName
    # if we already have the chaincodeSpec, change secureContext
    if 'chaincodeSpec' in context:
        context.chaincodeSpec["secureContext"] = context.userName