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
Exemplo n.º 3
0
def test_transfer(wallet: Wallet):
    initdelegate_balance_before = wallet.get_account_scr_balance('initdelegate')
    amount = initdelegate_balance_before - Amount('5.000000000 SCR')
    alice_balance_before = wallet.get_account_scr_balance('alice')

    print(wallet.transfer('initdelegate', 'alice', amount))

    initdelegate_balance_after = wallet.get_account_scr_balance('initdelegate')
    alice_balance_after = wallet.get_account_scr_balance('alice')

    assert initdelegate_balance_after == initdelegate_balance_before - amount
    assert alice_balance_after == alice_balance_before + amount
Exemplo n.º 4
0
def test_transfer_to_vesting(wallet: Wallet):
    initdelegate_scr_balance_before = wallet.get_account_scr_balance('initdelegate')
    alice_sp_balance_before = wallet.get_account_sp_balance('alice')

    amount = Amount('1.000000000 SCR')

    wallet.transfer_to_scorumpower('initdelegate', 'alice', amount)

    initdelegate_scr_balance_after = wallet.get_account_scr_balance('initdelegate')
    alice_sp_balance_after = wallet.get_account_sp_balance('alice')

    assert initdelegate_scr_balance_after == initdelegate_scr_balance_before - amount
    assert alice_sp_balance_after == alice_sp_balance_before + amount
Exemplo n.º 5
0
def test_transfer_invalid_amount(wallet: Wallet):
    initdelegate_balance_before = wallet.get_account_scr_balance('initdelegate')
    amount = initdelegate_balance_before + Amount('0.000000001 SCR')
    alice_balance_before = wallet.get_account_scr_balance('alice')

    response = wallet.transfer('initdelegate', 'alice', amount)

    initdelegate_balance_after = wallet.get_account_scr_balance('initdelegate')
    alice_balance_after = wallet.get_account_scr_balance('alice')

    assert initdelegate_balance_after == initdelegate_balance_before
    assert alice_balance_after == alice_balance_before

    assert 'Account does not have sufficient funds for transfer' in response['error']['message']
Exemplo n.º 6
0
def test_create_account_by_committee(wallet: Wallet, genesis: Genesis,
                                     valid_name):
    accounts_before = wallet.list_accounts()
    creator_balance_before = wallet.get_account_scr_balance(DEFAULT_WITNESS)
    print(
        wallet.create_account_by_committee(
            DEFAULT_WITNESS,
            newname=valid_name,
            owner=test_account_owner_pub_key,
            active=test_account_active_pub_key,
            posting=test_accout_posting_pub_key,
            memo=test_account_memo_key,
        ))
    assert creator_balance_before == wallet.get_account_scr_balance(
        DEFAULT_WITNESS)

    assert wallet.get_account(
        valid_name)['recovery_account'] == DEFAULT_WITNESS

    accounts_after = wallet.list_accounts()
    assert len(accounts_after) == len(accounts_before) + 1
    assert valid_name in accounts_after

    account_by_active_key = wallet.get_account_by_key(
        test_account_active_pub_key)[0][0]
    assert account_by_active_key == valid_name

    account_by_posting_key = wallet.get_account_by_key(
        test_accout_posting_pub_key)[0][0]
    assert account_by_posting_key == valid_name

    account_by_owner_key = wallet.get_account_by_key(
        test_account_owner_pub_key)[0][0]
    assert account_by_owner_key == valid_name

    account_by_memo_key = wallet.get_account_by_key(test_account_memo_key)[0]
    assert account_by_memo_key == []

    new_account_sp_balance_amount = str(
        wallet.get_account_sp_balance(valid_name)).split()[0]
    registration_bonus_amount = genesis['registration_bonus'].split()[0]
    assert new_account_sp_balance_amount == registration_bonus_amount

    # TODO add assert to check registration_supply delta

    keys_auths = wallet.get_account_keys_auths(valid_name)
    assert keys_auths['owner'] == test_account_owner_pub_key
    assert keys_auths['active'] == test_account_active_pub_key
    assert keys_auths['posting'] == test_accout_posting_pub_key
    assert keys_auths['memo'] == test_account_memo_key
Exemplo n.º 7
0
def test_create_account(wallet: Wallet, valid_name):
    fee = Amount('0.000001000 SCR')
    account_before = wallet.list_accounts()

    creator_balance_before = wallet.get_account_scr_balance(DEFAULT_WITNESS)
    print(
        wallet.create_account(DEFAULT_WITNESS,
                              newname=valid_name,
                              owner=test_account_owner_pub_key,
                              active=test_account_active_pub_key,
                              posting=test_accout_posting_pub_key,
                              memo=test_account_memo_key,
                              fee=fee))
    creator_balance_delta = creator_balance_before - wallet.get_account_scr_balance(
        DEFAULT_WITNESS)
    assert creator_balance_delta == fee

    assert wallet.get_account(
        valid_name)['recovery_account'] == DEFAULT_WITNESS

    accounts_after = wallet.list_accounts()
    assert len(accounts_after) == len(account_before) + 1
    assert valid_name in accounts_after

    account_by_active_key = wallet.get_account_by_key(
        test_account_active_pub_key)[0][0]
    assert account_by_active_key == valid_name

    account_by_posting_key = wallet.get_account_by_key(
        test_accout_posting_pub_key)[0][0]
    assert account_by_posting_key == valid_name

    account_by_owner_key = wallet.get_account_by_key(
        test_account_owner_pub_key)[0][0]
    assert account_by_owner_key == valid_name

    account_by_memo_key = wallet.get_account_by_key(test_account_memo_key)[0]
    assert account_by_memo_key == []

    new_account_sp_balance_amount = str(
        wallet.get_account_sp_balance(valid_name)).split()[0]
    fee_amount = str(fee).split()[0]
    assert new_account_sp_balance_amount == fee_amount

    keys_auths = wallet.get_account_keys_auths(valid_name)
    assert keys_auths['owner'] == test_account_owner_pub_key
    assert keys_auths['active'] == test_account_active_pub_key
    assert keys_auths['posting'] == test_accout_posting_pub_key
    assert keys_auths['memo'] == test_account_memo_key
Exemplo n.º 8
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
Exemplo n.º 9
0
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
Exemplo n.º 10
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())
Exemplo n.º 11
0
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
Exemplo n.º 12
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