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_account_final_withdraw(wallet: Wallet, account, amount): response = wallet.withdraw(account, amount) validate_response(response, wallet.withdraw.__name__) account_before = wallet.get_account(account) constants = wallet.get_config() intervals = constants["SCORUM_VESTING_WITHDRAW_INTERVALS"] single_payment = amount / intervals interval_sec = constants["SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS"] for i in range(1, intervals + 1): time.sleep(interval_sec + 1) expected_withdraw = single_payment * i transfers = wallet.get_account_transfers(account) expect(len(transfers) == 1, "Was created more withdrawals then was expected.") withdrawn = Amount(transfers[0][1]["withdrawn"]) expect( withdrawn == expected_withdraw, "step: %d, actual '%s', expected '%s'" % (i, withdrawn, expected_withdraw) ) account_after = wallet.get_account(account) sp_change = Amount(account_before["scorumpower"]) - Amount(account_after["scorumpower"]) expect( sp_change == expected_withdraw, "step: %d, actual '%s', expected '%s'" % (i, sp_change, expected_withdraw) ) scr_change = Amount(account_after["balance"]) - Amount(account_before["balance"]) expect( scr_change == expected_withdraw, "step: %d, actual '%s', expected '%s'" % (i, scr_change, expected_withdraw) ) assert_expectations() if i == intervals: assert transfers[0][1]["status"] == "finished"
def test_get_account(wallet: Wallet): response = wallet.get_account(DEFAULT_WITNESS) validate_response(response, wallet.get_account.__name__, [ "active_sp_holders_cashout_time", "active_sp_holders_pending_scr_reward", "active_sp_holders_pending_sp_reward", "balance", "scorumpower", "name", "created", "last_root_post", "received_scorumpower", ("can_vote", bool), ("created_by_genesis", bool), "curation_rewards_sp", "curation_rewards_scr", ("voting_power", int), ("post_count", int), "posting_rewards_sp", "posting_rewards_scr", "delegated_scorumpower", "memo_key", "last_vote_time", "last_post" ]) assert response["name"] == DEFAULT_WITNESS, "Returned invalid account"
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
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