Skip to content

Commit

Permalink
Add tests for CreateClaimedAccountOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Masłowski authored and vogel76 committed Jul 17, 2024
1 parent 49cf341 commit bddb27f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
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."
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import TYPE_CHECKING

import test_tools as tt
from hive_local_tools.functional.python import sample_authority
from hive_local_tools.functional.python import basic_authority
from hive_local_tools.functional.python.operation import (
Operation,
create_transaction_with_any_operation,
Expand Down Expand Up @@ -53,9 +53,9 @@ def generate_transaction(self, creator: AccountName, new_account_name: AccountNa
CreateClaimedAccountOperation(
creator=creator,
new_account_name=new_account_name,
owner=sample_authority(public_key),
active=sample_authority(public_key),
posting=sample_authority(public_key),
owner=basic_authority(public_key),
active=basic_authority(public_key),
posting=basic_authority(public_key),
memo_key=public_key,
json_metadata="{}",
),
Expand Down

0 comments on commit bddb27f

Please sign in to comment.