part of [#194] Get ScriptHash with address

Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
This commit is contained in:
Elizaveta Chichindaeva 2022-06-24 13:36:02 +03:00
parent c8a5a63791
commit 3ffa4f4534
5 changed files with 37 additions and 31 deletions

View file

@ -18,13 +18,6 @@ ROBOT_AUTO_KEYWORDS = False
NEOFS_CLI_EXEC = os.getenv('NEOFS_CLI_EXEC', 'neofs-cli') 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') @keyword('Verify Head Tombstone')
def verify_head_tombstone(wallet_path: str, cid: str, oid_ts: str, oid: str): def verify_head_tombstone(wallet_path: str, cid: str, oid_ts: str, oid: str):
header = neofs_verbs.head_object(wallet_path, cid, oid_ts) header = neofs_verbs.head_object(wallet_path, cid, oid_ts)

View file

@ -8,9 +8,10 @@ from common import (MAINNET_WALLET_PATH, MORPH_ENDPOINT,
import rpc_client import rpc_client
import contract import contract
import converters import converters
import wallet from wallet import nep17_transfer
from wrappers import run_sh_with_passwd_contract from wrappers import run_sh_with_passwd_contract
from converters import load_wallet from converters import load_wallet
from neo3 import wallet
from robot.api.deco import keyword from robot.api.deco import keyword
from robot.api import logger from robot.api import logger
@ -31,7 +32,10 @@ mainnet_rpc_cli = rpc_client.RPCClient(NEO_MAINNET_ENDPOINT)
@keyword('Withdraw Mainnet Gas') @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 = ( cmd = (
f"{NEOGO_CLI_EXEC} contract invokefunction -w {wlt} -a {address} " f"{NEOGO_CLI_EXEC} contract invokefunction -w {wlt} -a {address} "
f"-r {NEO_MAINNET_ENDPOINT} {NEOFS_CONTRACT} withdraw {scripthash} " f"-r {NEO_MAINNET_ENDPOINT} {NEOFS_CONTRACT} withdraw {scripthash} "
@ -65,9 +69,9 @@ def transaction_accepted(tx_id: str):
if resp is not None: if resp is not None:
logger.info(f"TX is accepted in block: {resp}") logger.info(f"TX is accepted in block: {resp}")
return True return True
except Exception as e: except Exception as out:
logger.info(f"request failed with error: {e}") logger.info(f"request failed with error: {out}")
raise e raise out
return False return False
@ -93,9 +97,9 @@ def get_balance(wallet_path: str):
logger.info(f"Got response \n{resp}") logger.info(f"Got response \n{resp}")
value = int(resp['stack'][0]['value']) value = int(resp['stack'][0]['value'])
return value / (10 ** MORPH_TOKEN_POWER) return value / (10 ** MORPH_TOKEN_POWER)
except Exception as e: except Exception as out:
logger.error(f"failed to get wallet balance: {e}") logger.error(f"failed to get wallet balance: {out}")
raise e raise out
@keyword('Transfer Mainnet Gas') @keyword('Transfer Mainnet Gas')
@ -112,11 +116,9 @@ def transfer_mainnet_gas(wallet_to: str, amount: int, wallet_password: str = EMP
Returns: Returns:
(void) (void)
''' '''
wlt = load_wallet(wallet_to, wallet_password) address_to = _address_from_wallet(wallet_to, wallet_password)
address_to = wlt.accounts[-1].address
logger.info(f"got address to: {address_to}")
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) wallet_pass=MAINNET_WALLET_PASS, addr_from=MAINNET_SINGLE_ADDR)
if not transaction_accepted(txid): if not transaction_accepted(txid):
raise RuntimeError(f"TX {txid} hasn't been processed") 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) deposit_addr = converters.contract_hash_to_address(NEOFS_CONTRACT)
logger.info(f"NeoFS contract address: {deposit_addr}") logger.info(f"NeoFS contract address: {deposit_addr}")
wlt = load_wallet(wallet_to, wallet_password) address_to = _address_from_wallet(wallet_to, wallet_password)
address_to = wlt.accounts[-1].address
logger.info(f"got address to: {address_to}")
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) wallet_pass=wallet_password, addr_from=address_to)
if not transaction_accepted(txid): if not transaction_accepted(txid):
raise RuntimeError(f"TX {txid} hasn't been processed") 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

View file

@ -35,7 +35,7 @@ CLI Accounting Balance Test
Should Be Equal As Numbers ${OUTPUT.stdout} ${DEPOSIT_AMOUNT} Should Be Equal As Numbers ${OUTPUT.stdout} ${DEPOSIT_AMOUNT}
# Getting balance with wallet and wrong address # 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} ${OUTPUT} = Run Process ${NEOFS_CLI_EXEC} accounting balance -r ${NEOFS_ENDPOINT} --address ${ANOTHER_ADDR} --wallet ${WALLET} --config ${WALLET_CONFIG}
... shell=True ... shell=True
Should Be Equal As Strings ${OUTPUT.stderr} --address option must be specified and valid Should Be Equal As Strings ${OUTPUT.stderr} --address option must be specified and valid

View file

@ -20,8 +20,7 @@ NeoFS Deposit and Withdraw
[Setup] Setup [Setup] Setup
${WALLET} ${ADDR} ${WIF} = Init Wallet with Address ${ASSETS_DIR} ${WALLET} ${ADDR} ${_} = Init Wallet with Address ${ASSETS_DIR}
${SCRIPT_HASH} = Get ScriptHash ${WIF}
########################################################## ##########################################################
# Transferring GAS from initial wallet to our test wallet # Transferring GAS from initial wallet to our test wallet
@ -47,15 +46,15 @@ NeoFS Deposit and Withdraw
########################### ###########################
# Withdrawing deposit back # Withdrawing deposit back
########################### ###########################
Withdraw Mainnet Gas ${WALLET} ${ADDR} ${SCRIPT_HASH} ${WITHDRAW_AMOUNT} Withdraw Mainnet Gas ${WALLET} ${WITHDRAW_AMOUNT}
Sleep ${NEOFS_CONTRACT_CACHE_TIMEOUT} Sleep ${NEOFS_CONTRACT_CACHE_TIMEOUT}
${NEOFS_BALANCE} = Get NeoFS Balance ${WALLET} ${NEOFS_BALANCE} = Get NeoFS Balance ${WALLET}
${EXPECTED_BALANCE} = Evaluate ${DEPOSIT_AMOUNT} - ${WITHDRAW_AMOUNT} ${EXPECTED_BALANCE} = Evaluate ${DEPOSIT_AMOUNT} - ${WITHDRAW_AMOUNT}
Should Be Equal As numbers ${NEOFS_BALANCE} ${EXPECTED_BALANCE} Should Be Equal As numbers ${NEOFS_BALANCE} ${EXPECTED_BALANCE}
${MAINNET_BALANCE_AFTER} = Get Mainnet Balance ${ADDR} ${MAINNET_BALANCE_AFTER} = Get Mainnet Balance ${ADDR}
${MAINNET_BALANCE_DIFF} = Evaluate ${MAINNET_BALANCE_AFTER} - ${MAINNET_BALANCE} ${MAINNET_BALANCE_DIFF} = Evaluate ${MAINNET_BALANCE_AFTER} - ${MAINNET_BALANCE}
Should Be True ${MAINNET_BALANCE_DIFF} < ${WITHDRAW_AMOUNT} Should Be True ${MAINNET_BALANCE_DIFF} < ${WITHDRAW_AMOUNT}
[Teardown] Teardown withdraw [Teardown] Teardown withdraw

View file

@ -24,7 +24,7 @@ Buckets in NeoFS S3 Gateway
[Setup] Setup [Setup] Setup
Make Up ${INCLUDE_SVC} Make Up ${INCLUDE_SVC}
${WALLET} ${_} ${WIF} = Prepare Wallet And Deposit ${WALLET} ${_} ${_} = Prepare Wallet And Deposit
${FILE_S3} ${_} = Generate file ${COMPLEX_OBJ_SIZE} ${FILE_S3} ${_} = Generate file ${COMPLEX_OBJ_SIZE}
${_} ${S3_OBJECT_KEY} = Split Path ${FILE_S3} ${_} ${S3_OBJECT_KEY} = Split Path ${FILE_S3}