def evilCreatePropagate(self, request: Request, clientName: str) -> Propagate: logger.debug( "EVIL: Creating propagate request for client request {}".format( request)) request.operation["amount"] += random.random() return Propagate(request.__getstate__(), clientName)
async def go(ctx): client1, wallet = genTestClient(ctx.nodeset, tmpdir=ctx.tmpdir) # remove the client's ability to sign assert wallet.defaultId wallet.defaultId = None assert not wallet.defaultId ctx.looper.add(client1) await client1.ensureConnectedToNodes() request = Request(randomOperation()) request = client1.submitReqs(request)[0] with pytest.raises(AssertionError): for node in ctx.nodeset: await eventually(checkLastClientReqForNode, node, request, retryWait=1, timeout=10) for n in ctx.nodeset: params = n.spylog.getLastParams(Node.handleInvalidClientMsg) ex = params['ex'] _, frm = params['wrappedMsg'] assert isinstance(ex, EmptySignature) assert frm == client1.name params = n.spylog.getLastParams(Node.discard) reason = params["reason"] (msg, frm) = params["msg"] assert msg == request.__dict__ assert frm == client1.name assert "EmptySignature" in reason
def signOp(self, op: Dict, identifier: Identifier=None) -> Request: """ Signs the message if a signer is configured :param identifier: signing identifier; if not supplied the default for the wallet is used. :param op: Operation to be signed :return: a signed Request object """ request = Request(operation=op) return self.signRequest(request, identifier)
def signRequest(self, req: Request, identifier: Identifier=None) -> Request: """ Signs request. Modifies reqId and signature. May modify identifier. :param req: request :param requestIdStore: request id generator :param identifier: signer identifier :return: signed request """ idr = self._requiredIdr(idr=identifier or req.identifier) idData = self._getIdData(idr) req.identifier = idr req.reqId = getTimeBasedId() self.ids[idr] = IdData(idData.signer, req.reqId) req.signature = self.signMsg(msg=req.getSigningState(), identifier=idr, otherIdentifier=req.identifier) return req
def createRequest(self, operation: Mapping, identifier: str = None) -> Request: """ Client creates request which include requested operation and request Id :param operation: requested operation :return: New client request """ request = Request(identifier or self.defaultIdentifier, self.lastReqId + 1, operation) self.lastReqId += 1 return request
def createRequest(self, operation: Mapping, identifier: str = None) -> Request: """ Client creates request which include requested operation and request Id :param operation: requested operation :return: New client request """ request = Request(identifier=identifier or self.defaultIdentifier, operation=operation) # DEPR # self.setReqId(request) return request
def evilCreatePropagate(self, request: Request, clientName: str) -> Propagate: logger.debug("EVIL: Creating propagate request for client request {}". format(request)) request.operation["amount"] += random.random() return Propagate(request.__getstate__(), clientName)
def serializeReq(req: Request) -> str: return json.dumps(req.__getstate__())