From 3ffa4f4534878e1c448812b29e0b6fdfad4e6fd9 Mon Sep 17 00:00:00 2001 From: Elizaveta Chichindaeva Date: Fri, 24 Jun 2022 13:36:02 +0300 Subject: [PATCH] part of [#194] Get ScriptHash with address Signed-off-by: Elizaveta Chichindaeva --- robot/resources/lib/python_keywords/neofs.py | 7 --- .../lib/python_keywords/payment_neogo.py | 46 ++++++++++++------- .../integration/cli/accounting/balance.robot | 2 +- .../integration/payment/withdraw.robot | 11 ++--- .../integration/services/s3_gate_bucket.robot | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/robot/resources/lib/python_keywords/neofs.py b/robot/resources/lib/python_keywords/neofs.py index 6b141a8..4553e99 100644 --- a/robot/resources/lib/python_keywords/neofs.py +++ b/robot/resources/lib/python_keywords/neofs.py @@ -18,13 +18,6 @@ ROBOT_AUTO_KEYWORDS = False NEOFS_CLI_EXEC = os.getenv('NEOFS_CLI_EXEC', 'neofs-cli') -# TODO: move to neofs-keywords -@keyword('Get ScriptHash') -def get_scripthash(wif: str): - acc = wallet.Account.from_wif(wif, '') - return str(acc.script_hash) - - @keyword('Verify Head Tombstone') def verify_head_tombstone(wallet_path: str, cid: str, oid_ts: str, oid: str): header = neofs_verbs.head_object(wallet_path, cid, oid_ts) diff --git a/robot/resources/lib/python_keywords/payment_neogo.py b/robot/resources/lib/python_keywords/payment_neogo.py index 0f91bd0..47f9699 100644 --- a/robot/resources/lib/python_keywords/payment_neogo.py +++ b/robot/resources/lib/python_keywords/payment_neogo.py @@ -8,9 +8,10 @@ from common import (MAINNET_WALLET_PATH, MORPH_ENDPOINT, import rpc_client import contract import converters -import wallet +from wallet import nep17_transfer from wrappers import run_sh_with_passwd_contract from converters import load_wallet +from neo3 import wallet from robot.api.deco import keyword from robot.api import logger @@ -31,7 +32,10 @@ mainnet_rpc_cli = rpc_client.RPCClient(NEO_MAINNET_ENDPOINT) @keyword('Withdraw Mainnet Gas') -def withdraw_mainnet_gas(wlt: str, address: str, scripthash: str, amount: int): +def withdraw_mainnet_gas(wlt: str, amount: int): + address = _address_from_wallet(wlt, EMPTY_PASSWORD) + scripthash = wallet.Account.address_to_script_hash(address) + cmd = ( f"{NEOGO_CLI_EXEC} contract invokefunction -w {wlt} -a {address} " f"-r {NEO_MAINNET_ENDPOINT} {NEOFS_CONTRACT} withdraw {scripthash} " @@ -65,9 +69,9 @@ def transaction_accepted(tx_id: str): if resp is not None: logger.info(f"TX is accepted in block: {resp}") return True - except Exception as e: - logger.info(f"request failed with error: {e}") - raise e + except Exception as out: + logger.info(f"request failed with error: {out}") + raise out return False @@ -93,9 +97,9 @@ def get_balance(wallet_path: str): logger.info(f"Got response \n{resp}") value = int(resp['stack'][0]['value']) return value / (10 ** MORPH_TOKEN_POWER) - except Exception as e: - logger.error(f"failed to get wallet balance: {e}") - raise e + except Exception as out: + logger.error(f"failed to get wallet balance: {out}") + raise out @keyword('Transfer Mainnet Gas') @@ -112,11 +116,9 @@ def transfer_mainnet_gas(wallet_to: str, amount: int, wallet_password: str = EMP Returns: (void) ''' - wlt = load_wallet(wallet_to, wallet_password) - address_to = wlt.accounts[-1].address - logger.info(f"got address to: {address_to}") + address_to = _address_from_wallet(wallet_to, wallet_password) - txid = wallet.nep17_transfer(MAINNET_WALLET_PATH, address_to, amount, NEO_MAINNET_ENDPOINT, + txid = nep17_transfer(MAINNET_WALLET_PATH, address_to, amount, NEO_MAINNET_ENDPOINT, wallet_pass=MAINNET_WALLET_PASS, addr_from=MAINNET_SINGLE_ADDR) if not transaction_accepted(txid): raise RuntimeError(f"TX {txid} hasn't been processed") @@ -131,11 +133,23 @@ def neofs_deposit(wallet_to: str, amount: int, wallet_password: str = EMPTY_PASS deposit_addr = converters.contract_hash_to_address(NEOFS_CONTRACT) logger.info(f"NeoFS contract address: {deposit_addr}") - wlt = load_wallet(wallet_to, wallet_password) - address_to = wlt.accounts[-1].address - logger.info(f"got address to: {address_to}") + address_to = _address_from_wallet(wallet_to, wallet_password) - txid = wallet.nep17_transfer(wallet_to, deposit_addr, amount, NEO_MAINNET_ENDPOINT, + txid = nep17_transfer(wallet_to, deposit_addr, amount, NEO_MAINNET_ENDPOINT, wallet_pass=wallet_password, addr_from=address_to) if not transaction_accepted(txid): raise RuntimeError(f"TX {txid} hasn't been processed") + +def _address_from_wallet(wlt: str, wallet_password: str): + """ + Extracting the address from the given wallet. + Args: + wlt (str): the path to the wallet to extract address from + wallet_password (str): the password for the given wallet + Returns: + (str): the address for the wallet + """ + wallet_loaded = load_wallet(wlt, wallet_password) + address = wallet_loaded.accounts[-1].address + logger.info(f"got address: {address}") + return address diff --git a/robot/testsuites/integration/cli/accounting/balance.robot b/robot/testsuites/integration/cli/accounting/balance.robot index d6119b1..793bf24 100644 --- a/robot/testsuites/integration/cli/accounting/balance.robot +++ b/robot/testsuites/integration/cli/accounting/balance.robot @@ -35,7 +35,7 @@ CLI Accounting Balance Test Should Be Equal As Numbers ${OUTPUT.stdout} ${DEPOSIT_AMOUNT} # Getting balance with wallet and wrong address - ${ANOTHER_WALLET} ${ANOTHER_ADDR} ${ANOTHER_WIF} = Init Wallet With Address ${ASSETS_DIR} + ${_} ${ANOTHER_ADDR} ${_} = Init Wallet With Address ${ASSETS_DIR} ${OUTPUT} = Run Process ${NEOFS_CLI_EXEC} accounting balance -r ${NEOFS_ENDPOINT} --address ${ANOTHER_ADDR} --wallet ${WALLET} --config ${WALLET_CONFIG} ... shell=True Should Be Equal As Strings ${OUTPUT.stderr} --address option must be specified and valid diff --git a/robot/testsuites/integration/payment/withdraw.robot b/robot/testsuites/integration/payment/withdraw.robot index 9fad068..d60adae 100644 --- a/robot/testsuites/integration/payment/withdraw.robot +++ b/robot/testsuites/integration/payment/withdraw.robot @@ -20,8 +20,7 @@ NeoFS Deposit and Withdraw [Setup] Setup - ${WALLET} ${ADDR} ${WIF} = Init Wallet with Address ${ASSETS_DIR} - ${SCRIPT_HASH} = Get ScriptHash ${WIF} + ${WALLET} ${ADDR} ${_} = Init Wallet with Address ${ASSETS_DIR} ########################################################## # Transferring GAS from initial wallet to our test wallet @@ -47,15 +46,15 @@ NeoFS Deposit and Withdraw ########################### # Withdrawing deposit back ########################### - Withdraw Mainnet Gas ${WALLET} ${ADDR} ${SCRIPT_HASH} ${WITHDRAW_AMOUNT} + Withdraw Mainnet Gas ${WALLET} ${WITHDRAW_AMOUNT} Sleep ${NEOFS_CONTRACT_CACHE_TIMEOUT} ${NEOFS_BALANCE} = Get NeoFS Balance ${WALLET} ${EXPECTED_BALANCE} = Evaluate ${DEPOSIT_AMOUNT} - ${WITHDRAW_AMOUNT} Should Be Equal As numbers ${NEOFS_BALANCE} ${EXPECTED_BALANCE} - ${MAINNET_BALANCE_AFTER} = Get Mainnet Balance ${ADDR} - ${MAINNET_BALANCE_DIFF} = Evaluate ${MAINNET_BALANCE_AFTER} - ${MAINNET_BALANCE} - Should Be True ${MAINNET_BALANCE_DIFF} < ${WITHDRAW_AMOUNT} + ${MAINNET_BALANCE_AFTER} = Get Mainnet Balance ${ADDR} + ${MAINNET_BALANCE_DIFF} = Evaluate ${MAINNET_BALANCE_AFTER} - ${MAINNET_BALANCE} + Should Be True ${MAINNET_BALANCE_DIFF} < ${WITHDRAW_AMOUNT} [Teardown] Teardown withdraw diff --git a/robot/testsuites/integration/services/s3_gate_bucket.robot b/robot/testsuites/integration/services/s3_gate_bucket.robot index 030fd6c..04d5f27 100644 --- a/robot/testsuites/integration/services/s3_gate_bucket.robot +++ b/robot/testsuites/integration/services/s3_gate_bucket.robot @@ -24,7 +24,7 @@ Buckets in NeoFS S3 Gateway [Setup] Setup Make Up ${INCLUDE_SVC} - ${WALLET} ${_} ${WIF} = Prepare Wallet And Deposit + ${WALLET} ${_} ${_} = Prepare Wallet And Deposit ${FILE_S3} ${_} = Generate file ${COMPLEX_OBJ_SIZE} ${_} ${S3_OBJECT_KEY} = Split Path ${FILE_S3}