From e922b150821e4bbdefec2640eddc712574a10648 Mon Sep 17 00:00:00 2001 From: anastasia prasolova Date: Mon, 1 Feb 2021 19:43:35 +0300 Subject: [PATCH] using neo-go directly instead of docker-exec in container --- README.md | 17 +++++---- robot/resources/lib/payment_neogo.py | 57 ++++++++++------------------ wallets/wallet.json | 30 +++++++++++++++ 3 files changed, 60 insertions(+), 44 deletions(-) create mode 100644 wallets/wallet.json diff --git a/README.md b/README.md index 9542d259..359a14f5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,14 @@ - `sudo cp bin/cdn-authmate /usr/local/bin/cdn-authmate`, add alias path to bin/cdn-authmate or run `export CDNAUTH_EXEC=` -3. Install Testcases dependencies +3. Install neo-go + - `git clone git@github.com:nspcc-dev/neo-go.git` + - `cd neo-go` + - `make` + - `sudo cp bin/neo-go /usr/local/bin/neo-go`, add alias path to bin/neo-go + or run `export NEOGO_CLI_EXEC=` + +4. Install Testcases dependencies - `pip3 install -r requirements.txt` (replace pip3 with the appropriate python package manager on the system). @@ -68,13 +75,7 @@ export ROBOT_PROFILE=selectel_smoke Dev-env is not needed. But you need to install neo-go. -2. Install neo-go - - `git clone git@github.com:nspcc-dev/neo-go.git` - - `cd neo-go` - - `make` - - `sudo cp bin/neo-go /usr/local/bin/neo-go` or add alias path to bin/neo-go - -3. To run smoke test: `robot --outputdir artifacts/ robot/testsuites/smoke/selectelcdn_smoke.robot` +2. To run smoke test: `robot --outputdir artifacts/ robot/testsuites/smoke/selectelcdn_smoke.robot` ## Generation of documentation diff --git a/robot/resources/lib/payment_neogo.py b/robot/resources/lib/payment_neogo.py index 2fe91da5..007c56a7 100644 --- a/robot/resources/lib/payment_neogo.py +++ b/robot/resources/lib/payment_neogo.py @@ -8,6 +8,7 @@ import logging import requests import json import os +import tarfile from robot.api.deco import keyword from robot.api import logger @@ -18,32 +19,28 @@ ROBOT_AUTO_KEYWORDS = False if os.getenv('ROBOT_PROFILE') == 'selectel_smoke': - from selectelcdn_smoke_vars import (NEOGO_CLI_PREFIX, NEO_MAINNET_ENDPOINT, + from selectelcdn_smoke_vars import (NEO_MAINNET_ENDPOINT, NEOFS_NEO_API_ENDPOINT, NEOFS_ENDPOINT, GAS_HASH, NEOFS_CONTRACT) else: - from neofs_int_vars import (NEOGO_CLI_PREFIX, NEO_MAINNET_ENDPOINT, + from neofs_int_vars import (NEO_MAINNET_ENDPOINT, NEOFS_NEO_API_ENDPOINT, NEOFS_ENDPOINT, GAS_HASH, NEOFS_CONTRACT) # path to neofs-cli executable NEOFS_CLI_EXEC = os.getenv('NEOFS_CLI_EXEC', 'neofs-cli') +NEOGO_CLI_EXEC = os.getenv('NEOGO_CLI_EXEC', 'neo-go') @keyword('Init wallet') def init_wallet(): - - filename = "wallets/" + str(uuid.uuid4()) + ".json" - cmd = ( f"{NEOGO_CLI_PREFIX} wallet init -w {filename}" ) - - logger.info(f"Executing shell command: {cmd}") - out = _run_sh(cmd) - logger.info(f"Command completed with output: {out}") + filename = os.getcwd() + '/' + str(uuid.uuid4()) + ".json" + cmd = f"{NEOGO_CLI_EXEC} wallet init -w {filename}" + logger.info(f"Executing command: {cmd}") + stdout = _run_sh(cmd) + logger.info(f"wallet init succeeded with output: {stdout}") return filename - - @keyword('Generate wallet from WIF') def generate_wallet_from_wif(wallet: str, wif: str): - cmd = ( f"{NEOGO_CLI_PREFIX} wallet import --wallet {wallet} --wif {wif}" ) - + cmd = f"{NEOGO_CLI_EXEC} wallet import --wallet {wallet} --wif {wif}" logger.info(f"Executing command: {cmd}") p = pexpect.spawn(cmd) p.expect(".*") @@ -55,11 +52,9 @@ def generate_wallet_from_wif(wallet: str, wif: str): logger.info(f"Command completed with output: {out}") - @keyword('Generate wallet') def generate_wallet(wallet: str): - cmd = ( f"{NEOGO_CLI_PREFIX} wallet create -w {wallet}" ) - + cmd = f"{NEOGO_CLI_EXEC} wallet create -w {wallet}" logger.info(f"Executing command: {cmd}") p = pexpect.spawn(cmd) p.expect(".*") @@ -73,35 +68,25 @@ def generate_wallet(wallet: str): @keyword('Dump Address') def dump_address(wallet: str): - address = "" - cmd = ( f"{NEOGO_CLI_PREFIX} wallet dump -w {wallet}" ) - - logger.info(f"Executing command: {cmd}") - out = _run_sh(cmd) - logger.info(f"Command completed with output: {out}") - - m = re.search(r'"address": "(\w+)"', out) - if m.start() != m.end(): - address = m.group(1) - else: - raise Exception("Can not get address.") - - return address + with open(wallet) as json_file: + data = json.load(json_file) + if len(data['accounts']) != 0: + return data['accounts'][0]['address'] + else: + raise Exception("Can not get address.") @keyword('Dump PrivKey') def dump_privkey(wallet: str, address: str): - cmd = ( f"{NEOGO_CLI_PREFIX} wallet export -w {wallet} --decrypt {address}" ) - + cmd = f"{NEOGO_CLI_EXEC} wallet export -w {wallet} --decrypt {address}" logger.info(f"Executing command: {cmd}") out = _run_sh_with_passwd('', cmd) logger.info(f"Command completed with output: {out}") - return out @keyword('Transfer Mainnet Gas') def transfer_mainnet_gas(wallet: str, address: str, address_to: str, amount: int, wallet_pass:str=''): cmd = ( - f"{NEOGO_CLI_PREFIX} wallet nep17 transfer -w {wallet} " + f"{NEOGO_CLI_EXEC} wallet nep17 transfer -w {wallet} " f"-r {NEO_MAINNET_ENDPOINT} --from {address} --to {address_to} " f"--token GAS --amount {amount}" ) @@ -118,7 +103,7 @@ def transfer_mainnet_gas(wallet: str, address: str, address_to: str, amount: int @keyword('Withdraw Mainnet Gas') def withdraw_mainnet_gas(wallet: str, address: str, scripthash: str, amount: int): cmd = ( - f"{NEOGO_CLI_PREFIX} contract invokefunction -w {wallet} -a {address} " + f"{NEOGO_CLI_EXEC} contract invokefunction -w {wallet} -a {address} " f"-r {NEO_MAINNET_ENDPOINT} {NEOFS_CONTRACT} withdraw {scripthash} " f"int:{amount} -- {scripthash}" ) @@ -163,7 +148,7 @@ def expected_mainnet_balance(address: str, expected: float): @keyword('NeoFS Deposit') def neofs_deposit(wallet: str, address: str, scripthash: str, amount: int, wallet_pass:str=''): - cmd = ( f"{NEOGO_CLI_PREFIX} contract invokefunction -w {wallet} -a {address} " + cmd = ( f"{NEOGO_CLI_EXEC} contract invokefunction -w {wallet} -a {address} " f"-r {NEO_MAINNET_ENDPOINT} {NEOFS_CONTRACT} " f"deposit {scripthash} int:{amount} bytes: -- {scripthash}") diff --git a/wallets/wallet.json b/wallets/wallet.json new file mode 100644 index 00000000..e007d956 --- /dev/null +++ b/wallets/wallet.json @@ -0,0 +1,30 @@ +{ + "version": "3.0", + "accounts": [ + { + "address": "NTrezR3C4X8aMLVg7vozt5wguyNfFhwuFx", + "key": "6PYWrvsPU47vJTeoLUht12pHUQunPBgaR7JEbx7MpuAuNP8CHHyH9hbqqk", + "label": "", + "contract": { + "script": "DCEDGmxvu98CyjUXRfqGubpalFLXhaxPf8K3VIyipGxPz0oLQZVEDXg=", + "parameters": [ + { + "name": "parameter0", + "type": "Signature" + } + ], + "deployed": false + }, + "lock": false, + "isdefault": false + } + ], + "scrypt": { + "n": 16384, + "r": 8, + "p": 8 + }, + "extra": { + "Tokens": null + } +}