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
Exemple #2
0
def test_dirty_read(looper, nodeSet, client1, wallet1):
    """
    Tests the case when read request comes before write request is
    not executed on some nodes
    """

    slow_nodes = list(nodeSet)[2:4]
    for node in slow_nodes:
        logger.debug("Making node {} slow".format(node))
        make_node_slow(node)

    set_request = sendReqsToNodesAndVerifySuffReplies(looper,
                                                      wallet1,
                                                      client1,
                                                      numReqs=1)[0]

    received_replies = getRepliesFromClientInbox(inbox=client1.inBox,
                                                 reqId=set_request.reqId)

    seq_no = received_replies[0]["result"]["seqNo"]
    get_request = [wallet1.signOp({"type": GET_TXN, DATA: seq_no})]
    send_signed_requests(client1, get_request)
    waitForSufficientRepliesForRequests(looper, client1, requests=get_request)
    received_replies = getRepliesFromClientInbox(inbox=client1.inBox,
                                                 reqId=get_request[0].reqId)
    results = [str(reply['result'][DATA]) for reply in received_replies]

    assert len(set(results)) == 1
def test_plugin_dynamic_validation(nodeSet, looper, stewardWallet,
                                   steward1, client1Connected,
                                   sdk_wallet_steward, sdk_pool_handle):
    """
    Check plugin dynamic validation fails and passes
    """
    op = {
        TXN_TYPE: AUCTION_END,
        DATA: {'id': 'abcdef'}
    }
    send_signed_requests(steward1, sign_requests(stewardWallet, [op, ]))
    waitRejectFromPoolWithReason(looper, nodeSet, steward1,
                                 'unknown auction')

    op = {
        TXN_TYPE: AUCTION_START,
        DATA: {'id': 'xyz'}
    }
    successful_op(looper, op, sdk_wallet_steward, sdk_pool_handle)

    op = {
        TXN_TYPE: AUCTION_END,
        DATA: {'id': 'xyz'}
    }
    successful_op(looper, op, sdk_wallet_steward, sdk_pool_handle)
Exemple #4
0
def test_request_no_protocol_version(looper, txnPoolNodeSet, client1, wallet1,
                                     request_num):
    reqs = random_request_objects(request_num, protocol_version=None)
    reqs = sign_request_objects(wallet1, reqs)
    for req in reqs:
        assert req.protocolVersion is None

    send_signed_requests(client1, reqs)
    waitForSufficientRepliesForRequests(looper, client1, requests=reqs)
Exemple #5
0
def test_request_with_correct_version(looper, txnPoolNodeSet, client1, wallet1,
                                      request_num):
    reqs = random_request_objects(request_num,
                                  protocol_version=CURRENT_PROTOCOL_VERSION)
    reqs = sign_request_objects(wallet1, reqs)
    for req in reqs:
        assert req.protocolVersion == CURRENT_PROTOCOL_VERSION

    send_signed_requests(client1, reqs)
    waitForSufficientRepliesForRequests(looper, client1, requests=reqs)
Exemple #6
0
def test_version_not_set_by_default(looper, txnPoolNodeSet, client1, wallet1,
                                    request_num):
    req_dicts = random_requests(request_num)
    reqs = [Request(operation=op) for op in req_dicts]
    for req in reqs:
        assert req.protocolVersion is None
    reqs = sign_request_objects(wallet1, reqs)
    for req in reqs:
        assert req.protocolVersion is None

    send_signed_requests(client1, reqs)
    waitForSufficientRepliesForRequests(looper, client1, requests=reqs)
def test_request_with_invalid_version(tconf, looper, txnPoolNodeSet,
                                      client1, client1Connected,
                                      wallet1,
                                      request_num):
    reqs = random_request_objects(request_num, protocol_version=-1)
    reqs = sign_request_objects(wallet1, reqs)
    for req in reqs:
        assert req.protocolVersion == -1

    send_signed_requests(client1, reqs)
    for node in txnPoolNodeSet:
        looper.run(eventually(checkReqNackWithReason, client1,
                              'Unknown protocol version value -1',
                              node.clientstack.name, retryWait=1))
def testSendGetTxnReqForNotExistsSeqNo(looper, steward1, stewardWallet):
    op = {TXN_TYPE: GET_TXN, DATA: randint(100, 1000)}
    req = stewardWallet.signOp(op)
    send_signed_requests(steward1, [req])

    timeout = waits.expectedTransactionExecutionTime(len(
        steward1.inBox)) + c_delay
    get_txn_response = looper.run(
        eventually(checkSufficientRepliesReceived,
                   steward1.inBox,
                   req.reqId,
                   fValue,
                   retryWait=1,
                   timeout=timeout))

    assert not get_txn_response[DATA]
Exemple #9
0
def test_request_executed_once_and_without_failing_behind(
        tconf, looper, txnPoolNodeSet, client1, wallet1):
    """
    Checks that all requests executed only once and without failing behind in
    wrote transactions

    1. Send request
    2. When it is ordered - send checkpoint to replica to force it
    make garbage collection
    3. Check that ordered request executed and client receives reply
    4. Check that ledgers on all nodes are the same and contain all
    expected transactions
    """

    number_of_requests = 5
    tconf.CHK_FREQ = 1

    for node in txnPoolNodeSet:
        for replica in node.replicas:
            set_checkpoint_faking(replica)

    requests = [
        wallet1.signOp(req) for req in random_requests(number_of_requests)
    ]

    for request in requests:
        send_signed_requests(client1, [request])
        waitForSufficientRepliesForRequests(looper,
                                            client1,
                                            requests=[request])

    expected = [request.reqId for request in requests]
    for node in txnPoolNodeSet:
        real_ledger_state = [
            txn[1]['reqId']
            for txn in node.getLedger(DOMAIN_LEDGER_ID).getAllTxn()
            if 'reqId' in txn[1]
        ]
        assert expected == real_ledger_state
def test_plugin_static_validation(nodeSet, looper, stewardWallet,
                                  steward1, client1Connected,
                                  sdk_wallet_steward, sdk_pool_handle):
    """
    Check plugin static validation fails and passes
    """
    op = {
        TXN_TYPE: AUCTION_START
    }
    send_signed_requests(steward1, sign_requests(stewardWallet, [op, ]))
    waitReqNackFromPoolWithReason(looper, nodeSet, steward1,
                                  'attribute is missing or not in proper format')

    op = {
        TXN_TYPE: AUCTION_START,
        DATA: 'should be a dict but giving a string'
    }
    send_signed_requests(steward1, sign_requests(stewardWallet, [op, ]))
    waitReqNackFromPoolWithReason(looper, nodeSet, steward1,
                                  'attribute is missing or not in proper format')

    op = {
        TXN_TYPE: AUCTION_START,
        DATA: {'id': 'abc'}
    }

    successful_op(looper, op, sdk_wallet_steward, sdk_pool_handle)

    op = {
        TXN_TYPE: PLACE_BID,
        DATA: {'id': 'abc', AMOUNT: -3}
    }
    send_signed_requests(steward1, sign_requests(stewardWallet, [op, ]))
    waitReqNackFromPoolWithReason(looper, nodeSet, steward1,
                                  'must be present and should be a number')

    op = {
        TXN_TYPE: PLACE_BID,
        DATA: {'id': 'abc', AMOUNT: 20}
    }
    successful_op(looper, op, sdk_wallet_steward, sdk_pool_handle)
Exemple #11
0
def send_and_check(signed_reqs, looper, txnPoolNodeSet, client):
    reqs = send_signed_requests(client, signed_reqs)
    waitForSufficientRepliesForRequests(looper, client, requests=reqs)
    checkNodesHaveSameRoots(txnPoolNodeSet)
Exemple #12
0
 def sign_and_send(op):
     signed = wallet.signOp(op)
     send_signed_requests(client, [signed])
Exemple #13
0
def test_already_processed_requests(looper, txnPoolNodeSet, client1, wallet1,
                                    client1Connected):
    """
    Client re-sending request and checking that nodes picked the reply from
    ledger and did not process the request again
    """
    def get_method_call_count(method):
        counts = set()
        for node in txnPoolNodeSet:
            c = node.spylog.count(method)
            counts.add(c)
        assert len(counts) == 1
        return counts.pop()

    def get_getReplyFromLedger_call_count():
        return get_method_call_count(
            next(iter(txnPoolNodeSet)).getReplyFromLedger)

    def get_recordAndPropagate_call_count():
        return get_method_call_count(
            next(iter(txnPoolNodeSet)).recordAndPropagate)

    def get_last_returned_val():
        rvs = []
        for node in txnPoolNodeSet:
            rv = getAllReturnVals(node, node.getReplyFromLedger)
            rvs.append(rv[0])
        # All items are same in the list
        assert rvs.count(rvs[0]) == len(txnPoolNodeSet)
        return rvs[0]

    # Send a request
    rlc1 = get_getReplyFromLedger_call_count()
    rpc1 = get_recordAndPropagate_call_count()
    req1, = sendReqsToNodesAndVerifySuffReplies(looper, wallet1, client1, 1)
    rlc2 = get_getReplyFromLedger_call_count()
    rpc2 = get_recordAndPropagate_call_count()
    assert rlc2 - rlc1 == 1  # getReplyFromLedger was called
    assert rpc2 - rpc1 == 1  # recordAndPropagate was called
    r1 = get_last_returned_val()
    assert r1 is None  # getReplyFromLedger returned None since had not seen request

    req2, = sendReqsToNodesAndVerifySuffReplies(looper, wallet1, client1, 1)
    assert req2.reqId != req1.reqId
    rlc3 = get_getReplyFromLedger_call_count()
    rpc3 = get_recordAndPropagate_call_count()
    assert rlc3 - rlc2 == 1  # getReplyFromLedger was called again
    assert rpc3 - rpc2 == 1  # recordAndPropagate was called again
    r2 = get_last_returned_val()
    assert r2 is None  # getReplyFromLedger returned None since had not seen request

    # Reply for the first request, which is going to be sent again
    rep1 = client1.getReply(req1.identifier, req1.reqId)

    # Clear the client so that test waits for client getting reply
    client1.inBox.clear()
    client1.txnLog.reset()

    # Client re-sending request
    req3, = send_signed_requests(client1, [
        req1,
    ])
    waitForSufficientRepliesForRequests(looper, client1, requests=[
        req3,
    ])
    assert req3.reqId == req1.reqId
    rlc4 = get_getReplyFromLedger_call_count()
    rpc4 = get_recordAndPropagate_call_count()
    assert rlc4 - rlc3 == 1  # getReplyFromLedger was called again
    assert rpc4 - rpc3 == 0  # recordAndPropagate was not called
    r3 = get_last_returned_val()
    assert r3 is not None  # getReplyFromLedger did not return None this time since had seen request
    rep3 = client1.getReply(req3.identifier, req3.reqId)

    # Since txnTime is not stored in ledger and reading from ledger return
    # all possible fields from transactions
    rep3 = {k: v for k, v in rep3[0].items() if v is not None}
    rep1 = {k: v for k, v in rep1[0].items() if k in rep3}

    assert rep3 == rep1  # The reply client got is same as the previous one