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)
Пример #2
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_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_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)
Пример #5
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)
Пример #6
0
def test_revert_set_fees_and_view_change_all_nodes(
        nodeSetWithIntegratedTokenPlugin, xfer_mint_tokens, helpers, looper,
        xfer_addresses):
    """
        Send SET_FEES and init view change. Check that it is reverted and transaction passes with old fees
    """
    def _get_len_preprepares(n):
        replica = n.master_replica
        return len(replica._ordering_service.sent_preprepares if replica.
                   isPrimary else replica._ordering_service.prePrepares)

    def _check_len_pprs(old_pprs_len):
        _len_pprs = set([
            _get_len_preprepares(n) for n in nodeSetWithIntegratedTokenPlugin
        ])
        _len_ppr = _len_pprs.pop()
        assert old_pprs_len + 1 == _len_ppr

    helpers.general.do_set_fees({NYM_FEES_ALIAS: 3})
    nodes = nodeSetWithIntegratedTokenPlugin
    node_stashers = [n.nodeIbStasher for n in nodeSetWithIntegratedTokenPlugin]
    seq_no = get_seq_no(xfer_mint_tokens)
    _old_len_pprs = set(
        [_get_len_preprepares(n) for n in nodeSetWithIntegratedTokenPlugin])
    assert len(_old_len_pprs)
    _old_len_ppr = _old_len_pprs.pop()

    with delay_rules_without_processing(node_stashers, cDelay()):
        helpers.general.set_fees_without_waiting({NYM_FEES_ALIAS: 5})
        looper.run(eventually(functools.partial(_check_len_pprs,
                                                _old_len_ppr)))
        send_and_check_nym_with_fees(helpers, {FEES: {
            NYM_FEES_ALIAS: 5
        }},
                                     seq_no,
                                     looper,
                                     xfer_addresses,
                                     1000,
                                     check_reply=False)
        for n in nodeSetWithIntegratedTokenPlugin:
            n.start_catchup()
        for n in nodes:
            looper.run(
                eventually(lambda: assertExp(n.mode == Mode.participating)))
    ensure_all_nodes_have_same_data(looper, nodes)
    send_and_check_nym_with_fees(helpers, {FEES: {
        NYM_FEES_ALIAS: 3
    }},
                                 seq_no,
                                 looper,
                                 xfer_addresses,
                                 1000,
                                 check_reply=False)
    ensure_all_nodes_have_same_data(looper, nodes)
def add_new_node(helpers, looper, node_set, sdk_wallet, current_amount, seq_no,
                 fees_set, sdk_pool_handle, tdir, tconf, allPluginsPath,
                 address, do_post_node_creation, node_class):
    new_did, verkey = helpers.wallet.create_did(sdk_wallet=sdk_wallet)
    req = helpers.request.nym(sdk_wallet=sdk_wallet,
                              alias="new_steward",
                              role=STEWARD_STRING,
                              dest=new_did,
                              verkey=verkey)
    utxos = [{ADDRESS: address, AMOUNT: current_amount, f.SEQ_NO.nm: seq_no}]
    req = add_fees_request_with_address(helpers,
                                        fees_set,
                                        req,
                                        address,
                                        utxos=utxos)
    current_amount, seq_no, _ = send_and_check_nym_with_fees(helpers,
                                                             fees_set,
                                                             seq_no,
                                                             looper,
                                                             addresses,
                                                             current_amount,
                                                             nym_with_fees=req)
    new_steward_wallet_handle = sdk_wallet[0], new_did
    new_node = sdk_add_new_node(looper,
                                sdk_pool_handle,
                                new_steward_wallet_handle,
                                'Epsilon',
                                tdir,
                                tconf,
                                allPluginsPath=allPluginsPath,
                                do_post_node_creation=do_post_node_creation,
                                nodeClass=node_class)
    node_set.append(new_node)
    looper.run(checkNodesConnected(node_set))
    waitNodeDataEquality(looper, new_node, *node_set[:-1])
Пример #8
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)
Пример #9
0
    def wrapped(addresses=None, check_reply=True, nym_with_fees=None):
        addresses = _addresses if addresses is None else addresses

        curr_utxo['amount'], curr_utxo[
            'seq_no'], resp = send_and_check_nym_with_fees(
                helpers,
                fees_set,
                curr_utxo['seq_no'],
                looper,
                addresses,
                curr_utxo['amount'],
                check_reply=check_reply,
                nym_with_fees=nym_with_fees)

        return curr_utxo, resp
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)
Пример #11
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)
Пример #12
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')
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'])
Пример #15
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_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)