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_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_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_vote_operation_2hf_invalid(wallet: Wallet, post, weight): apply_hardfork(wallet, 2) account = post["author"] validate_response(wallet.post_comment(**post), wallet.post_comment.__name__) validate_error_response(wallet.vote(account, account, post["permlink"], weight=weight), wallet.vote.__name__)
def test_vote_operation_valid(wallet: Wallet, post, weight): account = post["author"] validate_response(wallet.post_comment(**post), wallet.post_comment.__name__) validate_response(wallet.vote(account, account, post["permlink"], weight=weight), wallet.vote.__name__)