|
20 | 20 | import time
|
21 | 21 | import copy
|
22 | 22 | from datetime import datetime, timedelta
|
| 23 | +import base64 |
23 | 24 |
|
24 | 25 | import sys, requests, json
|
25 | 26 |
|
@@ -194,7 +195,6 @@ def getArgsFromContext(context):
|
194 | 195 | if 'table' in context:
|
195 | 196 | # There is ctor arguments
|
196 | 197 | args = context.table[0].cells
|
197 |
| - |
198 | 198 | return args
|
199 | 199 |
|
200 | 200 | @when(u'I deploy chaincode "{chaincodePath}" with ctor "{ctor}" to "{containerName}"')
|
@@ -239,16 +239,16 @@ def deployChainCodeToContainer(context, chaincode, containerName):
|
239 | 239 |
|
240 | 240 | def createChaincodeSpec(context, chaincode):
|
241 | 241 | chaincode = validateChaincodeDictionary(chaincode)
|
242 |
| - |
| 242 | + args = to_bytes(prepend(chaincode["constructor"], chaincode["args"])) |
| 243 | + # Create a ChaincodeSpec structure |
243 | 244 | chaincodeSpec = {
|
244 | 245 | "type": getChaincodeTypeValue(chaincode["language"]),
|
245 | 246 | "chaincodeID": {
|
246 | 247 | "path" : chaincode["path"],
|
247 | 248 | "name" : chaincode["name"]
|
248 | 249 | },
|
249 | 250 | "ctorMsg": {
|
250 |
| - "function" : chaincode["constructor"], |
251 |
| - "args" : chaincode["args"] |
| 251 | + "args" : args |
252 | 252 | },
|
253 | 253 | }
|
254 | 254 |
|
@@ -365,14 +365,12 @@ def invokeChaincode(context, devopsFunc, functionName, containerName, idGenAlg=N
|
365 | 365 | if 'table' in context:
|
366 | 366 | # There is ctor arguments
|
367 | 367 | args = context.table[0].cells
|
368 |
| - |
| 368 | + args = to_bytes(prepend(functionName, args)) |
369 | 369 | for idx, attr in enumerate(attributes):
|
370 | 370 | attributes[idx] = attr.strip()
|
371 | 371 |
|
372 |
| - context.chaincodeSpec['ctorMsg']['function'] = functionName |
373 | 372 | context.chaincodeSpec['ctorMsg']['args'] = args
|
374 | 373 | context.chaincodeSpec['attributes'] = attributes
|
375 |
| - |
376 | 374 | #If idGenAlg is passed then, we still using the deprecated devops API because this parameter can't be passed in the new API.
|
377 | 375 | if idGenAlg != None:
|
378 | 376 | invokeUsingDevopsService(context, devopsFunc, functionName, containerName, idGenAlg)
|
@@ -424,14 +422,14 @@ def invokeMasterChaincode(context, devopsFunc, chaincodeName, functionName, cont
|
424 | 422 | args = []
|
425 | 423 | if 'table' in context:
|
426 | 424 | args = context.table[0].cells
|
| 425 | + args = to_bytes(prepend(functionName, args)) |
427 | 426 | typeGolang = 1
|
428 | 427 | chaincodeSpec = {
|
429 | 428 | "type": typeGolang,
|
430 | 429 | "chaincodeID": {
|
431 | 430 | "name" : chaincodeName
|
432 | 431 | },
|
433 | 432 | "ctorMsg": {
|
434 |
| - "function" : functionName, |
435 | 433 | "args" : args
|
436 | 434 | }
|
437 | 435 | }
|
@@ -646,7 +644,7 @@ def step_impl(context, chaincodeName, functionName):
|
646 | 644 | if 'table' in context:
|
647 | 645 | # There is ctor arguments
|
648 | 646 | args = context.table[0].cells
|
649 |
| - context.chaincodeSpec['ctorMsg']['function'] = functionName |
| 647 | + args = to_bytes(prepend(functionName, args)) |
650 | 648 | context.chaincodeSpec['ctorMsg']['args'] = args #context.table[0].cells if ('table' in context) else []
|
651 | 649 | # Invoke the POST
|
652 | 650 | chaincodeOpPayload = createChaincodeOpPayload("query", context.chaincodeSpec)
|
@@ -678,8 +676,7 @@ def query_common(context, chaincodeName, functionName, value, failOnError):
|
678 | 676 | containerDataList = bdd_test_util.getContainerDataValuesFromContext(context, aliases, lambda containerData: containerData)
|
679 | 677 |
|
680 | 678 | # Update the chaincodeSpec ctorMsg for invoke
|
681 |
| - context.chaincodeSpec['ctorMsg']['function'] = functionName |
682 |
| - context.chaincodeSpec['ctorMsg']['args'] = [value] |
| 679 | + context.chaincodeSpec['ctorMsg']['args'] = to_bytes([functionName, value]) |
683 | 680 | # Invoke the POST
|
684 | 681 | # Make deep copy of chaincodeSpec as we will be changing the SecurityContext per call.
|
685 | 682 | chaincodeOpPayload = createChaincodeOpPayload("query", copy.deepcopy(context.chaincodeSpec))
|
@@ -819,3 +816,11 @@ def compose_op(context, op):
|
819 | 816 | else:
|
820 | 817 | parseComposeOutput(context)
|
821 | 818 | print("After {0}ing, the container service list is = {1}".format(op, [containerData.composeService for containerData in context.compose_containers]))
|
| 819 | + |
| 820 | +def to_bytes(strlist): |
| 821 | + return [base64.standard_b64encode(s.encode('ascii')) for s in strlist] |
| 822 | + |
| 823 | +def prepend(elem, l): |
| 824 | + if l is None or l == "": |
| 825 | + return [elem] |
| 826 | + return [elem] + l |
0 commit comments