github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/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 time
    18  
    19  import orderer_util
    20  
    21  @given(u'user "{enrollId}" is an authorized user of the ordering service')
    22  def step_impl(context, enrollId):
    23      secretMsg = {
    24          "enrollId": enrollId,
    25          "enrollSecret" : enrollId
    26      }
    27      orderer_util.registerUser(context, secretMsg, "N/A")
    28  
    29  
    30  @when(u'user "{enrollId}" broadcasts "{numMsgsToBroadcast}" unique messages on "{composeService}"')
    31  def step_impl(context, enrollId, numMsgsToBroadcast, composeService):
    32      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    33      userRegistration.broadcastMessages(context, numMsgsToBroadcast, composeService)
    34  
    35  
    36  @when(u'user "{enrollId}" connects to deliver function on "{composeService}"')
    37  def step_impl(context, enrollId, composeService):
    38      # First get the properties
    39      assert 'table' in context, "table (Start | End) not found in context"
    40      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    41      streamHelper = userRegistration.connectToDeliverFunction(context, composeService)
    42  
    43  
    44  @when(u'user "{enrollId}" waits "{waitTime}" seconds')
    45  def step_impl(context, enrollId, waitTime):
    46      time.sleep(float(waitTime))
    47  
    48  
    49  @then(u'user "{enrollId}" should get a delivery from "{composeService}" of "{expectedBlocks}" blocks with "{numMsgsToBroadcast}" messages within "{batchTimeout}" seconds')
    50  def step_impl(context, enrollId, expectedBlocks, numMsgsToBroadcast, batchTimeout, composeService):
    51      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    52      streamHelper = userRegistration.getDelivererStreamHelper(context, composeService)
    53      blocks = streamHelper.getBlocks()
    54      # Verify block count
    55      assert len(blocks) == int(expectedBlocks), "Expected {0} blocks, received {1}".format(expectedBlocks, len(blocks))
    56  
    57  
    58  @when(u'user "{enrollId}" sends deliver a seek request on "{composeService}" with properties')
    59  def step_impl(context, enrollId, composeService):
    60      row = context.table.rows[0]
    61      start, end, = orderer_util.convertSeek(row['Start']), orderer_util.convertSeek(row['End'])
    62  
    63      userRegistration = orderer_util.getUserRegistration(context, enrollId)
    64      streamHelper = userRegistration.getDelivererStreamHelper(context, composeService)
    65      streamHelper.seekToRange(start = start, end = end)