github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/bddtests/steps/orderer_impl.py (about)

     1  
     2  # Copyright IBM Corp. 2016 All Rights Reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #      http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  
    17  import os
    18  import re
    19  import time
    20  import subprocess
    21  import devops_pb2
    22  import fabric_pb2
    23  import chaincode_pb2
    24  
    25  import orderer_util
    26  from grpc.framework.interfaces.face.face import NetworkError
    27  from grpc.beta.interfaces import StatusCode
    28  
    29  from grpc.beta import implementations
    30  
    31  @given(u'user "{enrollId}" is an authorized user of the ordering service')
    32  def step_impl(context, enrollId):
    33      secretMsg = {
    34          "enrollId": enrollId,
    35          "enrollSecret" : enrollId
    36      }
    37      orderer_util.registerUser(context, secretMsg, "N/A")
    38  
    39  
    40  @when(u'user "{enrollId}" broadcasts "{numMsgsToBroadcast}" unique messages on "{composeService}"')
    41  def step_impl(context, enrollId, numMsgsToBroadcast, composeService):
    42      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    43      userRegistration.broadcastMessages(context, numMsgsToBroadcast, composeService)
    44  
    45  
    46  @when(u'user "{enrollId}" connects to deliver function on "{composeService}"')
    47  def step_impl(context, enrollId, composeService):
    48      # First get the properties
    49      assert 'table' in context, "table (Start | End) not found in context"
    50      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    51      streamHelper = userRegistration.connectToDeliverFunction(context, composeService)
    52  
    53  
    54  @when(u'user "{enrollId}" waits "{waitTime}" seconds')
    55  def step_impl(context, enrollId, waitTime):
    56      time.sleep(float(waitTime))
    57  
    58  
    59  @then(u'user "{enrollId}" should get a delivery from "{composeService}" of "{expectedBlocks}" blocks with "{numMsgsToBroadcast}" messages within "{batchTimeout}" seconds')
    60  def step_impl(context, enrollId, expectedBlocks, numMsgsToBroadcast, batchTimeout, composeService):
    61      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    62      streamHelper = userRegistration.getDelivererStreamHelper(context, composeService)
    63      blocks = streamHelper.getBlocks()
    64      # Verify block count
    65      assert len(blocks) == int(expectedBlocks), "Expected {0} blocks, received {1}".format(expectedBlocks, len(blocks))
    66  
    67  
    68  @when(u'user "{enrollId}" sends deliver a seek request on "{composeService}" with properties')
    69  def step_impl(context, enrollId, composeService):
    70      row = context.table.rows[0]
    71      start, end, = orderer_util.convertSeek(row['Start']), orderer_util.convertSeek(row['End'])
    72  
    73      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    74      streamHelper = userRegistration.getDelivererStreamHelper(context, composeService)
    75      streamHelper.seekToRange(start = start, end = end)