From 02c079eda3145f49bddc59846fe46624d6628230 Mon Sep 17 00:00:00 2001
From: Ekaterina Chernitsyna <e.chernitsyna@yadro.com>
Date: Fri, 4 Aug 2023 15:32:09 +0300
Subject: [PATCH] [OBJECT-3949] delete mainchain ready

---
 src/frostfs_testlib/steps/payment_neogo.py    | 85 ++-----------------
 src/frostfs_testlib/storage/__init__.py       |  3 -
 src/frostfs_testlib/storage/constants.py      |  1 -
 .../storage/dataclasses/frostfs_services.py   | 24 ------
 4 files changed, 9 insertions(+), 104 deletions(-)

diff --git a/src/frostfs_testlib/steps/payment_neogo.py b/src/frostfs_testlib/steps/payment_neogo.py
index 6a64a5a..7fe0b4d 100644
--- a/src/frostfs_testlib/steps/payment_neogo.py
+++ b/src/frostfs_testlib/steps/payment_neogo.py
@@ -13,7 +13,7 @@ from frostfs_testlib.reporter import get_reporter
 from frostfs_testlib.resources.cli import NEOGO_EXECUTABLE
 from frostfs_testlib.resources.common import FROSTFS_CONTRACT, GAS_HASH, MORPH_BLOCK_TIME
 from frostfs_testlib.shell import Shell
-from frostfs_testlib.storage.dataclasses.frostfs_services import MainChain, MorphChain
+from frostfs_testlib.storage.dataclasses.frostfs_services import MorphChain
 from frostfs_testlib.utils import converting_utils, datetime_utils, wallet_utils
 
 reporter = get_reporter()
@@ -21,10 +21,8 @@ logger = logging.getLogger("NeoLogger")
 
 EMPTY_PASSWORD = ""
 TX_PERSIST_TIMEOUT = 15  # seconds
-ASSET_POWER_MAINCHAIN = 10**8
 ASSET_POWER_SIDECHAIN = 10**12
 
-
 def get_nns_contract_hash(morph_chain: MorphChain) -> str:
     return morph_chain.rpc_client.get_contract_state(1)["hash"]
 
@@ -41,33 +39,7 @@ def get_contract_hash(morph_chain: MorphChain, resolve_name: str, shell: Shell)
     stack_data = json.loads(out.stdout.replace("\n", ""))["stack"][0]["value"]
     return bytes.decode(base64.b64decode(stack_data[0]["value"]))
 
-
-@reporter.step_deco("Withdraw Mainnet Gas")
-def withdraw_mainnet_gas(shell: Shell, main_chain: MainChain, wlt: str, amount: int):
-    address = wallet_utils.get_last_address_from_wallet(wlt, EMPTY_PASSWORD)
-    scripthash = neo3_utils.address_to_script_hash(address)
-
-    neogo = NeoGo(shell=shell, neo_go_exec_path=NEOGO_EXECUTABLE)
-    out = neogo.contract.invokefunction(
-        wallet=wlt,
-        address=address,
-        rpc_endpoint=main_chain.get_endpoint(),
-        scripthash=FROSTFS_CONTRACT,
-        method="withdraw",
-        arguments=f"{scripthash} int:{amount}",
-        multisig_hash=f"{scripthash}:Global",
-        wallet_password="",
-    )
-
-    m = re.match(r"^Sent invocation transaction (\w{64})$", out.stdout)
-    if m is None:
-        raise Exception("Can not get Tx.")
-    tx = m.group(1)
-    if not transaction_accepted(main_chain, tx):
-        raise AssertionError(f"TX {tx} hasn't been processed")
-
-
-def transaction_accepted(main_chain: MainChain, tx_id: str):
+def transaction_accepted(morph_chain: MorphChain, tx_id: str):
     """
     This function returns True in case of accepted TX.
     Args:
@@ -79,8 +51,8 @@ def transaction_accepted(main_chain: MainChain, tx_id: str):
     try:
         for _ in range(0, TX_PERSIST_TIMEOUT):
             time.sleep(1)
-            neogo = NeoGo(shell=main_chain.host.get_shell(), neo_go_exec_path=NEOGO_EXECUTABLE)
-            resp = neogo.query.tx(tx_hash=tx_id, rpc_endpoint=main_chain.get_endpoint())
+            neogo = NeoGo(shell=morph_chain.host.get_shell(), neo_go_exec_path=NEOGO_EXECUTABLE)
+            resp = neogo.query.tx(tx_hash=tx_id, rpc_endpoint=morph_chain.get_endpoint())
             if resp is not None:
                 logger.info(f"TX is accepted in block: {resp}")
                 return True, resp
@@ -110,12 +82,11 @@ def get_balance(shell: Shell, morph_chain: MorphChain, wallet_path: str, wallet_
         logger.error(f"failed to get wallet balance: {out}")
         raise out
 
-
 @reporter.step_deco("Transfer Gas")
 def transfer_gas(
     shell: Shell,
     amount: int,
-    main_chain: MainChain,
+    morph_chain: MorphChain,
     wallet_from_path: Optional[str] = None,
     wallet_from_password: Optional[str] = None,
     address_from: Optional[str] = None,
@@ -138,11 +109,11 @@ def transfer_gas(
         address_to: The address of the wallet to transfer assets to.
         amount: Amount of gas to transfer.
     """
-    wallet_from_path = wallet_from_path or main_chain.get_wallet_path()
+    wallet_from_path = wallet_from_path or morph_chain.get_wallet_path()
     wallet_from_password = (
         wallet_from_password
         if wallet_from_password is not None
-        else main_chain.get_wallet_password()
+        else morph_chain.get_wallet_password()
     )
     address_from = address_from or wallet_utils.get_last_address_from_wallet(
         wallet_from_path, wallet_from_password
@@ -153,7 +124,7 @@ def transfer_gas(
 
     neogo = NeoGo(shell, neo_go_exec_path=NEOGO_EXECUTABLE)
     out = neogo.nep17.transfer(
-        rpc_endpoint=main_chain.get_endpoint(),
+        rpc_endpoint=morph_chain.get_endpoint(),
         wallet=wallet_from_path,
         wallet_password=wallet_from_password,
         amount=amount,
@@ -165,49 +136,11 @@ def transfer_gas(
     txid = out.stdout.strip().split("\n")[-1]
     if len(txid) != 64:
         raise Exception("Got no TXID after run the command")
-    if not transaction_accepted(main_chain, txid):
+    if not transaction_accepted(morph_chain, txid):
         raise AssertionError(f"TX {txid} hasn't been processed")
     time.sleep(datetime_utils.parse_time(MORPH_BLOCK_TIME))
 
 
-@reporter.step_deco("FrostFS Deposit")
-def deposit_gas(
-    shell: Shell,
-    main_chain: MainChain,
-    amount: int,
-    wallet_from_path: str,
-    wallet_from_password: str,
-):
-    """
-    Transferring GAS from given wallet to FrostFS contract address.
-    """
-    # get FrostFS contract address
-    deposit_addr = converting_utils.contract_hash_to_address(FROSTFS_CONTRACT)
-    logger.info(f"FrostFS contract address: {deposit_addr}")
-    address_from = wallet_utils.get_last_address_from_wallet(
-        wallet_path=wallet_from_path, wallet_password=wallet_from_password
-    )
-    transfer_gas(
-        shell=shell,
-        main_chain=main_chain,
-        amount=amount,
-        wallet_from_path=wallet_from_path,
-        wallet_from_password=wallet_from_password,
-        address_to=deposit_addr,
-        address_from=address_from,
-    )
-
-
-@reporter.step_deco("Get Mainnet Balance")
-def get_mainnet_balance(main_chain: MainChain, address: str):
-    resp = main_chain.rpc_client.get_nep17_balances(address=address)
-    logger.info(f"Got getnep17balances response: {resp}")
-    for balance in resp["balance"]:
-        if balance["assethash"] == GAS_HASH:
-            return float(balance["amount"]) / ASSET_POWER_MAINCHAIN
-    return float(0)
-
-
 @reporter.step_deco("Get Sidechain Balance")
 def get_sidechain_balance(morph_chain: MorphChain, address: str):
     resp = morph_chain.rpc_client.get_nep17_balances(address=address)
diff --git a/src/frostfs_testlib/storage/__init__.py b/src/frostfs_testlib/storage/__init__.py
index 531964c..3562d25 100644
--- a/src/frostfs_testlib/storage/__init__.py
+++ b/src/frostfs_testlib/storage/__init__.py
@@ -2,7 +2,6 @@ from frostfs_testlib.storage.constants import _FrostfsServicesNames
 from frostfs_testlib.storage.dataclasses.frostfs_services import (
     HTTPGate,
     InnerRing,
-    MainChain,
     MorphChain,
     S3Gate,
     StorageNode,
@@ -17,8 +16,6 @@ __class_registry.register_service(_FrostfsServicesNames.INNER_RING, InnerRing)
 __class_registry.register_service(_FrostfsServicesNames.MORPH_CHAIN, MorphChain)
 __class_registry.register_service(_FrostfsServicesNames.S3_GATE, S3Gate)
 __class_registry.register_service(_FrostfsServicesNames.HTTP_GATE, HTTPGate)
-# # TODO: Remove this since we are no longer have main chain
-__class_registry.register_service(_FrostfsServicesNames.MAIN_CHAIN, MainChain)
 
 
 def get_service_registry() -> ServiceRegistry:
diff --git a/src/frostfs_testlib/storage/constants.py b/src/frostfs_testlib/storage/constants.py
index 2f9d8a8..6deedfb 100644
--- a/src/frostfs_testlib/storage/constants.py
+++ b/src/frostfs_testlib/storage/constants.py
@@ -21,4 +21,3 @@ class _FrostfsServicesNames:
     HTTP_GATE = "http-gate"
     MORPH_CHAIN = "morph-chain"
     INNER_RING = "ir"
-    MAIN_CHAIN = "main-chain"
diff --git a/src/frostfs_testlib/storage/dataclasses/frostfs_services.py b/src/frostfs_testlib/storage/dataclasses/frostfs_services.py
index 944837a..ccb30d5 100644
--- a/src/frostfs_testlib/storage/dataclasses/frostfs_services.py
+++ b/src/frostfs_testlib/storage/dataclasses/frostfs_services.py
@@ -110,30 +110,6 @@ class MorphChain(NodeBase):
     def label(self) -> str:
         return f"{self.name}: {self.get_endpoint()}"
 
-
-class MainChain(NodeBase):
-    """
-    Class represents main-chain consensus node in a cluster
-
-    Consensus node is not always the same as physical host:
-        It can be service running in a container or on physical host (or physical node, if you will):
-    For testing perspective, it's not relevant how it is actually running,
-        since frostfs network will still treat it as "node"
-    """
-
-    rpc_client: RPCClient
-
-    def construct(self):
-        self.rpc_client = RPCClient(self.get_endpoint())
-
-    def get_endpoint(self) -> str:
-        return self._get_attribute(ConfigAttributes.ENDPOINT_INTERNAL)
-
-    @property
-    def label(self) -> str:
-        return f"{self.name}: {self.get_endpoint()}"
-
-
 class StorageNode(NodeBase):
     """
     Class represents storage node in a storage cluster