Exemplo n.º 1
0
def test_send_claim_def_with_fees(helpers,
                                  looper,
                                  nodeSetWithIntegratedTokenPlugin,
                                  sdk_wallet_trustee,
                                  sdk_pool_handle,
                                  schema_json,
                                  fees_set, address_main, mint_tokens):
    req = helpers.request.claim_def(schema_json, sdk_wallet=sdk_wallet_trustee)
    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    utxos = [{"source": utxo_from_addr_and_seq_no(address_main, init_seq_no),
              AMOUNT: amount}]
    req = Request(**json.loads(req))
    req = add_fees_request_with_address(
        helpers,
        fees_set,
        req,
        address_main,
        utxos=utxos
    )

    token_len = len(nodeSetWithIntegratedTokenPlugin[0].ledgers[-1])
    write_rep = helpers.sdk.send_and_check_request_objects([req], wallet=sdk_wallet_trustee)
    assert token_len == len(nodeSetWithIntegratedTokenPlugin[0].ledgers[-1]) - 1
    assert get_last_token_txn(nodeSetWithIntegratedTokenPlugin)[1]['txn']['data']['fees'] == CLAIM_DEF_FEE

    added_claim_def_id = write_rep[0][1]['result'][TXN_METADATA][TXN_METADATA_ID]
    request = looper.loop.run_until_complete(build_get_cred_def_request(sdk_wallet_trustee[1], added_claim_def_id))
    read_rep = sdk_get_and_check_replies(looper,
                                         [sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_trustee, request)])
    assert req.operation[DATA] == read_rep[0][1]['result'][DATA]
Exemplo n.º 2
0
def test_last_committed_after_catchup(looper, helpers,
                                      nodeSetWithIntegratedTokenPlugin,
                                      sdk_pool_handle,
                                      fees_set, address_main, mint_tokens):
    node_set = nodeSetWithIntegratedTokenPlugin
    reverted_node = node_set[-1]

    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    request_1, request_2 = nyms_with_fees(2,
                                          helpers,
                                          fees_set,
                                          address_main,
                                          amount,
                                          init_seq_no=init_seq_no)
    reverted_last_committed = get_last_committed_from_tracker(reverted_node)
    not_reverted_last_committed = get_last_committed_from_tracker(node_set[-1])
    assert reverted_last_committed == not_reverted_last_committed
    with delay_rules(reverted_node.nodeIbStasher, cDelay()):
        """
        Send NYM with FEES and wait for reply. 
        """
        r = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle, helpers.request._steward_wallet, request_1)
        sdk_get_and_check_replies(looper, [r])
        """
        Start catchup. Uncommitted batch for reverted_node should be rejected and it will get 
        NYM with FEES during catchup procedure. 
        """
        reverted_node.start_catchup()
        looper.run(eventually(lambda: assertExp(reverted_node.mode == Mode.participating)))
        assert get_last_committed_from_tracker(reverted_node) ==\
               get_last_committed_from_tracker(node_set[0])
def two_requests(looper, helpers,
                 nodeSetWithIntegratedTokenPlugin,
                 sdk_pool_handle,
                 fees_set, address_main, mint_tokens, sdk_wallet_steward):
    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1

    seed = randomString(32)
    alias = randomString(5)
    wh, _ = sdk_wallet_steward
    nym_request, new_did = looper.loop.run_until_complete(
        prepare_nym_request(sdk_wallet_steward, seed,
                            alias, None))
    nym_request = \
        sdk_sign_request_objects(looper, sdk_wallet_steward, [sdk_json_to_request_object(json.loads(nym_request))])[0]
    req_obj = sdk_json_to_request_object(json.loads(nym_request))
    helpers.request.nym = lambda: copy.deepcopy(req_obj)

    req1, req2 = nyms_with_fees(2,
                                helpers,
                                fees_set,
                                address_main,
                                amount,
                                init_seq_no=init_seq_no)

    assert req1.payload_digest == req2.payload_digest
    assert req1.digest != req2.digest
    return req1, req2
Exemplo n.º 4
0
def test_chain_set_fees_and_nym_batch_size_2(looper, helpers,
                                             nodeSetWithIntegratedTokenPlugin,
                                             sdk_pool_handle,
                                             sdk_wallet_trustee, mint_tokens,
                                             addresses, poolConfigWTFF):
    """
    Set FEES for NYM with cost 2

    Send any transaction to config ledger.

    Send NYM with fees 2 from A

    Set FEES for NYM with cost 3

    Send any transaction to config ledger.

    Send NYM with fees 3 from A

    Check that first NYM is not written and second NYM is.
    """
    A, B = addresses
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = get_seq_no(mint_tokens)

    # Set fees and some config txn
    fees_nym_2 = {NYM_FEES_ALIAS: 2}
    fees_2_resp = helpers.general.set_fees_without_waiting(fees_nym_2)
    sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_trustee,
                         poolConfigWTFF)
    sdk_get_and_check_replies(looper, fees_2_resp)

    # NYM with fees 2 from A
    _, _, b_2_nym = send_and_check_nym_with_fees(helpers, {'fees': fees_nym_2},
                                                 seq_no,
                                                 looper, [A],
                                                 current_amount,
                                                 check_reply=False)
    # Set fees for NYM to 3
    fees_nym_3 = {NYM_FEES_ALIAS: 3}
    fees_3_resp = helpers.general.set_fees_without_waiting(fees_nym_3)
    sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_trustee,
                         poolConfigWTFF)
    sdk_get_and_check_replies(looper, fees_3_resp)

    # Send NYM with fees 3
    current_amount, seq_no, b_3_nym = send_and_check_nym_with_fees(
        helpers, {'fees': fees_nym_3},
        seq_no,
        looper, [A],
        current_amount,
        check_reply=False)

    with pytest.raises(RequestRejectedException):
        sdk_get_and_check_replies(looper, b_2_nym)
    sdk_get_and_check_replies(looper, b_3_nym)
    a_get = helpers.general.do_get_utxo(A)
    assert a_get[OUTPUTS][1][AMOUNT] == current_amount
    assert a_get[OUTPUTS][1][SEQNO] == seq_no

    ensure_all_nodes_have_same_data(looper, nodeSetWithIntegratedTokenPlugin)
def test_validation_nym_with_fees_more_than_required(fees,
                                                     helpers,
                                                     nodeSetWithIntegratedTokenPlugin,
                                                     address_main,
                                                     sdk_pool_handle,
                                                     sdk_wallet_trustee,
                                                     mint_tokens,
                                                     looper):
    """
    Steps:
    1. Checks that nym with fees will be rejected, because fees are not set
    2. Send auth_rule txn with fees in metadata and set fees for pool
    3. Resend nym with fees more than required and check, that it will be rejected
    """
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1
    with pytest.raises(RequestRejectedException, match="Fees are not required for this txn type"):
        current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, {FEES: fees}, seq_no, looper, [address_main],
                                                                 current_amount)


    helpers.general.do_set_fees(fees, fill_auth_map=False)
    original_action = add_new_identity_owner
    original_constraint = auth_map.get(add_new_identity_owner.get_action_id())
    original_constraint.set_metadata({'fees': NYM_FEES_ALIAS})
    sdk_send_and_check_auth_rule_request(looper,
                                         sdk_pool_handle,
                                         sdk_wallet_trustee,
                                         auth_action=ADD_PREFIX, auth_type=NYM,
                                         field=original_action.field, new_value=original_action.value,
                                         old_value=None, constraint=original_constraint.as_dict)
    with pytest.raises(RequestRejectedException, match="ExtraFundsError"):
        current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, {FEES: {NYM_FEES_ALIAS: fees[NYM_FEES_ALIAS] + 1}}, seq_no, looper, [address_main],
                                                                 current_amount)
    ensure_all_nodes_have_same_data(looper, nodeSetWithIntegratedTokenPlugin)
def test_apply_several_batches(looper, helpers,
                               nodeSetWithIntegratedTokenPlugin,
                               sdk_pool_handle, fees_set, address_main,
                               mint_tokens):
    node_set = [n.nodeIbStasher for n in nodeSetWithIntegratedTokenPlugin]
    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    request1, request2 = nyms_with_fees(2,
                                        helpers,
                                        fees_set,
                                        address_main,
                                        amount,
                                        init_seq_no=init_seq_no)
    expected_txns_length = 2
    txns_count_before = get_committed_txns_count_for_pool(
        nodeSetWithIntegratedTokenPlugin, TOKEN_LEDGER_ID)
    with delay_rules(node_set, cDelay()):
        r1 = sdk_send_signed_requests(sdk_pool_handle,
                                      [json.dumps(request1.as_dict)])
        r2 = sdk_send_signed_requests(sdk_pool_handle,
                                      [json.dumps(request2.as_dict)])
        for n in nodeSetWithIntegratedTokenPlugin:
            looper.run(
                eventually(check_uncommitted_txn,
                           n,
                           expected_txns_length,
                           TOKEN_LEDGER_ID,
                           retryWait=0.2,
                           timeout=15))

    sdk_get_and_check_replies(looper, r1)
    sdk_get_and_check_replies(looper, r2)
    txns_count_after = get_committed_txns_count_for_pool(
        nodeSetWithIntegratedTokenPlugin, TOKEN_LEDGER_ID)
    assert txns_count_after - txns_count_before == expected_txns_length
def test_revert_works_for_fees_after_view_change(looper, helpers,
                                                 nodeSetWithIntegratedTokenPlugin,
                                                 sdk_pool_handle,
                                                 fees_set,
                                                 mint_tokens, addresses, fees):
    node_set = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = get_seq_no(mint_tokens)
    reverted_node = nodeSetWithIntegratedTokenPlugin[-1]

    current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, fees_set, seq_no, looper, addresses,
                                                             current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(helpers, addresses, fees, looper, current_amount, seq_no)

    with delay_rules_without_processing(reverted_node.nodeIbStasher, delay_3pc(view_no=0, msgs=Commit)):
        len_batches_before = len(reverted_node.master_replica._ordering_service.batches)
        current_amount, seq_no, _ = send_and_check_transfer(helpers, addresses, fees, looper, current_amount, seq_no)
        current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, fees_set, seq_no, looper, addresses,
                                                                 current_amount)
        looper.runFor(waits.expectedPrePrepareTime(len(nodeSetWithIntegratedTokenPlugin)))
        len_batches_after = len(reverted_node.master_replica._ordering_service.batches)

        """
        Checks, that we have a 2 new batches
        """
        assert len_batches_after - len_batches_before == 2
        for n in node_set:
            n.view_changer.on_master_degradation()
        ensure_view_change(looper, nodeSetWithIntegratedTokenPlugin)

        looper.run(eventually(lambda: assertExp(reverted_node.mode == Mode.participating)))
    ensure_all_nodes_have_same_data(looper, node_set)

    send_and_check_nym_with_fees(helpers, fees_set, seq_no, looper, addresses, current_amount)
    ensure_all_nodes_have_same_data(looper, node_set)
def test_revert_nym_with_fees_before_catchup(looper, helpers,
                                             nodeSetWithIntegratedTokenPlugin,
                                             fees_set, fees, xfer_mint_tokens,
                                             xfer_addresses):
    nodes = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(xfer_mint_tokens)
    seq_no = get_seq_no(xfer_mint_tokens)
    lagging_node = nodes[-1]
    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, xfer_addresses, current_amount)
    with delay_rules_without_processing(lagging_node.nodeIbStasher, cDelay(),
                                        pDelay()):
        current_amount, seq_no, _ = send_and_check_nym_with_fees(
            helpers, fees_set, seq_no, looper, xfer_addresses, current_amount)
        looper.runFor(waits.expectedPrePrepareTime(len(nodes)))
        lagging_node.start_catchup()
        for n in nodes:
            looper.run(
                eventually(lambda: assertExp(n.mode == Mode.participating)))
        for n in nodes:
            looper.run(
                eventually(check_state, n, True, retryWait=0.2, timeout=15))
    ensure_all_nodes_have_same_data(looper, nodes)
    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, xfer_addresses, current_amount)
    ensure_all_nodes_have_same_data(looper, nodes)
Exemplo n.º 9
0
def test_malicious_primary_sent_pp(looper, helpers,
                                   nodeSetWithIntegratedTokenPlugin,
                                   sdk_pool_handle, fees_set, address_main,
                                   mint_tokens):
    def raise_invalid_ex():
        raise InvalidClientMessageException(1, 2, 3)

    nodes = nodeSetWithIntegratedTokenPlugin
    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    request1, request2 = nyms_with_fees(2,
                                        helpers,
                                        fees_set,
                                        address_main,
                                        amount,
                                        init_seq_no=init_seq_no)
    malicious_primary = getPrimaryReplica(nodes).node
    not_malicious_nodes = set(nodes) - {malicious_primary}
    for n in not_malicious_nodes:
        n.doDynamicValidation = lambda *args, **kwargs: raise_invalid_ex()
    r1 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                     helpers.request._steward_wallet, request1)

    with pytest.raises(RequestRejectedException,
                       match="client request invalid"):
        sdk_get_and_check_replies(looper, [r1])
def test_apply_several_batches_with_several_txns(
        looper, helpers, nodeSetWithIntegratedTokenPlugin, sdk_pool_handle,
        fees_set, address_main, mint_tokens):
    current_amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    node_set = nodeSetWithIntegratedTokenPlugin
    all_reqs = nyms_with_fees(NUM_BATCHES * TXN_IN_BATCH,
                              helpers,
                              fees_set,
                              address_main,
                              current_amount,
                              init_seq_no=init_seq_no)
    domain_txns_before = get_committed_txns_count_for_pool(
        node_set, DOMAIN_LEDGER_ID)
    token_txns_before = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    sdk_requests = []
    for req in all_reqs:
        r = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                        helpers.request._steward_wallet, req)
        sdk_requests.append(r)
    looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
    sdk_get_and_check_replies(looper, sdk_requests)
    domain_txns_after = get_committed_txns_count_for_pool(
        node_set, DOMAIN_LEDGER_ID)
    token_txns_after = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)

    assert domain_txns_after - domain_txns_before == NUM_BATCHES * TXN_IN_BATCH
    assert token_txns_after - token_txns_before == NUM_BATCHES * TXN_IN_BATCH
Exemplo n.º 11
0
def test_send_nym_with_fees(helpers, looper, nodeSetWithIntegratedTokenPlugin,
                            sdk_wallet_trustee, sdk_wallet_steward,
                            sdk_pool_handle, fees_set, address_main,
                            mint_tokens):
    req = helpers.request.nym_new(sdk_wallet=sdk_wallet_trustee)
    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    utxos = [{
        "source": utxo_from_addr_and_seq_no(address_main, init_seq_no),
        AMOUNT: amount
    }]
    req = Request(**json.loads(req))
    req = add_fees_request_with_address(helpers,
                                        fees_set,
                                        req,
                                        address_main,
                                        utxos=utxos)

    token_len = len(nodeSetWithIntegratedTokenPlugin[0].ledgers[-1])
    helpers.sdk.send_and_check_request_objects([req],
                                               wallet=sdk_wallet_trustee)
    assert token_len == len(
        nodeSetWithIntegratedTokenPlugin[0].ledgers[-1]) - 1
    assert get_last_token_txn(
        nodeSetWithIntegratedTokenPlugin)[1]['txn']['data']['fees'] == NYM_FEE

    request = looper.loop.run_until_complete(
        build_get_nym_request(sdk_wallet_trustee[1], req.operation['dest']))
    read_rep = sdk_get_and_check_replies(looper, [
        sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_trustee, request)
    ])
    reply = json.loads(read_rep[0][1]['result'][DATA])
    assert req.operation['dest'] == reply['dest']
    assert req.operation['verkey'] == reply['verkey']
def test_create_did_without_endorser_payment(looper, nodeSetWithIntegratedTokenPlugin, nym_txn_data, sdk_pool_handle,
                                             fees_set, address_main, mint_tokens, changed_auth_rule,
                                             sdk_wallet_trustee, helpers):
    sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee)

    wh, alias, sender_did, sender_verkey = nym_txn_data
    req = looper.loop.run_until_complete(
        build_nym_request(sender_did, sender_did, sender_verkey, alias, NEW_ROLE))

    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    utxos = [{"source": utxo_from_addr_and_seq_no(address_main, init_seq_no),
              AMOUNT: amount}]
    req = Request(**json.loads(req))
    req = add_fees_request_with_address(
        helpers,
        fees_set,
        req,
        address_main,
        utxos=utxos
    )

    rep = helpers.sdk.send_and_check_request_objects([req], wallet=(wh, sender_did))

    details = get_nym_details(nodeSetWithIntegratedTokenPlugin[0].states[1], sender_did, is_committed=True)
    assert details[ROLE] == NEW_ROLE
    assert details[VERKEY] == sender_verkey
def test_multiple_batches_for_pool(looper, helpers,
                                   nodeSetWithIntegratedTokenPlugin,
                                   sdk_pool_handle, fees_set, address_main,
                                   mint_tokens):
    node_set = nodeSetWithIntegratedTokenPlugin
    node_stashers = [n.nodeIbStasher for n in node_set]

    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    request1, request2 = nyms_with_fees(2,
                                        helpers,
                                        fees_set,
                                        address_main,
                                        amount,
                                        init_seq_no=init_seq_no)

    txns_count_before = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    with delay_rules(node_stashers, cDelay()):
        r1 = sdk_send_signed_requests(sdk_pool_handle,
                                      [json.dumps(request1.as_dict)])
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        r2 = sdk_send_signed_requests(sdk_pool_handle,
                                      [json.dumps(request2.as_dict)])
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        for n in node_set:
            n.start_catchup()
        for n in node_set:
            looper.run(
                eventually(lambda: assertExp(n.mode == Mode.participating)))
    txns_count_after = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    assert txns_count_after == txns_count_before
    ensure_all_nodes_have_same_data(looper, node_set)
def test_revert_works_for_fees_before_catch_up_on_one_node(
        looper, helpers, nodeSetWithIntegratedTokenPlugin, sdk_pool_handle,
        fees_set, address_main, mint_tokens):
    node_set = nodeSetWithIntegratedTokenPlugin
    reverted_node = node_set[-1]

    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    request_1, request_2 = nyms_with_fees(2,
                                          helpers,
                                          fees_set,
                                          address_main,
                                          amount,
                                          init_seq_no=init_seq_no)
    c_ledger_root_before = get_committed_txn_root_for_pool([reverted_node],
                                                           TOKEN_LEDGER_ID)
    with delay_rules(reverted_node.nodeIbStasher, cDelay()):
        """
        Send NYM with FEES and wait for reply. All of nodes, except reverted_node will order them 
        """
        r = sdk_send_signed_requests(sdk_pool_handle,
                                     [json.dumps(request_1.as_dict)])
        sdk_get_and_check_replies(looper, r)
        check_state(reverted_node, is_equal=False)
        c_ledger_root_for_other = get_committed_txn_root_for_pool(
            node_set[:-1], TOKEN_LEDGER_ID)
        """
        Start catchup. Uncommitted batch for reverted_node should be rejected and it will get 
        NYM with FEES during catchup procedure. 
        """
        reverted_node.start_catchup()
        looper.run(
            eventually(
                lambda: assertExp(reverted_node.mode == Mode.participating)))
        check_state(reverted_node, is_equal=True)
        """
        Check, that committed txn root was changed and it's the same as for others
        """
        c_ledger_root_after = get_committed_txn_root_for_pool([reverted_node],
                                                              TOKEN_LEDGER_ID)
        assert c_ledger_root_after != c_ledger_root_before
        assert c_ledger_root_after == c_ledger_root_for_other
    ensure_all_nodes_have_same_data(looper, node_set)
    c_ledger_root_before = get_committed_txn_root_for_pool(
        node_set, TOKEN_LEDGER_ID)
    """
    Send another NYM with FEES and check, that committed ledger's root was changed
    """
    r = sdk_send_signed_requests(sdk_pool_handle,
                                 [json.dumps(request_2.as_dict)])
    sdk_get_and_check_replies(looper, r)
    c_ledger_root_after = get_committed_txn_root_for_pool(
        node_set, TOKEN_LEDGER_ID)
    assert c_ledger_root_after != c_ledger_root_before
    ensure_all_nodes_have_same_data(looper, node_set)
    for n in node_set:
        check_state(n, is_equal=True)
Exemplo n.º 15
0
def test_revert_for_all_after_view_change(looper, helpers,
                                          nodeSetWithIntegratedTokenPlugin,
                                          sdk_pool_handle, fees_set,
                                          mint_tokens, addresses, fees):
    node_set = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = get_seq_no(mint_tokens)
    reverted_node = nodeSetWithIntegratedTokenPlugin[-1]

    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, addresses, current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(
        helpers, addresses, fees, looper, current_amount, seq_no)

    ensure_all_nodes_have_same_data(looper, node_set)

    with delay_rules([n.nodeIbStasher for n in node_set], cDelay(), pDelay()):
        len_batches_before = len(reverted_node.master_replica.batches)
        current_amount, seq_no, resp1 = send_and_check_transfer(
            helpers,
            addresses,
            fees,
            looper,
            current_amount,
            seq_no,
            check_reply=False)
        current_amount, seq_no, resp2 = send_and_check_nym_with_fees(
            helpers,
            fees_set,
            seq_no,
            looper,
            addresses,
            current_amount,
            check_reply=False)
        looper.runFor(
            waits.expectedPrePrepareTime(
                len(nodeSetWithIntegratedTokenPlugin)))
        len_batches_after = len(reverted_node.master_replica.batches)
        """
        Checks, that we have a 2 new batches
        """
        assert len_batches_after - len_batches_before == 2
        for n in node_set:
            n.view_changer.on_master_degradation()

        ensure_view_change_complete(looper, nodeSetWithIntegratedTokenPlugin)

        looper.run(
            eventually(
                lambda: assertExp(reverted_node.mode == Mode.participating)))
    ensure_all_nodes_have_same_data(looper, node_set)
    sdk_get_and_check_replies(looper, resp1)
    sdk_get_and_check_replies(looper, resp2)
    send_and_check_nym_with_fees(helpers, fees_set, seq_no, looper, addresses,
                                 current_amount)
    ensure_all_nodes_have_same_data(looper, node_set)
Exemplo n.º 16
0
def test_first_catchup_with_not_empty_ledger(looper, helpers,
                                             nodeSetWithIntegratedTokenPlugin,
                                             sdk_pool_handle,
                                             sdk_wallet_trustee,
                                             fees_set,
                                             mint_tokens, addresses, fees,
                                             tconf,
                                             tdir, allPluginsPath, do_post_node_creation):
    node_set = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1
    reverted_node = node_set[-1]
    idx = node_set.index(reverted_node)

    current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, fees_set, seq_no, looper, addresses,
                                                             current_amount)

    reverted_node.cleanupOnStopping = False
    disconnect_node_and_ensure_disconnected(looper,
                                            node_set,
                                            reverted_node.name)
    looper.removeProdable(name=reverted_node.name)

    from_a_to_b = [addresses[0], addresses[1]]
    from_b_to_c = [addresses[1], addresses[2]]
    from_c_to_d = [addresses[2], addresses[3]]
    from_d_to_a = [addresses[3], addresses[0]]

    # current_amount, seq_no, _ = add_nym_with_fees(helpers, fees_set, seq_no, looper, addresses, current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(helpers, from_a_to_b, fees, looper,
                                                        current_amount, seq_no,
                                                        transfer_summ=current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(helpers, from_b_to_c, fees, looper,
                                                        current_amount, seq_no,
                                                        transfer_summ=current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(helpers, from_c_to_d, fees, looper,
                                                        current_amount, seq_no,
                                                        transfer_summ=current_amount)

    # add node_to_disconnect to pool
    node_to_disconnect = start_stopped_node(reverted_node, looper, tconf,
                                            tdir, allPluginsPath, start=False)
    do_post_node_creation(node_to_disconnect)
    looper.add(node_to_disconnect)

    node_set[idx] = node_to_disconnect
    looper.run(checkNodesConnected(node_set))
    helpers.node.fill_auth_map_for_node(node_to_disconnect, XFER_PUBLIC)
    current_amount, seq_no, _ = send_and_check_transfer(helpers, from_d_to_a, fees, looper,
                                                        current_amount, seq_no, transfer_summ=current_amount)
    ensure_all_nodes_have_same_data(looper, node_set)
Exemplo n.º 17
0
def test_catchup_several_batches(looper, helpers,
                                 nodeSetWithIntegratedTokenPlugin,
                                 sdk_pool_handle, fees_set, address_main,
                                 mint_tokens):
    current_amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    node_set = nodeSetWithIntegratedTokenPlugin
    """
    Prepare NUM_BATCHES * TXN_IN_BATCH requests and 1 for checking pool functional
    """
    all_reqs = nyms_with_fees(NUM_BATCHES * TXN_IN_BATCH + 1,
                              helpers,
                              fees_set,
                              address_main,
                              current_amount,
                              init_seq_no=init_seq_no)
    reqs_to_catchup = all_reqs[:-1]
    req_for_check = all_reqs[-1]
    reverted_node = node_set[-1]
    with delay_rules(reverted_node.nodeIbStasher, cDelay()):

        len_batches_before = len(
            reverted_node.master_replica._ordering_service.batches)
        sdk_requests = []
        for req in reqs_to_catchup:
            r = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                            helpers.request._steward_wallet,
                                            req)
            sdk_requests.append(r)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        len_batches_after = len(
            reverted_node.master_replica._ordering_service.batches)
        """
        Checks, that we have a 2 new batches
        """
        assert len_batches_after - len_batches_before == NUM_BATCHES
        sdk_get_and_check_replies(looper, sdk_requests)
        reverted_node.start_catchup()
        looper.run(
            eventually(
                lambda: assertExp(reverted_node.mode == Mode.participating)))
    ensure_all_nodes_have_same_data(looper, node_set)

    r = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                    helpers.request._steward_wallet,
                                    req_for_check)
    sdk_get_and_check_replies(looper, [r])
    ensure_all_nodes_have_same_data(looper, node_set)
Exemplo n.º 18
0
def test_malicious_primary_sent_pp_with_xfer(looper, helpers,
                                   nodeSetWithIntegratedTokenPlugin,
                                   sdk_pool_handle,
                                   fees_set, address_main, xfer_mint_tokens,
                                   fees, xfer_addresses):
    def raise_invalid_ex():
        raise InvalidClientMessageException(1, 2, 3)

    nodes = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(xfer_mint_tokens)
    malicious_primary = getPrimaryReplica(nodes).node
    not_malicious_nodes = set(nodes) - {malicious_primary}
    seq_no = get_seq_no(xfer_mint_tokens)
    for n in not_malicious_nodes:
        n.master_replica._ordering_service._do_dynamic_validation = lambda *args, **kwargs: raise_invalid_ex()
    with pytest.raises(RequestRejectedException, match="client request invalid"):
        current_amount, seq_no, _ = send_and_check_transfer(helpers, xfer_addresses, fees, looper, current_amount, seq_no)
def test_multiple_batches_for_pool(looper, helpers,
                                   nodeSetWithIntegratedTokenPlugin,
                                   sdk_pool_handle, fees_set, address_main,
                                   mint_tokens):
    node_set = nodeSetWithIntegratedTokenPlugin
    node_stashers = [n.nodeIbStasher for n in node_set]

    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    request1, request2 = nyms_with_fees(2,
                                        helpers,
                                        fees_set,
                                        address_main,
                                        amount,
                                        init_seq_no=init_seq_no)

    txns_count_before = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    with delay_rules(node_stashers, cDelay()):
        r1 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                         helpers.request._steward_wallet,
                                         request1)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        r2 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                         helpers.request._steward_wallet,
                                         request2)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        for n in node_set:
            n.start_catchup()
        # clear all request queues to not re-send the same reqs after catch-up
        for n in node_set:
            n.requests.clear()
            for r in n.replicas.values():
                for ledger_id, queue in r._ordering_service.requestQueues.items(
                ):
                    queue.clear()
        for n in node_set:
            looper.run(
                eventually(lambda: assertExp(n.mode == Mode.participating)))
    txns_count_after = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    assert txns_count_after == txns_count_before
    ensure_all_nodes_have_same_data(looper, node_set)
Exemplo n.º 20
0
def test_fees_not_set_and_nym_with_fees(helpers,
                                        nodeSetWithIntegratedTokenPlugin,
                                        sdk_wallet_steward,
                                        address_main,
                                        sdk_pool_handle,
                                        sdk_wallet_trustee,
                                        mint_tokens,
                                        looper):
    """
    Steps:
    1. Checks that nym with zero fees is valid
    """
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1
    fees = {NYM_FEES_ALIAS: 0}
    current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, {FEES: fees}, seq_no, looper, [address_main],
                                                             current_amount)
    sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward)
    ensure_all_nodes_have_same_data(looper, nodeSetWithIntegratedTokenPlugin)
Exemplo n.º 21
0
def test_multiple_batches_for_one_node(looper, helpers,
                                       nodeSetWithIntegratedTokenPlugin,
                                       sdk_pool_handle, fees_set, address_main,
                                       mint_tokens):
    node_set = nodeSetWithIntegratedTokenPlugin
    affected_node = node_set[-1]

    amount = get_amount_from_token_txn(mint_tokens)
    init_seq_no = 1
    request1, request2, request3 = nyms_with_fees(3,
                                                  helpers,
                                                  fees_set,
                                                  address_main,
                                                  amount,
                                                  init_seq_no=init_seq_no)

    expected_txns_length = 2
    txns_count_before = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    with delay_rules(affected_node.nodeIbStasher, cDelay()):
        r1 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                         helpers.request._steward_wallet,
                                         request1)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        r2 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                         helpers.request._steward_wallet,
                                         request2)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        affected_node.start_catchup()
        looper.run(
            eventually(
                lambda: assertExp(affected_node.mode == Mode.participating)))
    txns_count_after = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    assert txns_count_after - txns_count_before == expected_txns_length
    ensure_all_nodes_have_same_data(looper, node_set)

    r3 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                     helpers.request._steward_wallet, request3)
    sdk_get_and_check_replies(looper, [r3])
    ensure_all_nodes_have_same_data(looper, node_set)
def test_validation_nym_with_zero_fees(helpers,
                                       nodeSetWithIntegratedTokenPlugin,
                                       sdk_wallet_steward, address_main,
                                       sdk_pool_handle, sdk_wallet_trustee,
                                       mint_tokens, looper):
    """
    Steps:
    1. Checks that nym with zero fees is valid
    2. Send auth_rule txn with zero fees in metadata
    3. Resend nym with fees and check, that it will be valid, because fees is 0, but fees are set in request
    """
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1
    fees = {NYM_FEES_ALIAS: 0}
    helpers.general.do_set_fees(fees, fill_auth_map=False)
    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, {FEES: fees}, seq_no, looper, [address_main], current_amount)
    sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward)

    original_action = add_new_identity_owner
    original_constraint = auth_map.get(add_new_identity_owner.get_action_id())
    original_constraint.set_metadata({'fees': NYM_FEES_ALIAS})
    sdk_send_and_check_auth_rule_request(
        looper,
        sdk_pool_handle,
        sdk_wallet_trustee,
        auth_action=ADD_PREFIX,
        auth_type=NYM,
        field=original_action.field,
        new_value=original_action.value,
        old_value=None,
        constraint=original_constraint.as_dict)
    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, {FEES: fees}, seq_no, looper, [address_main], current_amount)
    sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward)
    ensure_all_nodes_have_same_data(looper, nodeSetWithIntegratedTokenPlugin)
Exemplo n.º 23
0
def test_chain_set_fees_and_xfer_batch_size_2(looper, helpers,
                                              nodeSetWithIntegratedTokenPlugin,
                                              sdk_pool_handle,
                                              sdk_wallet_trustee, mint_tokens,
                                              addresses, poolConfigWTFF):
    """
    Set FEES for XFER for 2

    Send any transaction to config ledger.

    Send XFER with fees 2 from A to B

    Set FEES for XFER for 3

    Send any transaction to config ledger.

    Send XFER with fees 3 from A to B

    Check that first XFER is not written and second XFER is.
    """
    A, B = addresses
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = get_seq_no(mint_tokens)
    transfer_summ = 20

    # Set fees and some config txn
    helpers.node.set_fees_directly({XFER_PUBLIC_FEES_ALIAS: 42})
    fees_xfer_2 = {XFER_PUBLIC_FEES_ALIAS: 2}
    fees_2_rsp = helpers.general.set_fees_without_waiting(fees_xfer_2)
    sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_trustee,
                         poolConfigWTFF)
    sdk_get_and_check_replies(looper, fees_2_rsp)

    # XFER with fees 2 from A to B
    _, _, a_b_transfer_2 = send_and_check_transfer(helpers, [A, B],
                                                   fees_xfer_2,
                                                   looper,
                                                   current_amount,
                                                   seq_no,
                                                   transfer_summ=transfer_summ,
                                                   check_reply=False)
    # Set fees for XFER to 3
    fees_xfer_3 = {XFER_PUBLIC_FEES_ALIAS: 3}
    fees_3_rsp = helpers.general.set_fees_without_waiting(fees_xfer_3)
    sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_trustee,
                         poolConfigWTFF)
    sdk_get_and_check_replies(looper, fees_3_rsp)

    # Send XFER with fees from A to B
    a_amount, seq_no, a_b_transfer_3 = send_and_check_transfer(
        helpers, [A, B],
        fees_xfer_3,
        looper,
        current_amount,
        seq_no,
        transfer_summ=transfer_summ,
        check_reply=False)
    for n in nodeSetWithIntegratedTokenPlugin:
        fee_rq = n.ledger_to_req_handler[CONFIG_LEDGER_ID]
        assert fee_rq.fees == fees_xfer_3

    with pytest.raises(RequestRejectedException):
        sdk_get_and_check_replies(looper, a_b_transfer_2)
    sdk_get_and_check_replies(looper, a_b_transfer_3)
    a_get = helpers.general.do_get_utxo(A)
    assert a_get[OUTPUTS][1][AMOUNT] == a_amount
    assert a_get[OUTPUTS][1][SEQNO] == seq_no

    b_get = helpers.general.do_get_utxo(B)
    assert b_get[OUTPUTS][0][AMOUNT] == transfer_summ
    assert b_get[OUTPUTS][0][SEQNO] == seq_no

    ensure_all_nodes_have_same_data(looper, nodeSetWithIntegratedTokenPlugin)
def test_first_catchup_for_a_new_node(looper, helpers,
                                      nodeSetWithIntegratedTokenPlugin,
                                      sdk_pool_handle, sdk_wallet_trustee,
                                      fees_set, mint_tokens, addresses, fees,
                                      tconf, tdir, allPluginsPath,
                                      do_post_node_creation, testNodeClass):
    node_set = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1
    reverted_node = node_set[-1]
    idx = node_set.index(reverted_node)

    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, addresses, current_amount)

    reverted_node.cleanupOnStopping = False
    disconnect_node_and_ensure_disconnected(looper, node_set,
                                            reverted_node.name)
    looper.removeProdable(name=reverted_node.name)

    from_a_to_b = [addresses[0], addresses[1]]
    from_b_to_c = [addresses[1], addresses[2]]
    from_c_to_d = [addresses[2], addresses[3]]
    from_d_to_a = [addresses[3], addresses[0]]

    # current_amount, seq_no, _ = add_nym_with_fees(helpers, fees_set, seq_no, looper, addresses, current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(
        helpers,
        from_a_to_b,
        fees,
        looper,
        current_amount,
        seq_no,
        transfer_summ=current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(
        helpers,
        from_b_to_c,
        fees,
        looper,
        current_amount,
        seq_no,
        transfer_summ=current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(
        helpers,
        from_c_to_d,
        fees,
        looper,
        current_amount,
        seq_no,
        transfer_summ=current_amount)

    add_new_node(helpers,
                 looper,
                 node_set,
                 sdk_wallet_trustee,
                 current_amount,
                 seq_no,
                 fees_set,
                 sdk_pool_handle,
                 tdir,
                 tconf,
                 allPluginsPath,
                 addresses[3],
                 do_post_node_creation,
                 node_class=testNodeClass)

    current_amount, seq_no, _ = send_and_check_transfer(
        helpers,
        from_d_to_a,
        fees,
        looper,
        current_amount,
        seq_no,
        transfer_summ=current_amount)
    ensure_all_nodes_have_same_data(looper, node_set)
def test_state_recovery_with_xfer(looper, tconf, tdir,
                                  sdk_pool_handle,
                                  sdk_wallet_trustee,
                                  allPluginsPath,
                                  do_post_node_creation,
                                  nodeSetWithIntegratedTokenPlugin,
                                  helpers,
                                  valid_upgrade,
                                  mint_tokens,
                                  addresses,
                                  fees_set, fees,
                                  monkeypatch):
    version1 = "1.1.50"
    version2 = "1.1.88"
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1
    node_set = nodeSetWithIntegratedTokenPlugin

    current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers, fees_set, seq_no, looper, addresses,
                                                             current_amount)
    # send POOL_UPGRADE to write in a ledger
    last_ordered = node_set[0].master_last_ordered_3PC[1]
    sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee,
                            valid_upgrade)
    looper.run(eventually(lambda: assertEquality(node_set[0].master_last_ordered_3PC[1],
                                                 last_ordered + 1)))

    send_node_upgrades(node_set, version1, looper)
    for n in node_set:
        handler = n.write_manager.request_handlers.get(XFER_PUBLIC)[0]
        handler_for_1_0_0 = n.write_manager._request_handlers_with_version.get((XFER_PUBLIC, "1.0.0"))[0]
        monkeypatch.setattr(handler, 'update_state',
                            handler_for_1_0_0.update_state)

    current_amount, seq_no, _ = send_and_check_transfer(helpers, [addresses[0], addresses[1]], fees_set, looper,
                                                        current_amount, seq_no,
                                                        transfer_summ=current_amount)
    send_node_upgrades(node_set, version2, looper)
    monkeypatch.undo()
    current_amount, seq_no, _ = send_and_check_transfer(helpers, [addresses[1], addresses[0]], fees_set, looper,
                                                        current_amount, seq_no,
                                                        transfer_summ=current_amount)

    node_to_stop = node_set[-1]
    state_db_pathes = [state._kv.db_path
                       for state in node_to_stop.states.values()]
    node_to_stop.cleanupOnStopping = False
    node_to_stop.stop()
    looper.removeProdable(node_to_stop)
    ensure_node_disconnected(looper, node_to_stop, node_set[:-1])

    for path in state_db_pathes:
        shutil.rmtree(path)
    config_helper = NodeConfigHelper(node_to_stop.name, tconf, chroot=tdir)
    restarted_node = TestNode(
        node_to_stop.name,
        config_helper=config_helper,
        config=tconf,
        pluginPaths=allPluginsPath,
        ha=node_to_stop.nodestack.ha,
        cliha=node_to_stop.clientstack.ha)
    do_post_node_creation(restarted_node)

    looper.add(restarted_node)
    node_set[-1] = restarted_node

    looper.run(checkNodesConnected(node_set))
    waitNodeDataEquality(looper, restarted_node, *node_set[:-1], exclude_from_check=['check_last_ordered_3pc_backup'])
    current_amount, seq_no, _ = send_and_check_transfer(helpers, [addresses[0], addresses[1]], {}, looper,
                                                        current_amount, seq_no,
                                                        transfer_summ=1)
    waitNodeDataEquality(looper, restarted_node, *node_set[:-1], exclude_from_check=['check_last_ordered_3pc_backup'])
Exemplo n.º 26
0
def curr_amount(xfer_mint_tokens):
    return get_amount_from_token_txn(xfer_mint_tokens)
Exemplo n.º 27
0
def test_state_recover_from_ledger(looper, tconf, tdir, sdk_pool_handle,
                                   sdk_wallet_trustee, allPluginsPath,
                                   fees_set, mint_tokens, addresses, fees,
                                   do_post_node_creation,
                                   nodeSetWithIntegratedTokenPlugin, helpers):
    node_set = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1

    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, addresses, current_amount)
    current_amount, seq_no, _ = send_and_check_transfer(
        helpers, [addresses[0], addresses[1]],
        fees,
        looper,
        current_amount,
        seq_no,
        transfer_summ=current_amount)

    current_amount, seq_no, _ = send_and_check_transfer(
        helpers, [addresses[1], addresses[2]],
        fees,
        looper,
        current_amount,
        seq_no,
        transfer_summ=current_amount)

    ensure_all_nodes_have_same_data(looper, node_set)

    node_to_stop = node_set[-1]
    state_db_pathes = [
        state._kv.db_path for state in node_to_stop.states.values()
    ]
    node_to_stop.cleanupOnStopping = False
    node_to_stop.stop()
    looper.removeProdable(node_to_stop)
    ensure_node_disconnected(looper, node_to_stop, node_set[:-1])

    for path in state_db_pathes:
        shutil.rmtree(path)
    config_helper = NodeConfigHelper(node_to_stop.name, tconf, chroot=tdir)
    restarted_node = TestNode(node_to_stop.name,
                              config_helper=config_helper,
                              config=tconf,
                              pluginPaths=allPluginsPath,
                              ha=node_to_stop.nodestack.ha,
                              cliha=node_to_stop.clientstack.ha)
    do_post_node_creation(restarted_node)

    looper.add(restarted_node)
    node_set = node_set[:-1]

    looper.run(checkNodesConnected(node_set))
    waitNodeDataEquality(looper, restarted_node, *node_set[:-1])

    ensure_all_nodes_have_same_data(looper, node_set)

    current_amount, seq_no, _ = send_and_check_transfer(
        helpers, [addresses[2], addresses[0]],
        fees,
        looper,
        current_amount,
        seq_no,
        transfer_summ=current_amount)

    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, addresses, current_amount)
    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, addresses, current_amount)

    ensure_all_nodes_have_same_data(looper, node_set)
Exemplo n.º 28
0
def test_chain_fees_and_xfer_batch_size_2(looper, helpers,
                                          nodeSetWithIntegratedTokenPlugin,
                                          fees_set, mint_tokens, addresses,
                                          fees):
    """
    Set FEES for NYM transaction

    Send XFER from A to B

    Send NYM with fees from A using the UTXO as in 2

    Send XFER from B to C

    Send NYM with fees from C

    Check that XFERs are written

    Check that first NYM is not written and the second one is written.
    """
    a_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = get_seq_no(mint_tokens)
    initial_seq_no = seq_no
    A, B, C = addresses

    transfer_summ = 20
    # From A to B transfer
    a_amount, seq_no, a_b_transfer = send_and_check_transfer(
        helpers, [A, B],
        fees,
        looper,
        a_amount,
        seq_no,
        transfer_summ=transfer_summ,
        check_reply=False)
    # NYM with fees from A and utxo as for previous case
    _, _, a_nym = send_and_check_nym_with_fees(helpers,
                                               fees_set,
                                               initial_seq_no,
                                               looper, [A],
                                               a_amount + transfer_summ,
                                               check_reply=False)
    # From B to C transfer
    b_amount, seq_no, b_c_transfer = send_and_check_transfer(
        helpers, [B, C],
        fees,
        looper,
        transfer_summ,
        seq_no,
        transfer_summ=transfer_summ,
        check_reply=False)
    sdk_get_and_check_replies(looper, a_b_transfer)
    sdk_get_and_check_replies(looper, b_c_transfer)
    b_c_get = helpers.general.do_get_utxo(B)
    assert len(b_c_get[OUTPUTS]) == 0

    # NYM with fees from C
    c_nym_amount, seq_no, c_nym = send_and_check_nym_with_fees(
        helpers,
        fees_set,
        seq_no,
        looper, [C],
        transfer_summ,
        check_reply=False)
    with pytest.raises(RequestRejectedException,
                       match="are not found in list"):
        sdk_get_and_check_replies(looper, a_nym)
    a_b_get = helpers.general.do_get_utxo(A)
    assert a_b_get[OUTPUTS][1][AMOUNT] == a_amount

    sdk_get_and_check_replies(looper, c_nym)
    c_nym_get = helpers.general.do_get_utxo(C)
    assert c_nym_get[OUTPUTS][0][
        AMOUNT] == c_nym_amount == transfer_summ - fees.get(NYM_FEES_ALIAS, 0)

    ensure_all_nodes_have_same_data(looper, nodeSetWithIntegratedTokenPlugin)
def test_ordering_with_fees_and_without_fees(looper, helpers,
                                             nodeSetWithIntegratedTokenPlugin,
                                             sdk_pool_handle,
                                             sdk_wallet_steward, fees_set,
                                             address_main, mint_tokens, fees):
    node_set = nodeSetWithIntegratedTokenPlugin
    node_stashers = [n.nodeIbStasher for n in nodeSetWithIntegratedTokenPlugin]

    committed_tokens_before = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    committed_domain_before = get_committed_txns_count_for_pool(
        node_set, DOMAIN_LEDGER_ID)
    """
    We will try to send a 1 NYM txn with fees and 1 NYM without fees and 1 with fees
    In that case we expect, that we will have 3 domain txn and 2 token txn in ledgers
    """
    expected_domain_txns_count = 3
    expected_token_txns_count = 2
    with delay_rules(node_stashers, cDelay()):
        amount = get_amount_from_token_txn(mint_tokens)
        init_seq_no = 1
        request_1, request_2 = nyms_with_fees(2,
                                              helpers,
                                              fees_set,
                                              address_main,
                                              amount,
                                              init_seq_no=init_seq_no)
        """
        Sending 1 NYM txn with fees
        """
        r_with_1 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                               helpers.request._steward_wallet,
                                               request_1)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        """
        Unset fees for pool
        """
        r_unset_fees = helpers.general.set_fees_without_waiting(
            {k: 0
             for (k, v) in fees.items()})
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        """
        Sending 1 NYM txn without fees
        """
        r_without = sdk_send_new_nym(looper, sdk_pool_handle,
                                     sdk_wallet_steward)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        """
        Set fees for pool
        """
        r_set_fees = helpers.general.set_fees_without_waiting(fees)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
        """
        Send another NYM txn with fees
        """
        r_with_2 = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle,
                                               helpers.request._steward_wallet,
                                               request_2)
        looper.runFor(waits.expectedPrePrepareTime(len(node_set)))
    """
    Reset delays and check, that all txns was ordered successfully
    """
    sdk_get_and_check_replies(looper, [r_with_1])
    sdk_get_and_check_replies(looper, r_unset_fees)
    sdk_get_and_check_replies(looper, r_without)
    sdk_get_and_check_replies(looper, r_set_fees)
    sdk_get_and_check_replies(looper, [r_with_2])

    committed_tokens_after = get_committed_txns_count_for_pool(
        node_set, TOKEN_LEDGER_ID)
    committed_domain_after = get_committed_txns_count_for_pool(
        node_set, DOMAIN_LEDGER_ID)
    assert committed_domain_after - committed_domain_before == expected_domain_txns_count
    assert committed_tokens_after - committed_tokens_before == expected_token_txns_count

    ensure_all_nodes_have_same_data(looper, nodeSetWithIntegratedTokenPlugin)
Exemplo n.º 30
0
def test_demote_promote_restart_after_promotion(
        nodeSetWithIntegratedTokenPlugin, looper, sdk_pool_handle,
        sdk_wallet_trustee, tdir, tconf, allPluginsPath, mint_tokens,
        address_main, helpers, fees_set, addresses, fees,
        do_post_node_creation):
    pool = nodeSetWithIntegratedTokenPlugin
    current_amount = get_amount_from_token_txn(mint_tokens)
    seq_no = 1
    demoted_node = pool[-1]

    from_a_to_b = [addresses[0], addresses[1]]
    current_amount, seq_no, _ = send_and_check_transfer(
        helpers, from_a_to_b, fees, looper, current_amount, seq_no)

    rest_nodes = [n for n in pool if n != demoted_node]

    starting_view_no = checkViewNoForNodes(pool)

    # Step 1. Demote for node Zeta

    demote_node(helpers, sdk_wallet_trustee, demoted_node)

    # Step 2. Waiting for view change after nodes count changing
    waitForViewChange(looper, rest_nodes, expectedViewNo=starting_view_no + 1)
    ensureElectionsDone(looper, rest_nodes)
    ensure_all_nodes_have_same_data(
        looper, rest_nodes, exclude_from_check='check_seqno_db_equality')

    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, addresses, current_amount)

    current_amount, seq_no, _ = send_and_check_transfer(
        helpers, from_a_to_b, fees, looper, current_amount, seq_no)

    starting_view_no = checkViewNoForNodes(rest_nodes)

    # Step 3. Promote node back and waiting for view change

    promote_node(helpers, sdk_wallet_trustee, demoted_node)

    waitForViewChange(looper, rest_nodes, expectedViewNo=starting_view_no + 1)
    ensureElectionsDone(looper, rest_nodes)

    # Step 4. Restart promoted node only after Node txn ordering

    restart_node(demoted_node, pool, looper, tconf, tdir, allPluginsPath,
                 do_post_node_creation, fees)

    ensure_all_nodes_have_same_data(
        looper,
        pool,
        custom_timeout=60,
        exclude_from_check='check_seqno_db_equality')
    ensureElectionsDone(looper, pool)

    # Step 5. Make sure that pool works fine

    current_amount, seq_no, _ = send_and_check_transfer(
        helpers, from_a_to_b, fees, looper, current_amount, seq_no)
    current_amount, seq_no, _ = send_and_check_nym_with_fees(
        helpers, fees_set, seq_no, looper, addresses, current_amount)
    ensure_all_nodes_have_same_data(
        looper, pool, exclude_from_check='check_seqno_db_equality')