2022-09-20 15:03:52 +00:00
|
|
|
import logging
|
2022-10-27 05:43:20 +00:00
|
|
|
from time import sleep
|
2022-12-23 11:42:41 +00:00
|
|
|
from typing import Optional
|
2022-07-05 10:17:36 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import allure
|
2022-12-23 11:42:41 +00:00
|
|
|
from cluster import Cluster, StorageNode
|
|
|
|
from common import (
|
|
|
|
MAINNET_BLOCK_TIME,
|
|
|
|
NEOFS_ADM_CONFIG_PATH,
|
|
|
|
NEOFS_ADM_EXEC,
|
|
|
|
NEOFS_CLI_EXEC,
|
|
|
|
NEOGO_EXECUTABLE,
|
|
|
|
)
|
|
|
|
from neofs_testlib.cli import NeofsAdm, NeofsCli, NeoGo
|
2022-10-27 05:43:20 +00:00
|
|
|
from neofs_testlib.shell import Shell
|
|
|
|
from neofs_testlib.utils.wallet import get_last_address_from_wallet
|
|
|
|
from payment_neogo import get_contract_hash
|
|
|
|
from utility import parse_time
|
2022-07-05 10:17:36 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-07-04 19:49:14 +00:00
|
|
|
|
|
|
|
|
2022-11-25 12:44:47 +00:00
|
|
|
@allure.step("Ensure fresh epoch")
|
2022-12-23 11:42:41 +00:00
|
|
|
def ensure_fresh_epoch(
|
|
|
|
shell: Shell, cluster: Cluster, alive_node: Optional[StorageNode] = None
|
|
|
|
) -> int:
|
2022-11-25 12:44:47 +00:00
|
|
|
# ensure new fresh epoch to avoid epoch switch during test session
|
2022-12-23 11:42:41 +00:00
|
|
|
alive_node = alive_node if alive_node else cluster.storage_nodes[0]
|
|
|
|
current_epoch = get_epoch(shell, cluster, alive_node)
|
|
|
|
tick_epoch(shell, cluster, alive_node)
|
|
|
|
epoch = get_epoch(shell, cluster, alive_node)
|
2022-11-25 12:44:47 +00:00
|
|
|
assert epoch > current_epoch, "Epoch wasn't ticked"
|
|
|
|
return epoch
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Epoch")
|
2022-12-23 11:42:41 +00:00
|
|
|
def get_epoch(shell: Shell, cluster: Cluster, alive_node: Optional[StorageNode] = None):
|
|
|
|
alive_node = alive_node if alive_node else cluster.storage_nodes[0]
|
|
|
|
wallet_path = alive_node.get_wallet_path()
|
|
|
|
wallet_config = alive_node.get_wallet_config_path()
|
2022-12-05 22:31:45 +00:00
|
|
|
|
2022-12-23 11:42:41 +00:00
|
|
|
cli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=wallet_config)
|
|
|
|
|
|
|
|
epoch = cli.netmap.epoch(cluster.default_rpc_endpoint, wallet_path)
|
|
|
|
return int(epoch.stdout)
|
2022-07-04 19:49:14 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Tick Epoch")
|
2022-12-23 11:42:41 +00:00
|
|
|
def tick_epoch(shell: Shell, cluster: Cluster, alive_node: Optional[StorageNode] = None):
|
|
|
|
"""
|
|
|
|
Tick epoch using neofs-adm or NeoGo if neofs-adm is not available (DevEnv)
|
|
|
|
Args:
|
|
|
|
shell: local shell to make queries about current epoch. Remote shell will be used to tick new one
|
|
|
|
cluster: cluster instance under test
|
|
|
|
alive_node: node to send requests to (first node in cluster by default)
|
|
|
|
"""
|
|
|
|
|
|
|
|
alive_node = alive_node if alive_node else cluster.storage_nodes[0]
|
|
|
|
remote_shell = alive_node.host.get_shell()
|
2022-12-05 22:31:45 +00:00
|
|
|
|
2022-07-13 14:30:57 +00:00
|
|
|
if NEOFS_ADM_EXEC and NEOFS_ADM_CONFIG_PATH:
|
|
|
|
# If neofs-adm is available, then we tick epoch with it (to be consistent with UAT tests)
|
2022-10-27 05:43:20 +00:00
|
|
|
neofsadm = NeofsAdm(
|
2022-12-23 11:42:41 +00:00
|
|
|
shell=remote_shell,
|
|
|
|
neofs_adm_exec_path=NEOFS_ADM_EXEC,
|
|
|
|
config_file=NEOFS_ADM_CONFIG_PATH,
|
2022-10-27 05:43:20 +00:00
|
|
|
)
|
|
|
|
neofsadm.morph.force_new_epoch()
|
2022-07-13 14:30:57 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# Otherwise we tick epoch using transaction
|
2022-12-05 22:31:45 +00:00
|
|
|
cur_epoch = get_epoch(shell, cluster)
|
|
|
|
|
2022-12-23 11:42:41 +00:00
|
|
|
# Use first node by default
|
2022-12-05 22:31:45 +00:00
|
|
|
ir_node = cluster.ir_nodes[0]
|
|
|
|
# In case if no local_wallet_path is provided, we use wallet_path
|
|
|
|
ir_wallet_path = ir_node.get_wallet_path()
|
|
|
|
ir_wallet_pass = ir_node.get_wallet_password()
|
|
|
|
ir_address = get_last_address_from_wallet(ir_wallet_path, ir_wallet_pass)
|
2022-10-27 05:43:20 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
morph_chain = cluster.morph_chain_nodes[0]
|
|
|
|
morph_endpoint = morph_chain.get_endpoint()
|
2022-10-27 05:43:20 +00:00
|
|
|
|
|
|
|
neogo = NeoGo(shell, neo_go_exec_path=NEOGO_EXECUTABLE)
|
|
|
|
neogo.contract.invokefunction(
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet=ir_wallet_path,
|
|
|
|
wallet_password=ir_wallet_pass,
|
|
|
|
scripthash=get_contract_hash(morph_chain, "netmap.neofs", shell=shell),
|
2022-10-27 05:43:20 +00:00
|
|
|
method="newEpoch",
|
|
|
|
arguments=f"int:{cur_epoch + 1}",
|
|
|
|
multisig_hash=f"{ir_address}:Global",
|
|
|
|
address=ir_address,
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=morph_endpoint,
|
2022-10-27 05:43:20 +00:00
|
|
|
force=True,
|
|
|
|
gas=1,
|
2022-09-20 15:03:52 +00:00
|
|
|
)
|
2022-10-27 05:43:20 +00:00
|
|
|
sleep(parse_time(MAINNET_BLOCK_TIME))
|