def apply_hardfork(wallet: Wallet, hf_id: int): assert hf_id > 0 for i in range(1, hf_id + 1): wallet.get_block(i + 1, wait_for_block=True) wallet.debug_set_hardfork(i) wallet.get_block(i + 2, wait_for_block=True) assert wallet.debug_has_hardfork(i)
def test_get_ops_history(wallet: Wallet, block_num): wallet.get_block(block_num, wait_for_block=True) response = wallet.get_ops_history(-1, 100, 0) # get all operations validate_response(response, wallet.get_ops_history.__name__) assert len( response ) == block_num, "Each block should be provided 'producer_reward' operation."
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)
def test_get_ops_history_pagination(wallet: Wallet, block_num): wallet.get_block(block_num, wait_for_block=True) response = wallet.get_ops_history(1, 1, 0) # get first operation validate_response(response, wallet.get_ops_history.__name__) assert len(response) == 1, "Should be returned single operation." assert response[0][ 0] == 0, "Should be returned first operation (with 'id' = 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']
def test_budget_impact_on_rewards(wallet: Wallet, genesis: Genesis): def get_reward_per_block(): last_confirmed_block = wallet.get_witness( DEFAULT_WITNESS)['last_confirmed_block_num'] sp_balance_before_block_confirm = wallet.get_account_sp_balance( DEFAULT_WITNESS) circulating_capital_before = wallet.get_circulating_capital() new_confirmed_block = last_confirmed_block while new_confirmed_block == last_confirmed_block: new_confirmed_block = wallet.get_witness( DEFAULT_WITNESS)['last_confirmed_block_num'] witness_reward = wallet.get_account_sp_balance( DEFAULT_WITNESS) - sp_balance_before_block_confirm full_content_reward = wallet.get_circulating_capital( ) - circulating_capital_before activity_content_reward = full_content_reward * 95 / 100 assert witness_reward == full_content_reward - activity_content_reward, 'witness reward per block != expected' return full_content_reward def calculate_rewards_from_genesis(): blocks_per_month = 864000 days_in_month = 30 days_in_2_years = 730 rewards_supply = Amount(genesis['rewards_supply']) rewards_per_block = rewards_supply * days_in_month / days_in_2_years / blocks_per_month return rewards_per_block ''' content reward before balancer decrease it ''' expected_content_reward_on_start = calculate_rewards_from_genesis() content_reward_on_start = get_reward_per_block() assert expected_content_reward_on_start == content_reward_on_start, 'content reward on start != expected' ''' wait for balancer decrease content reward ''' wallet.get_block(25, wait_for_block=True, time_to_wait=60) content_reward_after_balancer_decrease = get_reward_per_block() assert content_reward_after_balancer_decrease < content_reward_on_start, 'content reward not decreased by balancer' ''' open budget with large amount and short lifetime to instantly increase reward pool which enforce balancer to increase content reward ''' wallet.create_budget(DEFAULT_WITNESS, Amount("10000.000000000 SCR"), fmt_time_from_now(), fmt_time_from_now(30)) content_reward_after_budget_open = get_reward_per_block() assert content_reward_after_budget_open > content_reward_after_balancer_decrease, \ 'content reward not increased after budget open'
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
def test_get_discussions_by_created_same_block(wallet: Wallet, node: Node, alice_post, bob_post): posts = [alice_post, bob_post] wallet.get_block(2, wait_for_block=True) # ugly workaround to create posts within same block result = parallel_create_posts(posts, node) assert 'error' not in result[0], "creation alice_post failed" assert 'error' not in result[1], "creation bob_post failed" assert result[0]["block_num"] == result[1][ "block_num"], "posts are not created in single block" posts = wallet.get_discussions_by( "created", **{ "tags": ["hockey", "football"], "limit": 100, "tags_logical_and": False }) assert len(posts) == 2 # check that returned latest created post # as id increments after creation, so latest post should have higher id num assert posts[0]["id"] > posts[1][ "id"], "Posts were not created in correct order"
def test_deadline_close_budget(wallet_3hf: Wallet, budget, start, deadline, node, balance): acc_balance_before = wallet_3hf.get_account_scr_balance(budget['owner']) update_budget_time(wallet_3hf, budget, start=start, deadline=deadline + start) budget.update({"balance": balance}) response = wallet_3hf.create_budget(**budget) update_budget_balance(wallet_3hf, budget) per_blocks_cnt = get_per_blocks_count(start, deadline) per_block, reminder = calc_per_block(per_blocks_cnt, Amount(balance)) assert per_block == Amount(budget['per_block']) last_block = response['block_num'] blocks_wait = last_block + per_blocks_cnt wallet_3hf.get_block(blocks_wait + 1, wait_for_block=True) budgets = wallet_3hf.get_user_budgets(budget['owner']) assert 0 == len(budgets), "All budgets should be closed. %s" % fmt_time_from_now() virt_ops = {'budget_closing', 'budget_outgo'} if reminder.amount: virt_ops.add('budget_owner_income') check_virt_ops(wallet_3hf, blocks_wait - 1, blocks_wait + 1, virt_ops) acc_balance_after = wallet_3hf.get_account_scr_balance(budget['owner']) assert acc_balance_before - Amount(balance) + reminder == acc_balance_after
def test_get_block(wallet: Wallet): validate_response(wallet.get_block(1, wait_for_block=True), wallet.get_block.__name__)
def test_block_production(wallet: Wallet, node: Node): block = wallet.get_block(1, wait_for_block=True) assert block['witness'] == node.config['witness'][1:-1]