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_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_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_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_update_budget_invalid_meta(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_error_response(response, wallet_3hf.update_budget.__name__, RE_PARSE_ERROR) budget_obj = wallet_3hf.get_budget(budget['uuid'], budget['type']) assert budget_obj['json_metadata'] == budget["json_metadata"]
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_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() )
def test_single_winner_pending_payments(wallet_3hf: Wallet, budget): change_auction_coeffs(wallet_3hf, [100], budget['type']) update_budget_time(wallet_3hf, budget, start=3, deadline=300) winner = copy(budget) winner.update({"owner": "test.test1", 'uuid': gen_uid()}) potato = copy(budget) # e.g. not winner (4th place: gold, silver, bronze, potato) potato.update({"owner": "test.test2", 'uuid': gen_uid()}) looser = copy(budget) looser.update({"owner": "test.test3", 'uuid': gen_uid(), 'balance': "0.100000000 SCR"}) budgets = [winner, potato, looser] wallet_3hf.broadcast_multiple_ops( "create_budget_operation", budgets, {winner['owner'], potato['owner'], looser['owner']} ) [update_budget_balance(wallet_3hf, b) for b in budgets] assert winner['per_block'] == potato['per_block'] assert looser['per_block'] != winner['per_block'] assert Amount(winner[OUTGO]) == Amount(potato['per_block']) and Amount(winner[INCOME]) == Amount() assert Amount(potato[OUTGO]) == Amount() and Amount(potato[INCOME]) == Amount(potato['per_block']) assert Amount(looser[OUTGO]) == Amount() and Amount(looser[INCOME]) == Amount(looser['per_block'])
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
def test_close_post_vs_banner(wallet_3hf: Wallet, moderator, post_budget, banner_budget): new_budget = copy(post_budget) update_budget_time(wallet_3hf, post_budget) wallet_3hf.create_budget(**post_budget) update_budget_balance(wallet_3hf, post_budget) # update budget params / set budget id update_budget_time(wallet_3hf, banner_budget) wallet_3hf.create_budget(**banner_budget) update_budget_balance( wallet_3hf, banner_budget) # update budget params / set budget id assert post_budget["id"] == banner_budget["id"] # both = 0 empower_advertising_moderator(wallet_3hf, moderator) response = wallet_3hf.close_budget_by_advertising_moderator( post_budget["uuid"], moderator, post_budget["type"]) validate_response( response, wallet_3hf.close_budget_by_advertising_moderator.__name__) post_budgets = wallet_3hf.get_budgets([post_budget['owner']], post_budget['type']) assert len(post_budgets) == 0 banner_budgets = wallet_3hf.get_budgets([banner_budget['owner']], banner_budget['type']) assert len(banner_budgets) == 1 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__) update_budget_balance(wallet_3hf, new_budget) # update budget params / set budget id assert new_budget["id"] > banner_budget[ "id"], "Newly created budget should have incremented index"
def test_close_post_vs_banner(wallet_3hf: Wallet, post_budget, banner_budget): new_budget = copy(post_budget) update_budget_time(wallet_3hf, post_budget) wallet_3hf.create_budget(**post_budget) update_budget_balance(wallet_3hf, post_budget) # update budget params / set budget id update_budget_time(wallet_3hf, banner_budget) wallet_3hf.create_budget(**banner_budget) update_budget_balance(wallet_3hf, banner_budget) # update budget params / set budget id assert post_budget["id"] == banner_budget["id"] # both = 0 response = wallet_3hf.close_budget(post_budget['uuid'], post_budget["owner"], post_budget["type"]) validate_response(response, wallet_3hf.close_budget.__name__) post_budgets = wallet_3hf.get_budgets([post_budget['owner']], post_budget['type']) assert len(post_budgets) == 0 banner_budgets = wallet_3hf.get_budgets([banner_budget['owner']], banner_budget['type']) assert len(banner_budgets) == 1 update_budget_time(wallet_3hf, new_budget) validate_response(wallet_3hf.create_budget(**new_budget), wallet_3hf.create_budget.__name__) update_budget_balance(wallet_3hf, new_budget) # update budget params / set budget id assert new_budget["id"] > banner_budget["id"], "Newly created budget should have incremented index"