forked from TrueCloudLab/frostfs-testcases
Refactor balance tests
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
parent
72d30c7e06
commit
1ec6540063
2 changed files with 64 additions and 50 deletions
|
@ -136,6 +136,10 @@ def run_health_check(collect_logs, hosting: Hosting):
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
@allure.title("Prepare wallet and deposit")
|
@allure.title("Prepare wallet and deposit")
|
||||||
def prepare_wallet_and_deposit(client_shell, prepare_tmp_dir):
|
def prepare_wallet_and_deposit(client_shell, prepare_tmp_dir):
|
||||||
|
return create_wallet_with_gas(client_shell, prepare_tmp_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def create_wallet_with_gas(client_shell, prepare_tmp_dir):
|
||||||
wallet_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{str(uuid.uuid4())}.json")
|
wallet_path = os.path.join(os.getcwd(), ASSETS_DIR, f"{str(uuid.uuid4())}.json")
|
||||||
init_wallet(wallet_path, WALLET_PASS)
|
init_wallet(wallet_path, WALLET_PASS)
|
||||||
allure.attach.file(wallet_path, os.path.basename(wallet_path), allure.attachment_type.JSON)
|
allure.attach.file(wallet_path, os.path.basename(wallet_path), allure.attachment_type.JSON)
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import uuid
|
|
||||||
|
|
||||||
import allure
|
import allure
|
||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
from common import (
|
from common import FREE_STORAGE, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, WALLET_CONFIG, WALLET_PASS
|
||||||
ASSETS_DIR,
|
|
||||||
FREE_STORAGE,
|
|
||||||
NEOFS_CLI_EXEC,
|
|
||||||
NEOFS_ENDPOINT,
|
|
||||||
WALLET_CONFIG,
|
|
||||||
WALLET_PASS,
|
|
||||||
)
|
|
||||||
from neofs_testlib.cli import NeofsCli
|
from neofs_testlib.cli import NeofsCli
|
||||||
from neofs_testlib.utils.wallet import get_last_address_from_wallet, init_wallet
|
from neofs_testlib.shell import CommandResult, Shell
|
||||||
|
from neofs_testlib.utils.wallet import get_last_address_from_wallet
|
||||||
|
|
||||||
|
from testsuites.conftest import create_wallet_with_gas
|
||||||
|
|
||||||
logger = logging.getLogger("NeoLogger")
|
logger = logging.getLogger("NeoLogger")
|
||||||
DEPOSIT_AMOUNT = 30
|
DEPOSIT_AMOUNT = 30
|
||||||
|
@ -23,51 +18,30 @@ DEPOSIT_AMOUNT = 30
|
||||||
@pytest.mark.payments
|
@pytest.mark.payments
|
||||||
@pytest.mark.skipif(FREE_STORAGE, reason="Test only works on public network with paid storage")
|
@pytest.mark.skipif(FREE_STORAGE, reason="Test only works on public network with paid storage")
|
||||||
class TestBalanceAccounting:
|
class TestBalanceAccounting:
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(scope="class")
|
||||||
def prepare_two_wallets(self, prepare_wallet_and_deposit):
|
def main_wallet(self, client_shell, prepare_tmp_dir) -> str:
|
||||||
self.user_wallet = prepare_wallet_and_deposit
|
return create_wallet_with_gas(client_shell=client_shell, prepare_tmp_dir=prepare_tmp_dir)
|
||||||
self.address = get_last_address_from_wallet(self.user_wallet, WALLET_PASS)
|
|
||||||
another_wallet = os.path.join(os.getcwd(), ASSETS_DIR, f"{str(uuid.uuid4())}.json")
|
|
||||||
init_wallet(another_wallet, WALLET_PASS)
|
|
||||||
self.another_address = get_last_address_from_wallet(another_wallet, WALLET_PASS)
|
|
||||||
|
|
||||||
@allure.title("Test balance request with wallet and address")
|
@pytest.fixture(scope="class")
|
||||||
def test_balance_wallet_address(self, client_shell):
|
def other_wallet(self, client_shell, prepare_tmp_dir) -> str:
|
||||||
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
|
return create_wallet_with_gas(client_shell=client_shell, prepare_tmp_dir=prepare_tmp_dir)
|
||||||
result = cli.accounting.balance(
|
|
||||||
wallet=self.user_wallet,
|
|
||||||
rpc_endpoint=NEOFS_ENDPOINT,
|
|
||||||
address=self.address,
|
|
||||||
)
|
|
||||||
assert int(result.stdout.rstrip()) == DEPOSIT_AMOUNT
|
|
||||||
|
|
||||||
@allure.title("Test balance request with wallet only")
|
@pytest.fixture(scope="class")
|
||||||
def test_balance_wallet(self, client_shell):
|
def cli(self, client_shell: Shell) -> NeofsCli:
|
||||||
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
|
return NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
|
||||||
result = cli.accounting.balance(wallet=self.user_wallet, rpc_endpoint=NEOFS_ENDPOINT)
|
|
||||||
assert int(result.stdout.rstrip()) == DEPOSIT_AMOUNT
|
|
||||||
|
|
||||||
@allure.title("Test balance request with wallet and wrong address")
|
@allure.step("Check deposit amount")
|
||||||
def test_balance_wrong_address(self, client_shell):
|
def check_amount(self, result: CommandResult) -> None:
|
||||||
with pytest.raises(Exception, match="address option must be specified and valid"):
|
amount_str = result.stdout.rstrip()
|
||||||
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
|
|
||||||
cli.accounting.balance(
|
try:
|
||||||
wallet=self.user_wallet,
|
amount = int(amount_str)
|
||||||
rpc_endpoint=NEOFS_ENDPOINT,
|
except Exception as ex:
|
||||||
address=self.another_address,
|
pytest.fail(
|
||||||
|
f"Amount parse error, should be parsable as int({DEPOSIT_AMOUNT}), but given {amount_str}: {ex}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@allure.title("Test balance request with config file")
|
assert amount == DEPOSIT_AMOUNT
|
||||||
def test_balance_api(self, prepare_tmp_dir, client_shell):
|
|
||||||
config_file = self.write_api_config(
|
|
||||||
config_dir=prepare_tmp_dir, endpoint=NEOFS_ENDPOINT, wallet=self.user_wallet
|
|
||||||
)
|
|
||||||
logger.info(f"Config with API endpoint: {config_file}")
|
|
||||||
|
|
||||||
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, config_file=config_file)
|
|
||||||
result = cli.accounting.balance()
|
|
||||||
|
|
||||||
assert int(result.stdout.rstrip()) == DEPOSIT_AMOUNT
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@allure.step("Write config with API endpoint")
|
@allure.step("Write config with API endpoint")
|
||||||
|
@ -83,3 +57,39 @@ class TestBalanceAccounting:
|
||||||
with open(api_config_file, "w") as file:
|
with open(api_config_file, "w") as file:
|
||||||
yaml.dump(api_config, file)
|
yaml.dump(api_config, file)
|
||||||
return api_config_file
|
return api_config_file
|
||||||
|
|
||||||
|
@allure.title("Test balance request with wallet and address")
|
||||||
|
def test_balance_wallet_address(self, main_wallet: str, cli: NeofsCli):
|
||||||
|
result = cli.accounting.balance(
|
||||||
|
wallet=main_wallet,
|
||||||
|
rpc_endpoint=NEOFS_ENDPOINT,
|
||||||
|
address=get_last_address_from_wallet(main_wallet, WALLET_PASS),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.check_amount(result)
|
||||||
|
|
||||||
|
@allure.title("Test balance request with wallet only")
|
||||||
|
def test_balance_wallet(self, main_wallet: str, cli: NeofsCli):
|
||||||
|
result = cli.accounting.balance(wallet=main_wallet, rpc_endpoint=NEOFS_ENDPOINT)
|
||||||
|
self.check_amount(result)
|
||||||
|
|
||||||
|
@allure.title("Test balance request with wallet and wrong address")
|
||||||
|
def test_balance_wrong_address(self, main_wallet: str, other_wallet: str, cli: NeofsCli):
|
||||||
|
with pytest.raises(Exception, match="address option must be specified and valid"):
|
||||||
|
cli.accounting.balance(
|
||||||
|
wallet=main_wallet,
|
||||||
|
rpc_endpoint=NEOFS_ENDPOINT,
|
||||||
|
address=get_last_address_from_wallet(other_wallet, WALLET_PASS),
|
||||||
|
)
|
||||||
|
|
||||||
|
@allure.title("Test balance request with config file")
|
||||||
|
def test_balance_api(self, prepare_tmp_dir: str, main_wallet: str, client_shell: Shell):
|
||||||
|
config_file = self.write_api_config(
|
||||||
|
config_dir=prepare_tmp_dir, endpoint=NEOFS_ENDPOINT, wallet=main_wallet
|
||||||
|
)
|
||||||
|
logger.info(f"Config with API endpoint: {config_file}")
|
||||||
|
|
||||||
|
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, config_file=config_file)
|
||||||
|
result = cli.accounting.balance()
|
||||||
|
|
||||||
|
self.check_amount(result)
|
||||||
|
|
Loading…
Reference in a new issue