Beispiel #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)
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
def test_get_dynamic_global_properties(wallet: Wallet):
    response = wallet.get_dynamic_global_properties()
    validate_response(response, wallet.get_dynamic_global_properties.__name__, [
        ("head_block_number", int), "head_block_id", "current_witness", "total_supply",
        "circulating_capital", "total_scorumpower", "total_pending_scr", "total_pending_sp",
        "total_witness_reward_scr", "total_witness_reward_sp", "majority_version", ("current_aslot", int),
        "recent_slots_filled", ("participation_count", int), ("last_irreversible_block_num", int),
        "registration_pool_balance", "fund_budget_balance", "reward_pool_balance", "max_virtual_bandwidth",
        "content_reward_scr_balance", "content_reward_sp_balance", ("current_reserve_ratio", int)
    ])
def test_create_budgets(wallet_3hf: Wallet, node, opened_budgets_same_acc, budget):
    assert len(wallet_3hf.get_budgets([budget['owner']], budget['type'])) == len(opened_budgets_same_acc)

    budgets_summary = wallet_3hf.get_dynamic_global_properties()['advertising']

    for b in opened_budgets_same_acc:
        update_budget_balance(wallet_3hf, b)

    # check that sum of budgets 'param' ==  summary 'param' in DGP
    assert all(
        sum([Amount(b[v]) for b in opened_budgets_same_acc], Amount("0 SCR")) == Amount(
            budgets_summary[DGP_BUDGETS[budget['type']]][k]
        )
        for k, v in DGP_PARAMS_MAP.items()
    )
Beispiel #5
0
def test_active_sp_holder_reward_legacy(wallet: Wallet, post, accounts):
    op_name = "active_sp_holders_reward_legacy"

    validate_response(wallet.post_comment(**post), wallet.post_comment.__name__)
    for acc in accounts:
        validate_response(wallet.vote(acc, post["author"], post["permlink"]), wallet.vote.__name__)

    last_block = wallet.get_dynamic_global_properties()["head_block_number"]

    # e.g. next N blocks should be payed active_sp_holders_reward_legacy
    for i in range(last_block, last_block + 5):
        wallet.get_block(i, wait_for_block=True)
        ops = wallet.get_ops_in_block(i)
        rewards = [data["op"][1]["rewarded"] for _, data in ops if data["op"][0] == op_name][0]
        assert len(rewards) == len(accounts), "Was provided unexpected amount of '%s' operations." % op_name
        for acc, _ in rewards:
            assert acc in accounts, "Provided payment to unexpected account: '%s'" % acc
Beispiel #6
0
def test_genesis_block(wallet: Wallet, genesis: Genesis):
    info = wallet.get_dynamic_global_properties()

    records = [
        'accounts_supply', 'rewards_supply', 'registration_supply',
        'founders_supply', 'steemit_bounty_accounts_supply',
        'development_sp_supply', 'development_scr_supply'
    ]

    expected_total_supply = Amount()

    for r in records:
        expected_total_supply = expected_total_supply + Amount(genesis[r])

    assert Amount(info['total_supply']) == expected_total_supply

    for account, amount in genesis.genesis_accounts:
        assert wallet.get_account_scr_balance(account.name) == amount
def test_create_budget(wallet_3hf: Wallet, node, budget, start, deadline):
    update_budget_time(wallet_3hf, budget, start=start, deadline=deadline + start)
    budget_balance = Amount(budget["balance"])
    balance_before = wallet_3hf.get_account_scr_balance(budget["owner"])
    response = wallet_3hf.create_budget(**budget)
    validate_response(response, wallet_3hf.create_budget.__name__)
    check_virt_ops(wallet_3hf, response["block_num"], response["block_num"], {'create_budget'})
    balance_after = wallet_3hf.get_account_scr_balance(budget["owner"])
    assert balance_before == balance_after + budget_balance

    update_budget_balance(wallet_3hf, budget)
    assert budget_balance == Amount(budget['balance']) + Amount(budget['owner_pending_income']) + \
        Amount(budget['budget_pending_outgo'])

    per_block, _ = calc_per_block(get_per_blocks_count(start, deadline), budget_balance)
    assert per_block == Amount(budget['per_block'])

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