Example #1
0
def test_single_winner_pending_payments(wallet_3hf: Wallet, budget):
    change_auction_coeffs(wallet_3hf, [100], budget['type'])

    update_budget_time(wallet_3hf, budget, start=3, deadline=300)

    winner = copy(budget)
    winner.update({"owner": "test.test1", 'uuid': gen_uid()})
    potato = copy(budget)  # e.g. not winner (4th place: gold, silver, bronze, potato)
    potato.update({"owner": "test.test2", 'uuid': gen_uid()})
    looser = copy(budget)
    looser.update({"owner": "test.test3", 'uuid': gen_uid(), 'balance': "0.100000000 SCR"})

    budgets = [winner, potato, looser]

    wallet_3hf.broadcast_multiple_ops(
        "create_budget_operation", budgets, {winner['owner'], potato['owner'], looser['owner']}
    )

    [update_budget_balance(wallet_3hf, b) for b in budgets]

    assert winner['per_block'] == potato['per_block']
    assert looser['per_block'] != winner['per_block']
    assert Amount(winner[OUTGO]) == Amount(potato['per_block']) and Amount(winner[INCOME]) == Amount()
    assert Amount(potato[OUTGO]) == Amount() and Amount(potato[INCOME]) == Amount(potato['per_block'])
    assert Amount(looser[OUTGO]) == Amount() and Amount(looser[INCOME]) == Amount(looser['per_block'])
Example #2
0
def test_close_budget_by_adv_moderator_locked(wallet: Wallet, budget,
                                              moderator):
    response = wallet.close_budget_by_advertising_moderator(
        gen_uid(), moderator, budget["type"])
    validate_error_response(
        response, wallet.close_budget_by_advertising_moderator.__name__,
        RE_OP_IS_LOCKED)
Example #3
0
def test_create_post_vs_banner(wallet_3hf: Wallet, post_budget, banner_budget):
    new_budget = copy(post_budget)
    update_budget_time(wallet_3hf, post_budget)
    validate_response(wallet_3hf.create_budget(**post_budget), wallet_3hf.create_budget.__name__)

    update_budget_time(wallet_3hf, banner_budget)
    validate_response(wallet_3hf.create_budget(**banner_budget), wallet_3hf.create_budget.__name__)

    update_budget_balance(wallet_3hf, post_budget)  # update budget params / set budget id
    update_budget_balance(wallet_3hf, banner_budget)  # update budget params / set budget id
    assert post_budget["id"] == banner_budget["id"]  # both = 0
    assert len(wallet_3hf.get_budgets([post_budget['owner']], post_budget['type'])) == 1
    assert len(wallet_3hf.get_budgets([banner_budget['owner']], banner_budget['type'])) == 1

    budgets_summary = wallet_3hf.get_dynamic_global_properties()['advertising']
    assert all(
        Amount(budgets_summary[DGP_BUDGETS[b['type']]][k]) == Amount(b[v])
        for k, v in DGP_PARAMS_MAP.items()
        for b in [banner_budget, post_budget]
    )

    update_budget_time(wallet_3hf, new_budget)
    new_budget.update({'uuid': gen_uid()})
    validate_response(wallet_3hf.create_budget(**new_budget), wallet_3hf.create_budget.__name__)
    assert len(wallet_3hf.get_budgets([post_budget['owner']], post_budget['type'])) == 2
Example #4
0
def opened_budgets(wallet_3hf, budget):
    budgets = []
    for i in range(1, 4):
        budget_cp = copy(budget)
        update_budget_time(wallet_3hf, budget_cp, deadline=300)  # to leave all budgets opened
        budget_cp.update({"owner": "test.test%d" % i, 'uuid': gen_uid()})
        wallet_3hf.create_budget(**budget_cp)
        update_budget_balance(wallet_3hf, budget_cp)  # update budget params / set budget id
        budgets.append(budget_cp)
    return budgets
Example #5
0
def banner_budget():
    return {
        'type': "banner",
        'uuid': gen_uid(),
        'owner': 'test.test1',
        'json_metadata': "{}",
        'balance': "1.000000000 SCR",
        'start': "1970-01-01T00:00:00",
        'deadline': "1970-01-01T00:00:30"
    }
Example #6
0
def test_budget_creation_influence_on_pending(wallet_3hf: Wallet, budget, count):
    coeffs = wallet_3hf.get_auction_coefficients()
    budgets = []
    for i in range(1, count + 1):
        budgets_before = get_sorted_budgets(wallet_3hf, budgets)
        budget_cp = copy(budget)
        update_budget_time(wallet_3hf, budget_cp, start=1, deadline=300)
        budget_cp.update({
            "owner": "test.test%d" % i,
            'balance': str(Amount(budget['balance']) * i),
            'uuid': gen_uid()
        })
        wallet_3hf.create_budget(**budget_cp)
        budgets.append(budget_cp)
        budgets_after = get_sorted_budgets(wallet_3hf, budgets)
        check_budgets_delta_pending_calc(get_pending_delta(budgets_before, budgets_after), coeffs)
Example #7
0
def create_budgets(wallet, budget, count, sync_start=False):
    last_block = 0
    delay = 3 if sync_start else 0
    budgets = []
    for i in range(1, count + 1):
        start = delay * (count - i + 1) or 1
        budget_cp = copy(budget)
        update_budget_time(wallet, budget_cp, start=start,  deadline=start + 300 - delay)
        budget_cp.update({
            "owner": "test.test%d" % i,
            'balance': str(Amount(budget['balance']) * i),
            "uuid": gen_uid()
        })
        response = wallet.create_budget(**budget_cp)
        last_block = response['block_num']
        budgets.append(budget_cp)
    return budgets, last_block
Example #8
0
def test_create_max_budgets(wallet_3hf: Wallet, budget):
    re_budgets_limit = r"Can't create more then .* budgets per owner."
    limit = wallet_3hf.get_config()["SCORUM_BUDGETS_LIMIT_PER_OWNER"]
    balance = "0.000000001 SCR"
    update_budget_time(wallet_3hf, budget, start=5, deadline=300)
    budgets = []
    for i in range(1, limit + 1):
        budget_cp = copy(budget)
        budget_cp.update({'uuid': gen_uid(), 'balance': balance})
        budgets.append(budget_cp)
    validate_response(
        wallet_3hf.broadcast_multiple_ops('create_budget_operation', budgets, {budget['owner']}),
        'create_budget_operation'
    )
    update_budget_time(wallet_3hf, budget, start=5, deadline=300)
    validate_error_response(
        wallet_3hf.create_budget(**budget),
        wallet_3hf.create_budget.__name__,
        re_budgets_limit
    )
    wallet_3hf.close_budget(str(budgets[0]['uuid']), budget['owner'], budget['type'])
    update_budget_time(wallet_3hf, budget, start=5, deadline=300)
    validate_response(wallet_3hf.create_budget(**budget), wallet_3hf.create_budget.__name__)
def test_close_post_vs_banner(wallet_3hf: Wallet, moderator, post_budget,
                              banner_budget):
    new_budget = copy(post_budget)
    update_budget_time(wallet_3hf, post_budget)
    wallet_3hf.create_budget(**post_budget)
    update_budget_balance(wallet_3hf,
                          post_budget)  # update budget params / set budget id

    update_budget_time(wallet_3hf, banner_budget)
    wallet_3hf.create_budget(**banner_budget)
    update_budget_balance(
        wallet_3hf, banner_budget)  # update budget params / set budget id

    assert post_budget["id"] == banner_budget["id"]  # both = 0

    empower_advertising_moderator(wallet_3hf, moderator)
    response = wallet_3hf.close_budget_by_advertising_moderator(
        post_budget["uuid"], moderator, post_budget["type"])
    validate_response(
        response, wallet_3hf.close_budget_by_advertising_moderator.__name__)

    post_budgets = wallet_3hf.get_budgets([post_budget['owner']],
                                          post_budget['type'])
    assert len(post_budgets) == 0
    banner_budgets = wallet_3hf.get_budgets([banner_budget['owner']],
                                            banner_budget['type'])
    assert len(banner_budgets) == 1

    update_budget_time(wallet_3hf, new_budget)
    new_budget.update({'uuid': gen_uid()})
    validate_response(wallet_3hf.create_budget(**new_budget),
                      wallet_3hf.create_budget.__name__)
    update_budget_balance(wallet_3hf,
                          new_budget)  # update budget params / set budget id
    assert new_budget["id"] > banner_budget[
        "id"], "Newly created budget should have incremented index"
Example #10
0
def test_update_budget_locked(wallet: Wallet, budget):
    response = wallet.update_budget(gen_uid(), DEFAULT_WITNESS, "{}",
                                    budget["type"])
    validate_error_response(response, wallet.close_budget.__name__,
                            RE_OP_IS_LOCKED)