2022-07-05 07:18:37 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
from re import search
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-07-01 17:30:07 +00:00
|
|
|
from robot.api import deco
|
|
|
|
|
2022-07-05 07:18:37 +00:00
|
|
|
import rpc_client
|
|
|
|
import wallet
|
|
|
|
from cli_helpers import _cmd_run
|
2022-07-05 10:17:36 +00:00
|
|
|
from common import (ASSETS_DIR, COMMON_PLACEMENT_RULE, CONTROL_NODE_USER, CONTROL_NODE_PWD,
|
|
|
|
FREE_STORAGE, MAINNET_WALLET_PATH, NEO_MAINNET_ENDPOINT, REMOTE_HOST)
|
2022-07-01 17:30:07 +00:00
|
|
|
from payment_neogo import neofs_deposit, transfer_mainnet_gas
|
2022-07-05 07:18:37 +00:00
|
|
|
from python_keywords.container import create_container
|
2022-07-01 17:30:07 +00:00
|
|
|
from ssh_helper import HostClient
|
2022-07-05 07:18:37 +00:00
|
|
|
from wellknown_acl import PUBLIC_ACL
|
|
|
|
|
|
|
|
deco.keyword = allure.step
|
|
|
|
|
|
|
|
logger = logging.getLogger('NeoLogger')
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session', autouse=True)
|
|
|
|
@allure.title('Check binary versions')
|
|
|
|
def check_binary_versions(request):
|
|
|
|
environment_dir = request.config.getoption('--alluredir')
|
|
|
|
binaries = ['neo-go', 'neofs-cli', 'neofs-authmate', 'aws']
|
|
|
|
env_out = {}
|
|
|
|
for binary in binaries:
|
|
|
|
out = _cmd_run(f'{binary} --version')
|
|
|
|
version = search(r'(v?\d.*)\s+', out)
|
|
|
|
version = version.group(1) if version else 'Unknown'
|
|
|
|
env_out[binary.upper()] = version
|
|
|
|
|
|
|
|
if environment_dir:
|
|
|
|
with open(f'{environment_dir}/environment.properties', 'w') as out_file:
|
|
|
|
for env, env_value in env_out.items():
|
|
|
|
out_file.write(f'{env}={env_value}\n')
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
@allure.title('Init wallet with address')
|
|
|
|
def init_wallet_with_address():
|
|
|
|
full_path = f'{os.getcwd()}/{ASSETS_DIR}'
|
|
|
|
os.mkdir(full_path)
|
|
|
|
|
2022-07-05 10:17:36 +00:00
|
|
|
yield wallet.init_wallet(ASSETS_DIR)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
shutil.rmtree(full_path)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
@allure.title('Prepare wallet and deposit')
|
|
|
|
def prepare_wallet_and_deposit(init_wallet_with_address):
|
2022-07-01 17:30:07 +00:00
|
|
|
local_wallet_path = None
|
|
|
|
wallet, addr, _ = init_wallet_with_address
|
|
|
|
logger.info(f'Init wallet: {wallet},\naddr: {addr}')
|
|
|
|
|
|
|
|
if REMOTE_HOST:
|
|
|
|
ssh_client = HostClient(REMOTE_HOST, CONTROL_NODE_USER, CONTROL_NODE_PWD)
|
|
|
|
local_wallet_path = os.path.join(ASSETS_DIR, os.path.basename(MAINNET_WALLET_PATH))
|
|
|
|
ssh_client.copy_file_from_host(MAINNET_WALLET_PATH, local_wallet_path)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-05 10:17:36 +00:00
|
|
|
if not FREE_STORAGE:
|
|
|
|
deposit = 30
|
|
|
|
transfer_mainnet_gas(wallet, deposit + 1, wallet_path=local_wallet_path or MAINNET_WALLET_PATH)
|
|
|
|
neofs_deposit(wallet, deposit)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-01 17:30:07 +00:00
|
|
|
return wallet
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
@allure.title('Create Container')
|
|
|
|
def prepare_container(prepare_wallet_and_deposit):
|
2022-07-01 17:30:07 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
return prepare_container_impl(wallet)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
@allure.title('Create Public Container')
|
|
|
|
def prepare_public_container(prepare_wallet_and_deposit):
|
|
|
|
placement_rule = 'REP 1 IN X CBF 1 SELECT 1 FROM * AS X'
|
2022-07-01 17:30:07 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
return prepare_container_impl(wallet, rule=placement_rule, basic_acl=PUBLIC_ACL)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
|
2022-07-01 17:30:07 +00:00
|
|
|
def prepare_container_impl(wallet: str, rule=COMMON_PLACEMENT_RULE, basic_acl: str = ''):
|
2022-07-05 07:18:37 +00:00
|
|
|
cid = create_container(wallet, rule=rule, basic_acl=basic_acl)
|
|
|
|
return cid, wallet
|
|
|
|
|
|
|
|
|
|
|
|
@allure.step('Wait until transaction accepted in block')
|
2022-07-05 10:17:36 +00:00
|
|
|
def wait_until_transaction_accepted_in_block(tx_id: str):
|
2022-07-05 07:18:37 +00:00
|
|
|
"""
|
|
|
|
This function return True in case of accepted TX.
|
|
|
|
Parameters:
|
|
|
|
:param tx_id: transaction ID
|
|
|
|
"""
|
|
|
|
mainnet_rpc_cli = rpc_client.RPCClient(NEO_MAINNET_ENDPOINT)
|
|
|
|
|
|
|
|
if isinstance(tx_id, bytes):
|
|
|
|
tx_id = tx_id.decode()
|
|
|
|
|
|
|
|
sleep_interval, attempts = 5, 10
|
|
|
|
|
|
|
|
for __attempt in range(attempts):
|
|
|
|
try:
|
|
|
|
resp = mainnet_rpc_cli.get_transaction_height(tx_id)
|
|
|
|
if resp is not None:
|
|
|
|
logger.info(f"got block height: {resp}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
|
|
logger.info(f"request failed with error: {e}")
|
|
|
|
raise e
|
|
|
|
sleep(sleep_interval)
|
|
|
|
raise TimeoutError(f'Timeout {sleep_interval * attempts} sec. reached on waiting for transaction accepted')
|