def create(self, msg: Dict, **kwargs) -> Propagate: ppg = Propagate(**msg) if ppg.request[f.IDENTIFIER.nm] != kwargs['identifier'] or \ ppg.request[f.REQ_ID.nm] != kwargs['req_id']: logger.debug('{} found PROPAGATE {} not ' 'satisfying query criteria'.format(self, ppg)) return None return ppg
def create(self, msg: Dict, **kwargs) -> Propagate: ppg = Propagate(**msg) request = self.node.client_request_class(**ppg.request) if request.digest != kwargs[f.DIGEST.nm]: logger.debug('{} found PROPAGATE {} not ' 'satisfying query criteria'.format(self, ppg)) return None return ppg
def evilCreatePropagate(self, request: Request, identifier: str) -> Propagate: logger.debug("EVIL: Creating propagate request for client request {}". format(request)) request.operation["amount"] += random.random() request._digest = request.getDigest() if isinstance(identifier, bytes): identifier = identifier.decode() return Propagate(request.as_dict, identifier)
def test_propagate_request(looper, node, sdk_wallet_steward, req): # Emulate Received PROPAGATE with the req propagate = Propagate(req.as_dict, "client_name") msg = emulate_received(node, propagate) # Create a new (requested) Propagate from the received data ph = PropagateHandler(node) kwargs = {f.DIGEST.nm: req.digest} received_propagate = ph.create(msg, **kwargs) assert received_propagate == propagate
def createPropagate(request: Union[Request, dict], identifier) -> Propagate: """ Create a new PROPAGATE for the given REQUEST. :param request: the client REQUEST :return: a new PROPAGATE msg """ if not isinstance(request, (Request, dict)): logger.error("Request not formatted properly to create propagate") return logger.debug("Creating PROPAGATE for REQUEST {}".format(request)) request = request.as_dict if isinstance(request, Request) else \ request if isinstance(identifier, bytes): identifier = identifier.decode() return Propagate(request, identifier)
def createPropagate( request: Union[Request, dict], client_name) -> Propagate: """ Create a new PROPAGATE for the given REQUEST. :param request: the client REQUEST :return: a new PROPAGATE msg """ if not isinstance(request, (Request, dict)): logger.error("{}Request not formatted properly to create propagate" .format(THREE_PC_PREFIX)) return logger.trace("Creating PROPAGATE for REQUEST {}".format(request)) request = request.as_dict if isinstance(request, Request) else \ request if isinstance(client_name, bytes): client_name = client_name.decode() return Propagate(request, client_name)
def _validate_requested_propagate(self, **kwargs): if not (RequestIdentifierField().validate( (kwargs['identifier'], kwargs['req_id']))): if 'propagate' in kwargs: try: # the input is expected as a dict (serialization with ujson==1.33) ppg = Propagate(**kwargs['propagate']) if ppg.request[f.IDENTIFIER.nm] != kwargs['identifier'] or \ ppg.request[f.REQ_ID.nm] != kwargs['req_id']: logger.warning('{} found PROPAGATE {} not ' 'satisfying query criteria'.format( self, *kwargs['ppg'])) return return ppg except TypeError as ex: logger.warning( '{} could not create PROPAGATE out of {}'.format( self, **kwargs['propagate'])) else: return True
def create(self, msg: Dict, **kwargs) -> Propagate: ppg = Propagate(**msg) request = self.node.client_request_class(**ppg.request) if request.digest != kwargs['digest']: raise MismatchedMessageReplyException return ppg
) commit_msg = Commit( 0, 1, 3, ) propagate_msg = Propagate( **{ 'request': { 'identifier': '5rArie7XKukPCaEwq5XGQJnM9Fc5aZE3M9HAPVfMU2xC', 'signature': 'ZbZG68WiaK67eU3CsgpVi85jpgCztW9Yqe7D5ezDUfWbKdiPPVbWq4Tb5m4Ur3jcR5wJ8zmBUZXZudjvMN63Aa9', 'operation': { 'amount': 62, 'type': 'buy' }, 'reqId': 1499782864169193, 'protocolVersion': CURRENT_PROTOCOL_VERSION }, 'senderClient': '+DG1:vO9#de6?R?>:3RwdAXSdefgLLfxSoN4WMEe' }) msg_reps_with_invalid_params = [ (LEDGER_STATUS, { 'p1': 'v1', 'p2': 'v2' }, LedgerStatus(1, 20, 1, 2, '77wuDUSr4FtAJzJbSqSW7bBw8bKAbra8ABSAjR72Nipq', CURRENT_PROTOCOL_VERSION)),