2022-10-27 05:43:20 +00:00
|
|
|
import json
|
2022-09-20 15:03:52 +00:00
|
|
|
import logging
|
2022-10-27 05:43:20 +00:00
|
|
|
from time import sleep
|
2022-07-05 10:17:36 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import allure
|
|
|
|
from common import (
|
|
|
|
IR_WALLET_PASS,
|
|
|
|
IR_WALLET_PATH,
|
2022-10-27 05:43:20 +00:00
|
|
|
MAINNET_BLOCK_TIME,
|
2022-09-20 15:03:52 +00:00
|
|
|
MORPH_ENDPOINT,
|
|
|
|
NEOFS_ADM_CONFIG_PATH,
|
|
|
|
NEOFS_ADM_EXEC,
|
2022-10-27 05:43:20 +00:00
|
|
|
NEOGO_EXECUTABLE,
|
2022-09-20 15:03:52 +00:00
|
|
|
)
|
2022-10-27 05:43:20 +00:00
|
|
|
from neofs_testlib.cli import NeofsAdm, NeoGo
|
|
|
|
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")
|
|
|
|
def ensure_fresh_epoch(shell: Shell) -> int:
|
|
|
|
# ensure new fresh epoch to avoid epoch switch during test session
|
|
|
|
current_epoch = get_epoch(shell)
|
|
|
|
tick_epoch(shell)
|
|
|
|
epoch = get_epoch(shell)
|
|
|
|
assert epoch > current_epoch, "Epoch wasn't ticked"
|
|
|
|
return epoch
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Epoch")
|
2022-10-27 05:43:20 +00:00
|
|
|
def get_epoch(shell: Shell):
|
|
|
|
neogo = NeoGo(shell=shell, neo_go_exec_path=NEOGO_EXECUTABLE)
|
|
|
|
out = neogo.contract.testinvokefunction(
|
|
|
|
scripthash=get_contract_hash("netmap.neofs", shell=shell),
|
|
|
|
method="epoch",
|
|
|
|
rpc_endpoint=MORPH_ENDPOINT,
|
2022-07-04 19:49:14 +00:00
|
|
|
)
|
2022-10-27 05:43:20 +00:00
|
|
|
return int(json.loads(out.stdout.replace("\n", ""))["stack"][0]["value"])
|
2022-07-04 19:49:14 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Tick Epoch")
|
2022-10-27 05:43:20 +00:00
|
|
|
def tick_epoch(shell: Shell):
|
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(
|
|
|
|
shell=shell, neofs_adm_exec_path=NEOFS_ADM_EXEC, config_file=NEOFS_ADM_CONFIG_PATH
|
|
|
|
)
|
|
|
|
neofsadm.morph.force_new_epoch()
|
2022-07-13 14:30:57 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# Otherwise we tick epoch using transaction
|
2022-10-27 05:43:20 +00:00
|
|
|
cur_epoch = get_epoch(shell)
|
|
|
|
|
|
|
|
ir_address = get_last_address_from_wallet(IR_WALLET_PATH, IR_WALLET_PASS)
|
|
|
|
|
|
|
|
neogo = NeoGo(shell, neo_go_exec_path=NEOGO_EXECUTABLE)
|
|
|
|
neogo.contract.invokefunction(
|
|
|
|
wallet=IR_WALLET_PATH,
|
|
|
|
wallet_password=IR_WALLET_PASS,
|
|
|
|
scripthash=get_contract_hash("netmap.neofs", shell=shell),
|
|
|
|
method="newEpoch",
|
|
|
|
arguments=f"int:{cur_epoch + 1}",
|
|
|
|
multisig_hash=f"{ir_address}:Global",
|
|
|
|
address=ir_address,
|
|
|
|
rpc_endpoint=MORPH_ENDPOINT,
|
|
|
|
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))
|