def test_close_after_starttime(wallet_3hf: Wallet, budget, moderator): update_budget_time(wallet_3hf, budget) budget_balance = Amount(budget["balance"]) balance_before = wallet_3hf.get_account_scr_balance(budget["owner"]) response = wallet_3hf.create_budget(**budget) create_block = response["block_num"] update_budget_balance(wallet_3hf, budget) # update budget params / set budget id per_block = Amount(budget["per_block"]) balance_after_create = wallet_3hf.get_account_scr_balance(budget["owner"]) assert balance_before - balance_after_create == budget_balance empower_advertising_moderator(wallet_3hf, moderator) response = wallet_3hf.close_budget_by_advertising_moderator( budget["uuid"], moderator, budget["type"]) validate_response( response, wallet_3hf.close_budget_by_advertising_moderator.__name__) close_block = response["block_num"] balance_after_close = wallet_3hf.get_account_scr_balance(budget["owner"]) assert balance_after_close == balance_after_create + budget_balance - per_block * ( close_block - create_block) check_virt_ops( wallet_3hf, close_block, close_block, { 'close_budget_by_advertising_moderator', 'budget_closing', 'budget_owner_income', 'budget_outgo' }) assert len(wallet_3hf.get_budgets([budget['owner']], budget['type'])) == 0 assert len(wallet_3hf.list_buddget_owners(budget_type=budget['type'])) == 0
def test_close_before_starttime(wallet_3hf: Wallet, budget, moderator): update_budget_time(wallet_3hf, budget, start=30, deadline=60) # to delay opening time for budget budget_balance = Amount(budget["balance"]) balance_before = wallet_3hf.get_account_scr_balance(budget["owner"]) wallet_3hf.create_budget(**budget) update_budget_balance(wallet_3hf, budget) # update budget params / set budget id balance_after_create = wallet_3hf.get_account_scr_balance(budget["owner"]) assert balance_before - balance_after_create == budget_balance empower_advertising_moderator(wallet_3hf, moderator) response = wallet_3hf.close_budget_by_advertising_moderator( budget["uuid"], moderator, budget["type"]) validate_response( response, wallet_3hf.close_budget_by_advertising_moderator.__name__) balance_after_close = wallet_3hf.get_account_scr_balance(budget["owner"]) assert balance_after_close == balance_after_create + budget_balance check_virt_ops( wallet_3hf, response['block_num'], response['block_num'], { 'close_budget_by_advertising_moderator', 'budget_closing', 'budget_owner_income' }) assert len(wallet_3hf.get_budgets([budget['owner']], budget['type'])) == 0 assert len(wallet_3hf.list_buddget_owners(budget_type=budget['type'])) == 0
def test_close_before_starttime(wallet_3hf: Wallet, budget): update_budget_time(wallet_3hf, budget, start=30, deadline=60) # to delay opening time for budget balance_before = wallet_3hf.get_account_scr_balance(budget["owner"]) wallet_3hf.create_budget(**budget) update_budget_balance(wallet_3hf, budget) # update budget params / set budget id response = wallet_3hf.close_budget(budget['uuid'], budget["owner"], budget["type"]) validate_response(response, wallet_3hf.close_budget.__name__) balance_after = wallet_3hf.get_account_scr_balance(budget["owner"]) assert balance_after == balance_before check_virt_ops( wallet_3hf, response['block_num'], response['block_num'], {'close_budget', 'budget_closing', 'budget_owner_income'} ) assert len(wallet_3hf.get_budgets([budget['owner']], budget['type'])) == 0 assert len(wallet_3hf.list_buddget_owners(budget_type=budget['type'])) == 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)
def test_close_after_starttime(wallet_3hf: Wallet, budget): update_budget_time(wallet_3hf, budget) balance_before = wallet_3hf.get_account_scr_balance(budget["owner"]) response = wallet_3hf.create_budget(**budget) create_block = response["block_num"] update_budget_balance(wallet_3hf, budget) # update budget params / set budget id per_block = Amount(budget["per_block"]) response = wallet_3hf.close_budget(budget['uuid'], budget["owner"], budget["type"]) validate_response(response, wallet_3hf.close_budget.__name__) close_block = response["block_num"] balance_after = wallet_3hf.get_account_scr_balance(budget["owner"]) assert balance_before == balance_after + per_block * (close_block - create_block) check_virt_ops( wallet_3hf, close_block, close_block, {'close_budget', 'budget_closing', 'budget_outgo', 'budget_owner_income'} ) assert len(wallet_3hf.get_budgets([budget['owner']], budget['type'])) == 0 assert len(wallet_3hf.list_buddget_owners(budget_type=budget['type'])) == 0
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())
def test_update_budget(wallet_3hf: Wallet, budget, json_metadata): update_budget_time(wallet_3hf, budget) wallet_3hf.create_budget(**budget) update_budget_balance(wallet_3hf, budget) response = wallet_3hf.update_budget(budget['uuid'], budget['owner'], json_metadata, budget['type']) validate_response(response, wallet_3hf.update_budget.__name__, [('block_num', int)]) check_virt_ops(wallet_3hf, response["block_num"], response["block_num"], {'update_budget'}) budget_obj = wallet_3hf.get_budget(budget['uuid'], budget['type']) assert budget_obj['json_metadata'] == json_metadata assert Amount(budget_obj['balance']) == Amount(budget['balance']) - Amount( budget['per_block']) assert Amount(budget_obj['budget_pending_outgo']) == Amount(budget['budget_pending_outgo']) + \ Amount(budget['per_block']) changed = {"json_metadata", 'balance', 'budget_pending_outgo'} assert all(budget[k] == budget_obj[k] for k in set(budget.keys()).difference(changed)), \ 'Not only budget metadata changed after update\n' \ 'before: {}\n' \ 'after: {}'.format(budget, budget_obj)
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