예제 #1
0
def test_active_sp_holder_reward_single_acc_2hf(wallet: Wallet, not_witness_post):
    post = not_witness_post
    account = post["author"]

    def check_reward_operation(start, stop):
        rewards = []
        for i in range(start, stop):
            wallet.get_block(i, wait_for_block=True)
            ops = wallet.get_ops_in_block(i)
            rewards = [data["op"][1] for _, data in ops if data["op"][0].startswith("active")]
            if rewards:
                break
        # Next assert also checks if legacy reward is not provided anymore
        assert len(rewards) == 1, "Should be provided single active_sp_holder_reward payment."
        assert rewards[0]["sp_holder"] == account, "Reward should be payed to specified user."
        return Amount(rewards[0]["reward"])

    apply_hardfork(wallet, 2)

    validate_response(wallet.post_comment(**post), wallet.post_comment.__name__)
    validate_response(wallet.vote(account, account, post["permlink"], 10000), wallet.vote.__name__)

    account_before = wallet.get_account(account)
    dgp_before = wallet.get_dynamic_global_properties()
    assert account_before["active_sp_holders_pending_sp_reward"] == dgp_before["total_pending_sp"]

    # 60 sec for testnet, one week for mainnet
    reward_period_sec = int(wallet.get_config()["SCORUM_ACTIVE_SP_HOLDERS_REWARD_PERIOD"] / 1000000)  # microesc -> sec
    expected_cashout = to_date(account_before["last_vote_time"], tmdelta={"seconds": reward_period_sec})
    actual_cashout = to_date(account_before["active_sp_holders_cashout_time"])
    assert actual_cashout == expected_cashout, \
        "Actual cashout time calculated incorrectly: '%s', expected '%s'" % \
        (date_to_str(actual_cashout), date_to_str(expected_cashout))

    blocks_to_wait = int(reward_period_sec / 3) + 1
    last_block = dgp_before["head_block_number"]
    reward = check_reward_operation(last_block, last_block + blocks_to_wait)

    account_after = wallet.get_account(account)
    assert account_before["balance"] == account_after["balance"]  # until advertising is locked
    assert account_before["scorumpower"] != account_after["scorumpower"]

    reset_cashout = to_date(account_after["active_sp_holders_cashout_time"])
    expected_cashout = to_date(account_before["active_sp_holders_cashout_time"], tmdelta={"seconds": reward_period_sec})
    assert reset_cashout == expected_cashout, \
        "Cashout time for active_sp_holder_reward was not reset: '%s', expected '%s'" % \
        (date_to_str(reset_cashout), date_to_str(expected_cashout))

    dgp_after = wallet.get_dynamic_global_properties()
    assert dgp_before["total_pending_scr"] == dgp_after["total_pending_scr"]  # until advertising is locked
    assert Amount(dgp_after["total_pending_sp"]) == Amount("0 SP")
    assert dgp_before["total_pending_sp"] != dgp_after["total_pending_sp"]
    assert dgp_before["total_scorumpower"] != dgp_after["total_scorumpower"]

    balance_change = Amount(account_after["scorumpower"]) - Amount(account_before["scorumpower"])
    assert balance_change == reward, \
        "Balance change is not equal with reward: '%s', expected '%s'" % (balance_change, reward)

    last_block = dgp_after["head_block_number"]
    check_reward_operation(last_block + 1, last_block + blocks_to_wait)
예제 #2
0
def test_cashout_scr_rewards(wallet_3hf: Wallet, budget, post):
    balancer_delay = 7  # blocks to wait until SCR will be in each required pool
    cfg = wallet_3hf.get_config()
    # Advertising cashout_blocks count
    adv_cash_blocks = int(cfg["SCORUM_ADVERTISING_CASHOUT_PERIOD_SEC"] / cfg["SCORUM_BLOCK_INTERVAL"])
    # Post / comment cashout blocks count
    # post_cash_blocks = int(cfg["SCORUM_CASHOUT_WINDOW_SECONDS"] / cfg["SCORUM_BLOCK_INTERVAL"])
    # Active SP holders cashout blocks count
    asph_cash_blocks = int(cfg["SCORUM_ACTIVE_SP_HOLDERS_REWARD_PERIOD"] / 1000000 / cfg["SCORUM_BLOCK_INTERVAL"]) - 1

    update_budget_time(wallet_3hf, budget, deadline=300)
    response = wallet_3hf.create_budget(**budget)
    budget_cashout_block = response['block_num'] + adv_cash_blocks + balancer_delay

    wallet_3hf.get_block(response['block_num'] + balancer_delay, wait_for_block=True)

    wallet_3hf.post_comment(**post)
    # post_cashout_block = response['block_num'] + post_cash_blocks

    response = wallet_3hf.vote(DEFAULT_WITNESS, post['author'], post['permlink'])
    active_sph_cashout_block = response['block_num'] + asph_cash_blocks

    blocks_ops = [
        (budget_cashout_block, 'producer_reward'),
        (active_sph_cashout_block, 'active_sp_holders_reward'),
        # (post_cashout_block, 'author_reward'),
        # (post_cashout_block, 'curator_reward')
    ]
    for cashout_block, op in blocks_ops:
        wallet_3hf.get_block(cashout_block, wait_for_block=True)
        ops = check_virt_ops(wallet_3hf, cashout_block, cashout_block, {op})
        assert any(Amount(data['reward']) > 0 and 'SCR' in data['reward'] for name, data in ops if name == op)
예제 #3
0
def test_cashout_budgets_distribution(wallet_3hf: Wallet, budget, count, sync_start):
    budgets, last_block = create_budgets(wallet_3hf, budget, count, sync_start)
    owners = [b['owner'] for b in budgets]
    cfg = wallet_3hf.get_config()
    cashout_blocks_cnt = int(cfg["SCORUM_ADVERTISING_CASHOUT_PERIOD_SEC"] / cfg["SCORUM_BLOCK_INTERVAL"])
    # collect data before cashout
    capital_before, accounts_balances_before = get_affected_balances(wallet_3hf, owners)
    [update_budget_balance(wallet_3hf, b) for b in budgets]
    #  wait until cashout
    wallet_3hf.get_block(last_block + cashout_blocks_cnt, wait_for_block=True)
    # collect data after cashout
    capital_after, accounts_balances_after = get_affected_balances(wallet_3hf, owners)
    [update_budget_balance(wallet_3hf, b) for b in budgets]
    # calc delta between 'after', 'before' cashout states
    capital_delta = get_capital_delta(capital_before, capital_after)
    accounts_balances_delta = get_accounts_delta(accounts_balances_after, accounts_balances_before)
    # calc total payments
    total = get_total_sums(budgets, accounts_balances_delta, cashout_blocks_cnt)
    # provide checks
    assert capital_delta['dev_pool_scr_balance'] == total['to_dev_pool']
    assert capital_delta['content_balancer_scr'] + \
        capital_delta['content_reward_fund_scr_balance'] == total['to_activity_pool']
    assert capital_delta['dev_pool_scr_balance'] + \
        capital_delta['content_balancer_scr'] + \
        capital_delta['content_reward_fund_scr_balance'] == total['spend']
예제 #4
0
def test_get_config(wallet: Wallet):
    response = wallet.get_config()
    validate_response(response, wallet.get_config.__name__, [
        ("SCORUM_HARDFORK_REQUIRED_WITNESSES", 17), ("SCORUM_MAX_VOTED_WITNESSES", 20),
        ("SCORUM_MAX_WITNESSES", 21),  # ("SCORUM_ACTIVE_SP_HOLDERS_REWARD_PERIOD", int), due to BLOC-484
        ("SCORUM_ACTIVE_SP_HOLDERS_PER_BLOCK_REWARD_PERCENT", int),
        ("SCORUM_VESTING_WITHDRAW_INTERVALS", 52), ("SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS", int)
    ])
예제 #5
0
def test_validate_get_content(
        wallet: Wallet, post_with_multilvl_comments, initdelegate_post, bob_comment_lv1, alice_comment_lv2
):
    for post in post_with_multilvl_comments:
        validate_response(wallet.post_comment(**post), wallet.post_comment.__name__)

    time_config = wallet.get_config()

    def validate_cashout_interval(comment: dict):
        date_start = to_date(comment['created'])
        date_finish = to_date(comment['cashout_time'])
        delta = date_finish - date_start
        cashout_window = int(time_config["SCORUM_CASHOUT_WINDOW_SECONDS"])
        assert delta.total_seconds() == cashout_window

    def validate_url(comment: dict):
        if comment['parent_author']:
            assert comment['url'] == '/{category}/@{root_author}/{root_permlink}#@{author}/{permlink}' \
                .format(category=comment['category'],
                        root_author=post['author'],
                        root_permlink=post['permlink'],
                        author=comment['author'],
                        permlink=comment['permlink'])
        else:
            assert comment['url'] == '/{}/@{}/{}'.format(comment['category'], comment['author'], comment['permlink'])

    def validate_content(comment, comment_kwargs, parent=None):
        for key, value in comment_kwargs.items():
            assert comment[key] == value, '{} value differs from expected'.format(key)
        assert comment['category'] == initdelegate_post['parent_permlink']
        expected_depth = parent['depth'] + 1 if parent else 0
        assert comment['depth'] == expected_depth
        assert comment['root_title'] == initdelegate_post['title']
        assert comment['root_comment'] == post['id']
        validate_cashout_interval(comment)
        validate_url(comment)

    post = wallet.get_content(initdelegate_post['author'], initdelegate_post['permlink'])
    validate_content(post, initdelegate_post)

    comment_level_1 = wallet.get_content(bob_comment_lv1['author'], bob_comment_lv1['permlink'])
    validate_content(comment_level_1, bob_comment_lv1, post)

    comment_level_2 = wallet.get_content(alice_comment_lv2['author'], alice_comment_lv2['permlink'])
    validate_content(comment_level_2, alice_comment_lv2, comment_level_1)
예제 #6
0
def test_account_final_withdraw(wallet: Wallet, account, amount):
    response = wallet.withdraw(account, amount)
    validate_response(response, wallet.withdraw.__name__)

    account_before = wallet.get_account(account)

    constants = wallet.get_config()
    intervals = constants["SCORUM_VESTING_WITHDRAW_INTERVALS"]

    single_payment = amount / intervals

    interval_sec = constants["SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS"]

    for i in range(1, intervals + 1):
        time.sleep(interval_sec + 1)

        expected_withdraw = single_payment * i

        transfers = wallet.get_account_transfers(account)
        expect(len(transfers) == 1, "Was created more withdrawals then was expected.")

        withdrawn = Amount(transfers[0][1]["withdrawn"])
        expect(
            withdrawn == expected_withdraw,
            "step: %d, actual '%s', expected '%s'" % (i, withdrawn, expected_withdraw)
        )

        account_after = wallet.get_account(account)
        sp_change = Amount(account_before["scorumpower"]) - Amount(account_after["scorumpower"])
        expect(
            sp_change == expected_withdraw,
            "step: %d, actual '%s', expected '%s'" % (i, sp_change, expected_withdraw)
        )

        scr_change = Amount(account_after["balance"]) - Amount(account_before["balance"])
        expect(
            scr_change == expected_withdraw,
            "step: %d, actual '%s', expected '%s'" % (i, scr_change, expected_withdraw)
        )

        assert_expectations()

        if i == intervals:
            assert transfers[0][1]["status"] == "finished"
예제 #7
0
def test_get_config(wallet: Wallet):
    response = wallet.get_config()
    validate_response(
        response,
        wallet.get_config.__name__,
        [
            ("SCORUM_HARDFORK_REQUIRED_WITNESSES", 17),
            ("SCORUM_MAX_VOTED_WITNESSES", 20),
            (
                "SCORUM_MAX_WITNESSES", 21
            ),  # ("SCORUM_ACTIVE_SP_HOLDERS_REWARD_PERIOD", int), due to BLOC-484
            ("SCORUM_ACTIVE_SP_HOLDERS_PER_BLOCK_REWARD_PERCENT", int),
            ("SCORUM_VESTING_WITHDRAW_INTERVALS", 52),
            ("SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS", int),
            ("SCORUM_LOW_MEMORY_NODE", bool),
            ("SCORUM_CLEAR_VOTES", bool),
            ("SCORUM_SKIP_BY_TX_ID", bool),
            ("SCORUM_LIVE_TESTNET", bool),
            ("SCORUM_ADVERTISING_CASHOUT_PERIOD_SEC", int),
            ("SCORUM_BUDGETS_LIMIT_PER_OWNER", 100)
        ])
예제 #8
0
def test_get_discussions_by_author_order(wallet: Wallet, initdelegate_post):
    permlinks = ["initdelegate-post-%d" % i for i in range(1, 5)]

    post_creation_interval = int(
        int(wallet.get_config()["SCORUM_MIN_ROOT_COMMENT_INTERVAL"]) / 1000000)
    for permlink in permlinks:
        initdelegate_post["permlink"] = permlink
        res = wallet.post_comment(**initdelegate_post)
        validate_response(res, wallet.post_comment.__name__)
        if permlink != permlinks[-1]:
            time.sleep(post_creation_interval)  # 5 min for each post on prod

    discussions = wallet.get_discussions_by(
        "author", **{
            "start_author": DEFAULT_WITNESS,
            "limit": len(permlinks)
        })
    validate_response(discussions, "get_discussions_by_author")
    total_posts = len(permlinks)
    for current in range(0, total_posts):
        opposite = total_posts - current - 1
        assert permlinks[current] == discussions[opposite]["permlink"], \
            "Broken posts order, Post %d should be on %d position." % (current, opposite)
예제 #9
0
def test_get_paid_posts_comments_by_author(wallet: Wallet, initdelegate_post):
    # REQUIREMENTS: return an array of posts and comments belonging to the given author that have reached cashout time.
    # This method should allow for pagination. The query should include field that will filter posts/comments that
    # have 0 SP rewards. The posts/comments should be sorted by last_payout field in the descending order.
    permlinks = ["initdelegate-post-%d" % i for i in range(1, 2)]

    post_creation_interval = int(
        int(wallet.get_config()["SCORUM_MIN_ROOT_COMMENT_INTERVAL"]) / 1000000)

    for permlink in permlinks:
        initdelegate_post["permlink"] = permlink
        res = wallet.post_comment(**initdelegate_post)
        validate_response(res, wallet.post_comment.__name__)
        # print(wallet.get_content(DEFAULT_WITNESS, permlink))
        if permlink != permlinks[-1]:
            time.sleep(post_creation_interval)  # 5 min for each post on prod

    posts = wallet.get_paid_posts_comments_by_author(**{
        "start_author": DEFAULT_WITNESS,
        "limit": len(permlinks)
    })

    assert len(posts) == len(permlinks)
예제 #10
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__)