2022-09-06 13:58:11 +00:00
|
|
|
import logging
|
2022-10-17 10:57:27 +00:00
|
|
|
import os
|
2022-10-27 05:43:20 +00:00
|
|
|
import uuid
|
2022-09-06 13:58:11 +00:00
|
|
|
|
2022-09-27 09:12:16 +00:00
|
|
|
import allure
|
2022-09-06 13:58:11 +00:00
|
|
|
import pytest
|
|
|
|
import yaml
|
2022-10-27 05:43:20 +00:00
|
|
|
from common import ASSETS_DIR, FREE_STORAGE, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, WALLET_CONFIG, WALLET_PASS
|
2022-10-13 18:53:44 +00:00
|
|
|
from neofs_testlib.cli import NeofsCli
|
2022-10-27 05:43:20 +00:00
|
|
|
from neofs_testlib.utils.wallet import get_last_address_from_wallet, init_wallet
|
2022-09-06 13:58:11 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("NeoLogger")
|
|
|
|
DEPOSIT_AMOUNT = 30
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.payments
|
2022-09-27 09:12:16 +00:00
|
|
|
@pytest.mark.skipif(FREE_STORAGE, reason="Test only works on public network with paid storage")
|
2022-09-06 13:58:11 +00:00
|
|
|
class TestBalanceAccounting:
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def prepare_two_wallets(self, prepare_wallet_and_deposit):
|
|
|
|
self.user_wallet = prepare_wallet_and_deposit
|
2022-10-27 05:43:20 +00:00
|
|
|
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)
|
2022-09-06 13:58:11 +00:00
|
|
|
|
|
|
|
@allure.title("Test balance request with wallet and address")
|
2022-10-13 18:53:44 +00:00
|
|
|
def test_balance_wallet_address(self, client_shell):
|
|
|
|
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
|
2022-09-06 13:58:11 +00:00
|
|
|
output = cli.accounting.balance(
|
2022-09-27 09:12:16 +00:00
|
|
|
wallet=self.user_wallet,
|
|
|
|
rpc_endpoint=NEOFS_ENDPOINT,
|
|
|
|
address=self.address,
|
2022-09-06 13:58:11 +00:00
|
|
|
)
|
2022-10-13 18:53:44 +00:00
|
|
|
assert int(output.stdout.rstrip()) == DEPOSIT_AMOUNT
|
2022-09-06 13:58:11 +00:00
|
|
|
|
|
|
|
@allure.title("Test balance request with wallet only")
|
2022-10-13 18:53:44 +00:00
|
|
|
def test_balance_wallet(self, client_shell):
|
|
|
|
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
|
2022-09-27 09:12:16 +00:00
|
|
|
output = cli.accounting.balance(wallet=self.user_wallet, rpc_endpoint=NEOFS_ENDPOINT)
|
2022-10-13 18:53:44 +00:00
|
|
|
assert int(output.stdout.rstrip()) == DEPOSIT_AMOUNT
|
2022-09-06 13:58:11 +00:00
|
|
|
|
|
|
|
@allure.title("Test balance request with wallet and wrong address")
|
2022-10-13 18:53:44 +00:00
|
|
|
def test_balance_wrong_address(self, client_shell):
|
2022-09-27 09:12:16 +00:00
|
|
|
with pytest.raises(Exception, match="address option must be specified and valid"):
|
2022-10-13 18:53:44 +00:00
|
|
|
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
|
2022-09-06 13:58:11 +00:00
|
|
|
cli.accounting.balance(
|
|
|
|
wallet=self.user_wallet,
|
|
|
|
rpc_endpoint=NEOFS_ENDPOINT,
|
|
|
|
address=self.another_address,
|
|
|
|
)
|
|
|
|
|
|
|
|
@allure.title("Test balance request with config file")
|
2022-10-17 10:57:27 +00:00
|
|
|
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
|
2022-09-06 13:58:11 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-10-17 10:57:27 +00:00
|
|
|
@allure.step("Write config with API endpoint")
|
|
|
|
def write_api_config(config_dir: str, endpoint: str, wallet: str) -> str:
|
|
|
|
with open(WALLET_CONFIG, "r") as file:
|
|
|
|
wallet_config = yaml.full_load(file)
|
2022-09-06 13:58:11 +00:00
|
|
|
api_config = {
|
|
|
|
**wallet_config,
|
|
|
|
"rpc-endpoint": endpoint,
|
|
|
|
"wallet": wallet,
|
|
|
|
}
|
2022-10-17 10:57:27 +00:00
|
|
|
api_config_file = os.path.join(config_dir, "neofs-cli-api-config.yaml")
|
2022-09-06 13:58:11 +00:00
|
|
|
with open(api_config_file, "w") as file:
|
|
|
|
yaml.dump(api_config, file)
|
|
|
|
return api_config_file
|