-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for CreateClaimedAccountOperation
- Loading branch information
Showing
2 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
tests/python/functional/operation_tests/claim_account_tests/test_create_claimed_account.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"""https://gitlab.syncad.com/hive/hive/-/issues/694""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
import test_tools as tt | ||
from hive_local_tools.functional.python.operation import assert_account_was_created | ||
from hive_local_tools.functional.python.operation.claim_account import ( | ||
ClaimAccountToken, | ||
CreateClaimedAccount, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from hive_local_tools.functional.python.operation import Account | ||
|
||
|
||
@pytest.fixture() | ||
def create_new_account_token_for_alice(node: tt.InitNode, wallet_alice: tt.Wallet, alice: Account) -> ClaimAccountToken: | ||
"""User has enough Hive to claim a new account token.""" | ||
alice.top_up(tt.Asset.Test(3)) | ||
|
||
create_token = ClaimAccountToken(node, wallet_alice, alice.name, tt.Asset.Test(3)) | ||
|
||
assert alice.get_pending_claimed_accounts() == 1, "Claim token was not created." | ||
|
||
return create_token | ||
|
||
|
||
@pytest.mark.parametrize("fee", [tt.Asset.Test(3)], indirect=["fee"]) | ||
def test_create_claimed_account_operation( | ||
node: tt.InitNode, | ||
initminer_wallet: tt.Wallet, | ||
wallet_alice: tt.Wallet, | ||
alice: Account, | ||
create_new_account_token_for_alice: ClaimAccountToken, | ||
fee: tt.Asset.TestT, | ||
) -> None: | ||
initminer_wallet.api.delegate_rc("initminer", [alice.name], 200000000000) | ||
|
||
alice.update_account_info() | ||
|
||
create_claimed_account = CreateClaimedAccount(node, wallet_alice, alice.name, "bob") | ||
|
||
assert alice.get_pending_claimed_accounts() == 0, "Claim token was not used." | ||
alice.check_if_current_rc_mana_was_reduced(create_claimed_account.trx) | ||
assert wallet_alice.api.get_account("bob"), "Account named bob does not exist" | ||
assert_account_was_created(node, "bob") | ||
|
||
|
||
@pytest.mark.parametrize("fee", [tt.Asset.Test(3)], indirect=["fee"]) | ||
def test_try_to_create_claimed_account_operation_without_available_token( | ||
node: tt.InitNode, wallet_alice: tt.Wallet, alice: Account, fee: tt.Asset.TestT | ||
) -> None: | ||
with pytest.raises(tt.exceptions.CommunicationError) as exception: | ||
CreateClaimedAccount(node, wallet_alice, alice.name, "bob") | ||
|
||
assert "alice has no claimed accounts to create" in exception.value.error | ||
|
||
|
||
@pytest.mark.parametrize("fee", [tt.Asset.Test(3)], indirect=["fee"]) | ||
def test_try_to_create_claimed_account_operation_with_already_existing_account( | ||
node: tt.InitNode, | ||
initminer_wallet: tt.Wallet, | ||
wallet_alice: tt.Wallet, | ||
alice: Account, | ||
create_new_account_token_for_alice: ClaimAccountToken, | ||
fee: tt.Asset.TestT, | ||
) -> None: | ||
initminer_wallet.create_account("bob") | ||
initminer_wallet.api.delegate_rc("initminer", [alice.name], 200000000000) | ||
|
||
with pytest.raises(tt.exceptions.CommunicationError) as exception: | ||
CreateClaimedAccount(node, wallet_alice, alice.name, "bob") | ||
|
||
assert ( | ||
"could not insert object, most likely a uniqueness constraint was violated inside index holding types" | ||
in exception.value.error | ||
) | ||
assert alice.get_pending_claimed_accounts() == 1, "Claim token was used. Shouldn't be." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters