def testOnlyAStewardCanAddAnotherSteward(looper, txnPoolNodeSet, tdirWithPoolTxns, poolTxnClientData, steward1, stewardWallet, client1, wallet1, client1Connected): addNewClient(STEWARD, looper, steward1, stewardWallet, "testSteward1") sendAddNewClient(STEWARD, "testSteward2", client1, wallet1) for node in txnPoolNodeSet: waitRejectWithReason(looper, client1, 'Only Steward is allowed to do these transactions', node.clientstack.name)
def testStewardsCanBeAddedOnlyTillAThresholdIsReached(looper, tconf, txnPoolNodeSet, tdirWithPoolTxns, poolTxnStewardData, steward1, stewardWallet): addNewClient(STEWARD, looper, steward1, stewardWallet, "testSteward3") sendAddNewClient(STEWARD, "testSteward4", steward1, stewardWallet) for node in txnPoolNodeSet: waitRejectWithReason(looper, steward1, 'New stewards cannot be added by other ' 'stewards as there are already {} ' 'stewards in the system'.format(tconf.stewardThreshold), node.clientstack.name)
def testSendGetTxnReqSameAsExpected(looper, steward1, stewardWallet): req, wallet = sendAddNewClient(STEWARD, "name", steward1, stewardWallet) timeout = waits.expectedTransactionExecutionTime(len( steward1.inBox)) + c_delay nym_response = looper.run( eventually(checkSufficientRepliesReceived, steward1.inBox, req.reqId, fValue, retryWait=1, timeout=timeout)) op = {TXN_TYPE: GET_TXN, DATA: nym_response['seqNo']} req = Request(identifier=stewardWallet.defaultId, operation=op, reqId=getTimeBasedId()) steward1.submitReqs(req) get_txn_response = looper.run( eventually(checkSufficientRepliesReceived, steward1.inBox, req.reqId, fValue, retryWait=1, timeout=timeout)) get_txn_response = json.loads(get_txn_response[DATA]) del nym_response['txnTime'] del get_txn_response['txnTime'] assert nym_response == get_txn_response
def testLoggingTxnStateWhenCommitFails(looper, txnPoolNodeSet, steward1, stewardWallet, logsearch): logsPropagate, _ = logsearch(levels=['INFO'], files=['propagator.py'], funcs=['propagate'], msgs=['propagating.*request.*from client']) logsOrdered, _ = logsearch(levels=['INFO'], files=['replica.py'], funcs=['order_3pc_key'], msgs=['ordered batch request']) logsCommitFail, _ = logsearch(levels=['WARNING'], files=['node.py'], funcs=['executeBatch'], msgs=['commit failed for batch request']) req, wallet = sendAddNewClient(None, "name", steward1, stewardWallet) class SomeError(Exception): pass def commitPatched(node, commitOrig, *args, **kwargs): req_handler = node.get_req_handler(ledger_id=DOMAIN_LEDGER_ID) req_handler.commit = commitOrig raise SomeError(ERORR_MSG) excCounter = 0 def executeBatchPatched(node, executeBatchOrig, *args, **kwargs): nonlocal excCounter try: executeBatchOrig(*args, **kwargs) except SomeError: excCounter += 1 node.executeBatch = executeBatchOrig pass def checkSufficientExceptionsHappend(): assert excCounter == len(txnPoolNodeSet) return for node in txnPoolNodeSet: req_handler = node.get_req_handler(ledger_id=DOMAIN_LEDGER_ID) req_handler.commit = functools.partial(commitPatched, node, req_handler.commit) node.executeBatch = functools.partial(executeBatchPatched, node, node.executeBatch) timeout = waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)) looper.run( eventually(checkSufficientExceptionsHappend, retryWait=1, timeout=timeout)) reqId = str(req.reqId) assert any(reqId in record.getMessage() for record in logsPropagate) assert any(reqId in record.getMessage() for record in logsOrdered) assert any(reqId in record.getMessage() for record in logsCommitFail) assert any(ERORR_MSG in record.getMessage() for record in logsCommitFail)
def testLoggingTxnStateForInvalidRequest(looper, txnPoolNodeSet, clientAndWallet1, client1Connected, logsearch): client, clientWallet = clientAndWallet1 logsPropagate, _ = logsearch(levels=['INFO'], files=['propagator.py'], funcs=['propagate'], msgs=['propagating.*request.*from client']) logsReject, _ = logsearch( levels=['WARNING'], files=['replica.py'], funcs=['processReqDuringBatch'], msgs=['encountered exception.*while processing.*will reject']) req, wallet = sendAddNewClient(STEWARD, "name", client, clientWallet) ensureRejectsRecvd( looper, txnPoolNodeSet, client, reason="Only Steward is allowed to do these transactions", timeout=waits.expectedReqRejectQuorumTime()) reqId = str(req.reqId) assert any(reqId in record.getMessage() for record in logsPropagate) assert any(reqId in record.getMessage() for record in logsReject)
def testLoggingTxnStateForValidRequest(looper, steward1, stewardWallet, logsearch): logsPropagate, _ = logsearch(levels=['INFO'], files=['propagator.py'], funcs=['propagate'], msgs=['propagating.*request.*from client']) logsOrdered, _ = logsearch(levels=['INFO'], files=['replica.py'], funcs=['order_3pc_key'], msgs=['ordered batch request']) logsCommited, _ = logsearch(levels=['INFO'], files=['node.py'], funcs=['executeBatch'], msgs=['committed batch request']) req, wallet = sendAddNewClient(None, "name", steward1, stewardWallet) nNodes = len(steward1.inBox) timeout = waits.expectedTransactionExecutionTime(nNodes) looper.run( eventually(check_sufficient_replies_received, steward1, req.identifier, req.reqId, retryWait=1, timeout=timeout)) reqId = str(req.reqId) assert any(reqId in record.getMessage() for record in logsPropagate) assert any(reqId in record.getMessage() for record in logsOrdered) assert any(reqId in record.getMessage() for record in logsCommited)
def testSendGetTxnReqSameAsExpected(looper, steward1, stewardWallet): req, wallet = sendAddNewClient(STEWARD, "name", steward1, stewardWallet) timeout = waits.expectedTransactionExecutionTime( len(steward1.inBox)) + c_delay nym_response = \ looper.run(eventually(check_sufficient_replies_received, steward1, req.identifier, req.reqId, retryWait=1, timeout=timeout)) op = { TXN_TYPE: GET_TXN, DATA: nym_response['seqNo'] } req = Request(identifier=stewardWallet.defaultId, operation=op, reqId=getTimeBasedId(), protocolVersion=CURRENT_PROTOCOL_VERSION) steward1.submitReqs(req) get_txn_response = \ looper.run(eventually(check_sufficient_replies_received, steward1, req.identifier, req.reqId, retryWait=1, timeout=timeout)) nym_response.pop('txnTime', None) get_txn_response[DATA].pop('txnTime', None) assert nym_response == get_txn_response[DATA]
def testSendGetTxnReqSameAsExpected(looper, steward1, stewardWallet): req, wallet = sendAddNewClient(STEWARD, "name", steward1, stewardWallet) timeout = waits.expectedTransactionExecutionTime(len( steward1.inBox)) + c_delay nym_response = looper.run( eventually(checkSufficientRepliesReceived, steward1.inBox, req.reqId, fValue, retryWait=1, timeout=timeout)) op = {TXN_TYPE: GET_TXN, DATA: nym_response['seqNo']} req = stewardWallet.signOp(op) send_signed_requests(steward1, [req]) get_txn_response = looper.run( eventually(checkSufficientRepliesReceived, steward1.inBox, req.reqId, fValue, retryWait=1, timeout=timeout)) get_txn_response = json.loads(get_txn_response[DATA]) del nym_response['txnTime'] del get_txn_response['txnTime'] assert nym_response == get_txn_response