From 19f9d97328a851e5b1a6a4a8c4a097325a651715 Mon Sep 17 00:00:00 2001 From: anastasia prasolova Date: Thu, 9 Sep 2021 16:36:34 +0300 Subject: [PATCH] (#102): neofs-cli accounting balance test Signed-off-by: anastasia prasolova --- robot/resources/lib/cli_keywords.py | 23 ++++++ robot/resources/lib/payment_operations.robot | 18 +++++ robot/resources/lib/utility_keywords.py | 9 +++ .../integration/cli/accounting/balance.robot | 72 +++++++++++++++++++ .../netmap}/networkinfo_rpc_method.robot | 16 ++--- robot/variables/common.py | 8 +-- venv/localtest/environment.sh | 2 + 7 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 robot/resources/lib/cli_keywords.py create mode 100644 robot/testsuites/integration/cli/accounting/balance.robot rename robot/testsuites/integration/{network => cli/netmap}/networkinfo_rpc_method.robot (94%) diff --git a/robot/resources/lib/cli_keywords.py b/robot/resources/lib/cli_keywords.py new file mode 100644 index 00000000..d7fb5987 --- /dev/null +++ b/robot/resources/lib/cli_keywords.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3.8 + +import pexpect + +from robot.api.deco import keyword + +ROBOT_AUTO_KEYWORDS = False + +@keyword('Run Process And Enter Empty Password') +def run_proccess_and_interact(cmd: str) -> str: + p = pexpect.spawn(cmd) + p.expect("[pP]assword") + # enter empty password + p.sendline('\r') + p.wait() + # throw a string with password prompt + first = p.readline() + # take all output + child_output = p.readline() + p.close() + if p.exitstatus != 0: + raise Exception(f"{first}\n{child_output}") + return child_output diff --git a/robot/resources/lib/payment_operations.robot b/robot/resources/lib/payment_operations.robot index 752c0da9..0f1d77b7 100644 --- a/robot/resources/lib/payment_operations.robot +++ b/robot/resources/lib/payment_operations.robot @@ -3,6 +3,7 @@ Variables ../../variables/common.py Library wallet_keywords.py Library rpc_call_keywords.py +Library payment_neogo.py *** Variables *** ${TRANSFER_AMOUNT} = ${30} @@ -43,3 +44,20 @@ Payment Operations ${NEOFS_BALANCE} = Get NeoFS Balance ${WIF} Should Be Equal As Numbers ${NEOFS_BALANCE} ${DEPOSIT_AMOUNT} + +Prepare Wallet And Deposit + [Arguments] ${DEPOSIT} + + ${WALLET} ${ADDR} ${WIF} = Init Wallet with Address ${ASSETS_DIR} + ${TX} = Transfer Mainnet Gas ${MAINNET_WALLET_WIF} ${ADDR} ${DEPOSIT+1} + Wait Until Keyword Succeeds ${MAINNET_TIMEOUT} ${MAINNET_BLOCK_TIME} + ... Transaction accepted in block ${TX} + + ${TX_DEPOSIT} = NeoFS Deposit ${WIF} ${DEPOSIT} + Wait Until Keyword Succeeds ${MAINNET_TIMEOUT} ${MAINNET_BLOCK_TIME} + ... Transaction accepted in block ${TX_DEPOSIT} + # Now we have TX in main chain, but deposit might not propagate into the side chain yet. + # For certainty, sleeping during one morph block. + Sleep ${MORPH_BLOCK_TIME} + + [Return] ${WALLET} ${ADDR} ${WIF} diff --git a/robot/resources/lib/utility_keywords.py b/robot/resources/lib/utility_keywords.py index 865fd8f8..b311ef36 100644 --- a/robot/resources/lib/utility_keywords.py +++ b/robot/resources/lib/utility_keywords.py @@ -5,6 +5,7 @@ import os import tarfile import uuid +from neo3 import wallet from robot.api.deco import keyword from robot.api import logger from robot.libraries.BuiltIn import BuiltIn @@ -42,3 +43,11 @@ def get_container_logs(testcase_name: str) -> None: tar.add(file_name) os.remove(file_name) tar.close() + +@keyword('WIF to Binary') +def wif_to_binary(wif: str) -> str: + priv_key = wallet.Account.private_key_from_wif(wif) + path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}" + with open(path, "wb") as f: + f.write(priv_key) + return path diff --git a/robot/testsuites/integration/cli/accounting/balance.robot b/robot/testsuites/integration/cli/accounting/balance.robot new file mode 100644 index 00000000..f62dc54b --- /dev/null +++ b/robot/testsuites/integration/cli/accounting/balance.robot @@ -0,0 +1,72 @@ +*** Settings *** +Variables ../../../../variables/common.py + +Library Collections +Library Process +Library String +Library contract_keywords.py +Library cli_keywords.py +Library utility_keywords.py + +Resource setup_teardown.robot +Resource payment_operations.robot + +*** Variables *** +${DEPOSIT_AMOUNT} = ${10} + +*** Test cases *** +CLI Accounting Balance Test + [Documentation] neofs-cli accounting balance test + [Tags] NeoFSCLI Accounting + [Timeout] 10 min + + [Setup] Setup + + ${WALLET} ${ADDR} ${WIF} = Prepare Wallet And Deposit ${DEPOSIT_AMOUNT} + + # Getting balance with WIF + ${OUTPUT} = Run Process neofs-cli accounting balance -r ${NEOFS_ENDPOINT} --wif ${WIF} + ... shell=True + Should Be Equal As Numbers ${OUTPUT.stdout} ${DEPOSIT_AMOUNT} + + # Getting balance with wallet and address + ${OUTPUT} = Run Process And Enter Empty Password + ... neofs-cli accounting balance -r ${NEOFS_ENDPOINT} --address ${ADDR} --wallet ${WALLET} + Should Be Equal As Numbers ${OUTPUT} ${DEPOSIT_AMOUNT} + + # Getting balance with wallet only + ${OUTPUT} = Run Process And Enter Empty Password + ... neofs-cli accounting balance -r ${NEOFS_ENDPOINT} --wallet ${WALLET} + Should Be Equal As Numbers ${OUTPUT} ${DEPOSIT_AMOUNT} + + # Getting balance with wallet and wrong address + ${ANOTHER_WALLET} ${ANOTHER_ADDR} ${ANOTHER_WIF} = Init Wallet With Address ${ASSETS_DIR} + ${OUTPUT} = Run Process neofs-cli accounting balance -r ${NEOFS_ENDPOINT} --address ${ANOTHER_ADDR} --wallet ${WALLET} + ... shell=True + Should Be Equal As Strings ${OUTPUT.stderr} --address option must be specified and valid + Should Be Equal As Numbers ${OUTPUT.rc} 1 + + # Getting balance with control API + ${CONFIG_PATH} = Write Control API Config ${NEOFS_ENDPOINT} ${WIF} + ${OUTPUT} = Run Process neofs-cli accounting balance --config ${CONFIG_PATH} + ... shell=True + Should Be Equal As Numbers ${OUTPUT.stdout} ${DEPOSIT_AMOUNT} + + # Getting balance with binary key + ${KEY_PATH} = WIF To Binary ${WIF} + ${OUTPUT} = Run Process neofs-cli accounting balance -r ${NEOFS_ENDPOINT} --binary-key ${KEY_PATH} + ... shell=True + Should Be Equal As Numbers ${OUTPUT.stdout} ${DEPOSIT_AMOUNT} + + [Teardown] Teardown cli_accounting_balance + +*** Keywords *** + +Write Control API Config + [Documentation] Write YAML config for requesting NeoFS Control API via CLI + [Arguments] ${ENDPOINT} ${WIF} + + Set Local Variable ${PATH} ${ASSETS_DIR}/config.yaml + Create File ${PATH} rpc: ${ENDPOINT}\nwif: ${WIF} + + [Return] ${PATH} diff --git a/robot/testsuites/integration/network/networkinfo_rpc_method.robot b/robot/testsuites/integration/cli/netmap/networkinfo_rpc_method.robot similarity index 94% rename from robot/testsuites/integration/network/networkinfo_rpc_method.robot rename to robot/testsuites/integration/cli/netmap/networkinfo_rpc_method.robot index 5c119212..c87b2f1b 100644 --- a/robot/testsuites/integration/network/networkinfo_rpc_method.robot +++ b/robot/testsuites/integration/cli/netmap/networkinfo_rpc_method.robot @@ -15,7 +15,7 @@ ${SN_02_ADDR} = s02.neofs.devenv:8080 *** Test cases *** NetworkInfo RPC Method [Documentation] Testcase to check NetworkInfo RPC method. - [Tags] RPC NeoFS NeoCLI NetworkInfo + [Tags] RPC NeoFS NeoFSCLI NetworkInfo [Timeout] 10 min [Setup] Setup @@ -32,10 +32,10 @@ NetworkInfo RPC Method ############################################# # Checking if morph magic number is relevant ############################################# - + ${NETWORK_MAGIC_S01} = Parse Magic ${RESULT1_S01.stdout} Should Be Equal ${NETWORK_MAGIC_S01} ${MORPH_MAGIC} - + ${NETWORK_MAGIC_S02} = Parse Magic ${RESULT1_S02.stdout} Should Be Equal ${NETWORK_MAGIC_S02} ${MORPH_MAGIC} @@ -50,7 +50,7 @@ NetworkInfo RPC Method ######################################## # Ticking epoch and getting new netinfo ######################################## - + Tick Epoch ${RESULT2_S01} Run Process neofs-cli netmap netinfo -r ${SN_01_ADDR} --wif ${MAINNET_WALLET_WIF} shell=True @@ -69,13 +69,13 @@ NetworkInfo RPC Method ${NEW_EPOCH} = Evaluate ${EPOCH1_S01}+${1} Should Be Equal ${EPOCH2_S01} ${NEW_EPOCH} - - [Teardown] Teardown network_rpc_method + + [Teardown] Teardown network_rpc_method *** Keywords *** Parse Magic - [Arguments] ${RESULT_STDOUT} + [Arguments] ${RESULT_STDOUT} @{MAGIC} = Split String ${RESULT_STDOUT} ${\n} ${NETWORK_MAGIC} = Get From List ${MAGIC} ${1} @{MAGIC_INFO} = Split String ${NETWORK_MAGIC} ${SPACE} @@ -83,7 +83,7 @@ Parse Magic [Return] ${MAGIC_VALUE} Parse Epoch - [Arguments] ${RESULT_STDOUT} + [Arguments] ${RESULT_STDOUT} @{EPOCH} = Split String ${RESULT_STDOUT} ${\n} ${NETWORK_EPOCH} = Get From List ${EPOCH} ${0} @{EPOCH_INFO} = Split String ${NETWORK_EPOCH} ${SPACE} diff --git a/robot/variables/common.py b/robot/variables/common.py index 9f7f11c5..a2be183c 100644 --- a/robot/variables/common.py +++ b/robot/variables/common.py @@ -6,10 +6,6 @@ RESOURCES="%s/resources/lib" % ROOT CERT="%s/../../ca" % ROOT KEYWORDS="%s/../../../neofs-keywords/robot/" % ROOT -# path from repo root is required for object put and get -# in case when test is run from root in docker -ABSOLUTE_FILE_PATH="/robot/testsuites/integration" - # Common NeoFS variables can be declared from neofs-dev-env env variables. # High priority is accepted for those envs. @@ -36,7 +32,7 @@ NEOFS_NEO_API_ENDPOINT = os.getenv("NEOFS_NEO_API_ENDPOINT", 'http://morph_chain HTTP_GATE = os.getenv("HTTP_GATE", 'http://http.neofs.devenv') S3_GATE = os.getenv("S3_GATE", 'https://s3.neofs.devenv:8080') NEOFS_NETMAP = os.getenv("NEOFS_NETMAP", ['s01.neofs.devenv:8080', 's02.neofs.devenv:8080','s03.neofs.devenv:8080','s04.neofs.devenv:8080']) -GAS_HASH = os.getenv("GAS_HASH", '0xd2a4cff31913016155e38e474a2c06d08be276cf') +GAS_HASH = '0xd2a4cff31913016155e38e474a2c06d08be276cf' NEOFS_CONTRACT = (os.getenv("NEOFS_CONTRACT") if os.getenv("NEOFS_CONTRACT") else os.getenv("NEOFS_IR_CONTRACTS_NEOFS", '008b43d3de8741b896015f79ac0fbfa4055b4574')) @@ -46,4 +42,4 @@ COMMON_PLACEMENT_RULE = "REP 2 IN X CBF 1 SELECT 4 FROM * AS X" ASSETS_DIR = os.getenv("ASSETS_DIR", "TemporaryDir/") MORPH_MAGIC = os.environ["MORPH_MAGIC"] -GATE_PUB_KEY = '0313b1ac3a8076e155a7e797b24f0b650cccad5941ea59d7cfd51a024a8b2a06bf' \ No newline at end of file +GATE_PUB_KEY = '0313b1ac3a8076e155a7e797b24f0b650cccad5941ea59d7cfd51a024a8b2a06bf' diff --git a/venv/localtest/environment.sh b/venv/localtest/environment.sh index 494b1bb7..2832c05c 100644 --- a/venv/localtest/environment.sh +++ b/venv/localtest/environment.sh @@ -3,3 +3,5 @@ export NEOFS_MORPH_DISABLE_CACHE=true pushd ../neofs-dev-env export `make env` popd + +export PYTHONPATH=${PYTHONPATH}:${VIRTUAL_ENV}/neofs-keywords/lib:${VIRTUAL_ENV}/neofs-keywords/robot:~/neofs-testcases/robot/resources/lib