Skip to content

Commit

Permalink
tests: add new deployment tests with main chain
Browse files Browse the repository at this point in the history
Part of #943

Signed-off-by: Evgeniy Zayats <[email protected]>
  • Loading branch information
Evgeniy Zayats committed Feb 6, 2025
1 parent fa763bb commit aedee27
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 86 deletions.
58 changes: 37 additions & 21 deletions neofs-testlib/neofs_testlib/env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,31 @@ def deploy_neofs_contract(self):
"There should be at least a single IR instance configured(not started) to deploy neofs contract"
)
neo_go = self.neo_go()
neo_go.nep17.balance(
self.main_chain.wallet.address,
"GAS",
f"http://{self.main_chain.rpc_address}",
wallet_config=self.main_chain.neo_go_config,
)
neo_go.nep17.transfer(
"GAS",
self.default_wallet.address,
f"http://{self.main_chain.rpc_address}",
from_address=self.inner_ring_nodes[-1].alphabet_wallet.address,
from_address=self.main_chain.wallet.address,
amount=9000,
force=True,
wallet_config=self.main_chain.neo_go_config,
await_=True,
)
ir_alphabet_pubkey_from_neogo = wallet_utils.get_last_public_key_from_wallet_with_neogo(
self.neo_go(), self.inner_ring_nodes[-1].alphabet_wallet.path
mainchain_pubkey = wallet_utils.get_last_public_key_from_wallet_with_neogo(
self.neo_go(), self.main_chain.wallet.path
)
result = neo_go.contract.deploy(
input_file=f"{self.neofs_contract_dir}/neofs/neofs_contract.nef",
manifest=f"{self.neofs_contract_dir}/neofs/config.json",
force=True,
rpc_endpoint=f"http://{self.main_chain.rpc_address}",
post_data=f"[ true ffffffffffffffffffffffffffffffffffffffff [ {ir_alphabet_pubkey_from_neogo} ] [ InnerRingCandidateFee 10 WithdrawFee 10 ] ]",
post_data=f"[ true ffffffffffffffffffffffffffffffffffffffff [ {mainchain_pubkey} ] [ InnerRingCandidateFee 10 WithdrawFee 10 ] ]",
wallet_config=self.default_wallet_neogo_config,
)
contract_hash = result.stdout.split("Contract: ")[-1].strip()
Expand Down Expand Up @@ -304,34 +310,34 @@ def generate_storage_wallet(

@allure.step("Generate alphabet wallets")
def generate_alphabet_wallets(
self,
network_config: Optional[str] = None,
size: Optional[int] = 1,
self, network_config: Optional[str] = None, size: Optional[int] = 1, alphabet_wallets_dir: Optional[str] = None
) -> list[NodeWallet]:
neofs_adm = self.neofs_adm(network_config)

neofs_adm.fschain.generate_alphabet(alphabet_wallets=self.alphabet_wallets_dir, size=size)
if not alphabet_wallets_dir:
alphabet_wallets_dir = self.alphabet_wallets_dir
neofs_adm.fschain.generate_alphabet(alphabet_wallets=alphabet_wallets_dir, size=size)

generated_wallets = []

for generated_wallet in os.listdir(self.alphabet_wallets_dir):
for generated_wallet in os.listdir(alphabet_wallets_dir):
# neo3 package requires some attributes to be set
with open(os.path.join(self.alphabet_wallets_dir, generated_wallet), "r") as wallet_file:
with open(os.path.join(alphabet_wallets_dir, generated_wallet), "r") as wallet_file:
wallet_json = json.load(wallet_file)

wallet_json["name"] = None
for acc in wallet_json["accounts"]:
acc["extra"] = None

with open(os.path.join(self.alphabet_wallets_dir, generated_wallet), "w") as wallet_file:
with open(os.path.join(alphabet_wallets_dir, generated_wallet), "w") as wallet_file:
json.dump(wallet_json, wallet_file)

generated_wallets.append(
NodeWallet(
path=os.path.join(self.alphabet_wallets_dir, generated_wallet),
path=os.path.join(alphabet_wallets_dir, generated_wallet),
password=self.default_password,
address=wallet_utils.get_last_address_from_wallet(
os.path.join(self.alphabet_wallets_dir, generated_wallet), self.default_password
os.path.join(alphabet_wallets_dir, generated_wallet), self.default_password
),
)
)
Expand Down Expand Up @@ -677,6 +683,8 @@ def __init__(self, neofs_env: NeoFSEnv):
self.p2p_address = f"{self.neofs_env.domain}:{NeoFSEnv.get_available_port()}"
self.pprof_address = f"{self.neofs_env.domain}:{NeoFSEnv.get_available_port()}"
self.prometheus_address = f"{self.neofs_env.domain}:{NeoFSEnv.get_available_port()}"
self.wallet_dir = self.neofs_env._generate_temp_dir(prefix="mainchain_wallet")
self.wallet = None
self.stdout = "Not initialized"
self.stderr = "Not initialized"
self.process = None
Expand Down Expand Up @@ -706,21 +714,31 @@ def start(self, wait_until_ready=True):
if self.process is not None:
raise RuntimeError("This main chain instance has already been started")

alphabet_wallet = self.neofs_env.inner_ring_nodes[-1].alphabet_wallet
self.wallet = self.neofs_env.generate_alphabet_wallets(alphabet_wallets_dir=self.wallet_dir)[0]

standby_committee = wallet_utils.get_last_public_key_from_wallet_with_neogo(
self.neofs_env.neo_go(), self.wallet.path
)

ir_alphabet_pubkey_from_neogo = wallet_utils.get_last_public_key_from_wallet_with_neogo(
self.neofs_env.neo_go(), alphabet_wallet.path
self.neofs_env.neo_go(), self.neofs_env.inner_ring_nodes[-1].alphabet_wallet.path
)

if len(self.neofs_env.inner_ring_nodes) > 1:
ir_public_keys = ir_alphabet_pubkey_from_neogo.splitlines()[:3]
else:
ir_public_keys = [ir_alphabet_pubkey_from_neogo]

logger.info(f"Generating main chain config at: {self.main_chain_config_path}")
main_chain_config_template = "main_chain.yaml"

NeoFSEnv.generate_config_file(
config_template=main_chain_config_template,
config_path=self.main_chain_config_path,
custom=Path(main_chain_config_template).is_file(),
wallet=alphabet_wallet,
public_key=ir_alphabet_pubkey_from_neogo,
wallet=self.wallet,
standby_committee=standby_committee,
ir_public_keys=ir_public_keys,
main_chain_boltdb=self.main_chain_boltdb,
p2p_address=self.p2p_address,
rpc_address=self.rpc_address,
Expand All @@ -729,12 +747,10 @@ def start(self, wait_until_ready=True):
prometheus_address=self.prometheus_address,
)
logger.info(f"Generating CLI config at: {self.cli_config}")
NeoFSEnv.generate_config_file(
config_template="cli_cfg.yaml", config_path=self.cli_config, wallet=alphabet_wallet
)
NeoFSEnv.generate_config_file(config_template="cli_cfg.yaml", config_path=self.cli_config, wallet=self.wallet)
logger.info(f"Generating NEO GO config at: {self.neo_go_config}")
NeoFSEnv.generate_config_file(
config_template="neo_go_cfg.yaml", config_path=self.neo_go_config, wallet=alphabet_wallet
config_template="neo_go_cfg.yaml", config_path=self.neo_go_config, wallet=self.wallet
)
logger.info(f"Launching Main Chain:{self}")
self._launch_process()
Expand Down
14 changes: 13 additions & 1 deletion neofs-testlib/neofs_testlib/env/templates/main_chain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ ProtocolConfiguration:
TimePerBlock: 1s
MemPoolSize: 50000
StandbyCommittee:
- {{ public_key }}
- {{ standby_committee }}
ValidatorsCount: 1
VerifyTransactions: true
P2PSigExtensions: false
{% if ir_public_keys | length > 1 %}
Genesis:
Roles:
NeoFSAlphabet:
{%- for public_key in ir_public_keys %}
- {{ public_key }}
{%- endfor %}
P2PNotary:
{%- for public_key in ir_public_keys %}
- {{ public_key }}
{%- endfor %}
{% endif %}

ApplicationConfiguration:
SkipBlockVerification: false
Expand Down
51 changes: 51 additions & 0 deletions pytest_tests/lib/helpers/wallet_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,54 @@ def wait_for_correct_wallet_balance(
assert compare_func(get_wallet_balance(neofs_env, neo_go, wallet, neo_go_wallet_config)), (
"Wallet balance is not correct after"
)


def create_wallet_with_money(neofs_env_with_mainchain: NeoFSEnv) -> NodeWallet:
neofs_env = neofs_env_with_mainchain

with allure.step("Create wallet for deposit"):
wallet = NodeWallet(
path=neofs_env_with_mainchain._generate_temp_file(
neofs_env._env_dir, prefix="deposit_withdrawal_test_wallet"
),
address="",
password=neofs_env.default_password,
)
init_wallet(wallet.path, wallet.password)
wallet.address = get_last_address_from_wallet(wallet.path, wallet.password)
wallet.neo_go_config = neofs_env.generate_neo_go_config(wallet)
wallet.cli_config = neofs_env.generate_cli_config(wallet)

with allure.step("Transfer some money to created wallet"):
neo_go = neofs_env.neo_go()
neo_go.nep17.transfer(
"GAS",
wallet.address,
f"http://{neofs_env.main_chain.rpc_address}",
from_address=neofs_env.main_chain.wallet.address,
amount=1000,
force=True,
wallet_config=neofs_env.main_chain.neo_go_config,
await_=True,
)
assert get_wallet_balance(neofs_env, neo_go, wallet, wallet.neo_go_config) == 1000.0, (
"Money transfer from alphabet to test wallet didn't succeed"
)

with allure.step("Deposit money to neofs contract"):
neo_go.nep17.transfer(
"GAS",
neofs_env.main_chain.neofs_contract_address,
f"http://{neofs_env.main_chain.rpc_address}",
from_address=wallet.address,
amount=100,
force=True,
wallet_config=wallet.neo_go_config,
await_=True,
)
assert get_wallet_balance(neofs_env, neo_go, wallet, wallet.neo_go_config) <= 900, (
"Wallet balance is not correct after deposit"
)
wait_for_correct_neofs_balance(neofs_env, wallet, wallet.cli_config, lambda balance: balance == 100)

return wallet
61 changes: 53 additions & 8 deletions pytest_tests/tests/network/test_deployment.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import time
from importlib.resources import files

import allure
import pytest
import yaml
from helpers.common import SIMPLE_OBJECT_SIZE
from helpers.container import create_container
from helpers.file_helper import generate_file, get_file_hash
from helpers.neofs_verbs import get_object_from_random_node, put_object_to_random_node
from helpers.wallet_helpers import create_wallet
from helpers.neofs_verbs import get_object_from_random_node, put_object, put_object_to_random_node
from helpers.wallet_helpers import create_wallet, create_wallet_with_money
from neofs_testlib.env.env import NeoFSEnv, NodeWallet


@pytest.fixture
def clear_neofs_env():
neofs_env_config = yaml.safe_load(
files("neofs_testlib.env.templates").joinpath("neofs_env_config.yaml").read_text()
)
neofs_env = NeoFSEnv(neofs_env_config=neofs_env_config)
neofs_env = NeoFSEnv(neofs_env_config=NeoFSEnv._generate_default_neofs_env_config())
yield neofs_env
neofs_env.kill()

Expand Down Expand Up @@ -92,3 +88,52 @@ def test_multiple_ir_node_deployment(ir_nodes_count: int, clear_neofs_env: NeoFS

with allure.step("Run put get to ensure neofs setup is actually working"):
put_get_object(neofs_env, default_wallet)


@pytest.mark.parametrize("ir_nodes_count", [4, 7])
def test_multiple_ir_node_deployment_with_main_chain(ir_nodes_count: int, clear_neofs_env: NeoFSEnv):
neofs_env = clear_neofs_env
with allure.step(f"Deploy neofs with {ir_nodes_count} ir nodes and main chain"):
neofs_env.download_binaries()
neofs_env.deploy_inner_ring_nodes(count=ir_nodes_count, with_main_chain=True)
neofs_env.deploy_storage_nodes(
count=1,
node_attrs={
0: ["UN-LOCODE:RU MOW", "Price:22"],
1: ["UN-LOCODE:RU LED", "Price:33"],
2: ["UN-LOCODE:SE STO", "Price:11"],
3: ["UN-LOCODE:FI HEL", "Price:44"],
},
)
neofs_env.log_env_details_to_file()
neofs_env.log_versions_to_allure()

neofs_adm = neofs_env.neofs_adm()
for sn in neofs_env.storage_nodes:
neofs_adm.fschain.refill_gas(
rpc_endpoint=f"http://{neofs_env.fschain_rpc}",
alphabet_wallets=neofs_env.alphabet_wallets_dir,
storage_wallet=sn.wallet.path,
gas="10.0",
)
neofs_env.neofs_adm().fschain.set_config(
rpc_endpoint=f"http://{neofs_env.fschain_rpc}",
alphabet_wallets=neofs_env.alphabet_wallets_dir,
post_data="WithdrawFee=5",
)

with allure.step("Create container and put object"):
new_wallet = create_wallet_with_money(neofs_env)
cid = create_container(
new_wallet.path,
rule="REP 1",
shell=neofs_env.shell,
endpoint=neofs_env.sn_rpc,
)
put_object(
new_wallet.path,
generate_file(1000),
cid,
neofs_env.shell,
neofs_env.sn_rpc,
)
57 changes: 2 additions & 55 deletions pytest_tests/tests/payment/test_container_payments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
import time

import allure
import neofs_env.neofs_epoch as neofs_epoch
Expand All @@ -10,67 +9,15 @@
from helpers.file_helper import generate_file
from helpers.neofs_verbs import put_object
from helpers.node_management import restart_storage_nodes
from helpers.wallet_helpers import (
get_neofs_balance,
get_wallet_balance,
wait_for_correct_neofs_balance,
)
from helpers.wallet_helpers import create_wallet_with_money, get_neofs_balance
from neofs_testlib.env.env import NeoFSEnv, NodeWallet
from neofs_testlib.utils import wallet as wallet_utils

logger = logging.getLogger("NeoLogger")


@pytest.fixture
def wallet_with_money(neofs_env_with_mainchain: NeoFSEnv) -> NodeWallet:
neofs_env = neofs_env_with_mainchain

with allure.step("Create wallet for deposit"):
wallet = NodeWallet(
path=neofs_env_with_mainchain._generate_temp_file(
neofs_env._env_dir, prefix="deposit_withdrawal_test_wallet"
),
address="",
password=neofs_env.default_password,
)
wallet_utils.init_wallet(wallet.path, wallet.password)
wallet.address = wallet_utils.get_last_address_from_wallet(wallet.path, wallet.password)
wallet.neo_go_config = neofs_env.generate_neo_go_config(wallet)
wallet.cli_config = neofs_env.generate_cli_config(wallet)

with allure.step("Transfer some money to created wallet"):
neo_go = neofs_env.neo_go()
neo_go.nep17.transfer(
"GAS",
wallet.address,
f"http://{neofs_env.main_chain.rpc_address}",
from_address=neofs_env.inner_ring_nodes[-1].alphabet_wallet.address,
amount=1000,
force=True,
wallet_config=neofs_env.main_chain.neo_go_config,
await_=True,
)
assert get_wallet_balance(neofs_env, neo_go, wallet, wallet.neo_go_config) == 1000.0, (
"Money transfer from alphabet to test wallet didn't succeed"
)

with allure.step("Deposit money to neofs contract"):
neo_go.nep17.transfer(
"GAS",
neofs_env.main_chain.neofs_contract_address,
f"http://{neofs_env.main_chain.rpc_address}",
from_address=wallet.address,
amount=100,
force=True,
wallet_config=wallet.neo_go_config,
await_=True,
)
assert get_wallet_balance(neofs_env, neo_go, wallet, wallet.neo_go_config) <= 900, (
"Wallet balance is not correct after deposit"
)
wait_for_correct_neofs_balance(neofs_env, wallet, wallet.cli_config, lambda balance: balance == 100)

return wallet
return create_wallet_with_money(neofs_env_with_mainchain)


class TestContainerPayments:
Expand Down
2 changes: 1 addition & 1 deletion pytest_tests/tests/payment/test_deposit_withdrawal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_deposit_withdrawal(self, neofs_env_with_mainchain: NeoFSEnv):
"GAS",
wallet.address,
f"http://{neofs_env.main_chain.rpc_address}",
from_address=neofs_env.inner_ring_nodes[-1].alphabet_wallet.address,
from_address=neofs_env.main_chain.wallet.address,
amount=1000,
force=True,
wallet_config=neofs_env.main_chain.neo_go_config,
Expand Down

0 comments on commit aedee27

Please sign in to comment.