Test: balance accounting test -> pytest
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
This commit is contained in:
parent
38a177107e
commit
37f73af11e
3 changed files with 93 additions and 5 deletions
|
@ -25,3 +25,4 @@ markers =
|
|||
failover_net: tests for network failure
|
||||
add_nodes: add nodes to cluster
|
||||
check_binaries: check neofs installed binaries versions
|
||||
payments: tests for payment associated operations
|
||||
|
|
79
pytest_tests/testsuites/payment/test_balance.py
Normal file
79
pytest_tests/testsuites/payment/test_balance.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
import logging
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from cli_utils import NeofsCli
|
||||
from common import ASSETS_DIR, NEOFS_ENDPOINT, WALLET_CONFIG
|
||||
from python_keywords.payment_neogo import _address_from_wallet
|
||||
from wallet import init_wallet
|
||||
|
||||
import allure
|
||||
|
||||
logger = logging.getLogger("NeoLogger")
|
||||
DEPOSIT_AMOUNT = 30
|
||||
|
||||
|
||||
@pytest.mark.payments
|
||||
class TestBalanceAccounting:
|
||||
@pytest.fixture(autouse=True)
|
||||
def prepare_two_wallets(self, prepare_wallet_and_deposit):
|
||||
self.user_wallet = prepare_wallet_and_deposit
|
||||
self.address = _address_from_wallet(self.user_wallet, "")
|
||||
_, self.another_address, _ = init_wallet(ASSETS_DIR)
|
||||
|
||||
@allure.title("Test balance request with wallet and address")
|
||||
def test_balance_wallet_address(self):
|
||||
cli = NeofsCli(config=WALLET_CONFIG)
|
||||
output = cli.accounting.balance(
|
||||
wallet=self.user_wallet, rpc_endpoint=NEOFS_ENDPOINT, address=self.address
|
||||
)
|
||||
logger.info(f"Out wallet+addres: {output}")
|
||||
assert int(output.rstrip()) == DEPOSIT_AMOUNT
|
||||
|
||||
@allure.title("Test balance request with wallet only")
|
||||
def test_balance_wallet(self):
|
||||
cli = NeofsCli(config=WALLET_CONFIG)
|
||||
output = cli.accounting.balance(
|
||||
wallet=self.user_wallet,
|
||||
rpc_endpoint=NEOFS_ENDPOINT,
|
||||
)
|
||||
logger.info(f"Out wallet: {output}")
|
||||
assert int(output.rstrip()) == DEPOSIT_AMOUNT
|
||||
|
||||
@allure.title("Test balance request with wallet and wrong address")
|
||||
def test_balance_wrong_address(self):
|
||||
with pytest.raises(
|
||||
Exception, match="address option must be specified and valid"
|
||||
):
|
||||
cli = NeofsCli(config=WALLET_CONFIG)
|
||||
cli.accounting.balance(
|
||||
wallet=self.user_wallet,
|
||||
rpc_endpoint=NEOFS_ENDPOINT,
|
||||
address=self.another_address,
|
||||
)
|
||||
|
||||
@allure.title("Test balance request with config file")
|
||||
def test_balance_api(self):
|
||||
config_file = self.write_api_config(
|
||||
endpoint=NEOFS_ENDPOINT, wallet=self.user_wallet
|
||||
)
|
||||
logger.info(f"YAML: {config_file}")
|
||||
cli = NeofsCli(config=config_file)
|
||||
output = cli.accounting.balance()
|
||||
logger.info(f"Out api: {output}")
|
||||
assert int(output.rstrip()) == DEPOSIT_AMOUNT
|
||||
|
||||
@staticmethod
|
||||
@allure.step("Write YAML config")
|
||||
def write_api_config(endpoint: str, wallet: str) -> str:
|
||||
with open(WALLET_CONFIG) as file:
|
||||
wallet_config = yaml.load(file, Loader=yaml.FullLoader)
|
||||
api_config = {
|
||||
**wallet_config,
|
||||
"rpc-endpoint": endpoint,
|
||||
"wallet": wallet,
|
||||
}
|
||||
api_config_file = f"{ASSETS_DIR}/config.yaml"
|
||||
with open(api_config_file, "w") as file:
|
||||
yaml.dump(api_config, file)
|
||||
return api_config_file
|
|
@ -4,8 +4,13 @@ from cli_utils.cli_command import NeofsCliCommand
|
|||
|
||||
|
||||
class NeofsCliAccounting(NeofsCliCommand):
|
||||
def balance(self, wallet: str, rpc_endpoint: str, address: Optional[str] = None,
|
||||
owner: Optional[str] = None) -> str:
|
||||
def balance(
|
||||
self,
|
||||
wallet: Optional[str] = None,
|
||||
rpc_endpoint: Optional[str] = None,
|
||||
address: Optional[str] = None,
|
||||
owner: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Get internal balance of NeoFS account
|
||||
|
||||
Args:
|
||||
|
@ -14,12 +19,15 @@ class NeofsCliAccounting(NeofsCliCommand):
|
|||
rpc_endpoint: remote node address (as 'multiaddr' or '<host>:<port>')
|
||||
wallet: WIF (NEP-2) string or path to the wallet or binary key
|
||||
|
||||
|
||||
Returns:
|
||||
str: Command string
|
||||
|
||||
"""
|
||||
return self._execute(
|
||||
'accounting balance',
|
||||
**{param: param_value for param, param_value in locals().items() if param not in ['self']}
|
||||
"accounting balance",
|
||||
**{
|
||||
param: param_value
|
||||
for param, param_value in locals().items()
|
||||
if param not in ["self"]
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue