This commit is contained in:
anatoly@nspcc.ru 2020-11-28 06:16:10 +03:00
parent 610d444f70
commit b7a30c763d
14 changed files with 262 additions and 945 deletions

View file

@ -1,21 +0,0 @@
#!/usr/bin/python3
"""
A file with specific assertions that Robot Framework
doesn't have in its builtins.
"""
from robot.api.deco import keyword
from robot.utils.asserts import assert_equal
@keyword('Should Be Equal as Binaries')
def sbe_as_binaries(fst: str, snd: str):
"""
Assertion to compare binary contents of
two files. Parameters:
- `fst`: path to first file
- `snd`: path to second file
"""
fst_fd, snd_fd = open(fst, 'rb'), open(snd, 'rb')
fst_bytes, snd_bytes = fst_fd.read(), snd_fd.read()
assert_equal(fst_bytes, snd_bytes, msg='Given files are not equal as binaries')

View file

@ -1,25 +0,0 @@
{
"body": {
"eaclTable": {
"containerID": {
"value": "5nWjhWaME7krQsEKwwczsxAatT4SNqB1bnxKR36Szwtb"
},
"records": [
{
"operation": "GET",
"action": "ALLOW",
"targets": [
{
"role": "OTHERS"
}
]
}
]
},
"lifetime": {
"exp": "100500",
"nbf": "1",
"iat": "0"
}
}
}

View file

@ -1,30 +0,0 @@
#!/usr/bin/python3
import subprocess
import re
import os
import shutil
import json
import binascii
import time
from robot.api.deco import keyword
from robot.api import logger
import robot.errors
import requests
import uuid
from robot.libraries.BuiltIn import BuiltIn
ROBOT_AUTO_KEYWORDS = False
@keyword('Prepare Environment')
def prepare_environment():
return
@keyword('Cleanup Environment')
def cleanup_environment():
return

View file

@ -1,62 +0,0 @@
#!/usr/bin/python3
import subprocess
import re
import json
import binascii
from robot.api.deco import keyword
from robot.api import logger
import robot.errors
import requests
from robot.libraries.BuiltIn import BuiltIn
from neocore.KeyPair import KeyPair
from Crypto import Random
ROBOT_AUTO_KEYWORDS = False
NEOFS_NEO_API_ENDPOINT = "main_chain.neofs.devenv:30333"
@keyword('Generate Neo private key')
def generate_neo_private_key():
"""
This function generates new random Neo private key.
Parameters: None
:rtype: 'bytes' object
"""
private_key = Random.get_random_bytes(32)
logger.info("Generated private key: %s" % binascii.hexlify(private_key))
return private_key
@keyword('Get Neo public key')
def get_neo_public_key(private_key: bytes):
"""
This function return neo public key.
Parameters:
:param private_key: neo private key
:rtype: string
"""
keypair_gen = KeyPair(bytes(private_key))
pubkey = keypair_gen.PublicKey.encode_point(True).decode("utf-8")
logger.info("Generated public key: %s" % pubkey)
return pubkey
@keyword('Get Neo address')
def get_neo_address(private_key: bytes):
"""
This function return neo address.
Parameters:
:param private_key: neo private key
:rtype: string
"""
keypair_gen = KeyPair(private_key)
address = keypair_gen.GetAddress()
wif = keypair_gen.Export()
logger.info("Generated Neo address: %s" % address)
logger.info("Generated WIF: %s" % wif)
return address

View file

@ -8,7 +8,7 @@ import uuid
import hashlib
from robot.api.deco import keyword
from robot.api import logger
import json
ROBOT_AUTO_KEYWORDS = False

View file

@ -1,83 +0,0 @@
#!/usr/bin/python3
import subprocess
import re
from robot.api.deco import keyword
from robot.api import logger
import logging
import robot.errors
import requests
from robot.libraries.BuiltIn import BuiltIn
from neocore.KeyPair import KeyPair
from Crypto import Random
ROBOT_AUTO_KEYWORDS = False
@keyword('Request NeoFS Deposit')
def request_neofs_deposit(public_key: str):
"""
This function requests Deposit to the selected public key.
:param public_key: neo public key
"""
response = requests.get('https://fs.localtest.nspcc.ru/api/deposit/'+str(public_key), verify='ca/nspcc-ca.pem')
if response.status_code != 200:
BuiltIn().fatal_error('Can not run Deposit to {} with error: {}'.format(public_key, response.text))
else:
logger.info("Deposit has been completed for '%s'; tx: '%s'" % (public_key, response.text) )
return response.text
@keyword('Get Balance')
def get_balance(public_key: str):
"""
This function returns NeoFS balance for selected public key.
:param public_key: neo public key
"""
balance = _get_balance_request(public_key)
return balance
@keyword('Expected Balance')
def expected_balance(public_key: str, init_amount: float, deposit_size: float):
"""
This function returns NeoFS balance for selected public key.
:param public_key: neo public key
:param init_amount: initial number of tokens in the account
:param deposit_size: expected amount of the balance increasing
"""
balance = _get_balance_request(public_key)
deposit_change = round((float(balance) - init_amount),8)
if deposit_change != deposit_size:
raise Exception('Expected deposit increase: {}. This does not correspond to the actual change in account: {}'.format(deposit_size, deposit_change))
logger.info('Expected deposit increase: {}. This correspond to the actual change in account: {}'.format(deposit_size, deposit_change))
return deposit_change
def _get_balance_request(public_key: str):
'''
Internal method.
'''
response = requests.get('https://fs.localtest.nspcc.ru/api/balance/neofs/'+str(public_key)+'/', verify='ca/nspcc-ca.pem')
if response.status_code != 200:
raise Exception('Can not get balance for {} with error: {}'.format(public_key, response.text))
m = re.match(r"\"+([\d.\.?\d*]+)", response.text )
if m is None:
BuiltIn().fatal_error('Can not parse balance: "%s"' % response.text)
balance = m.group(1)
logger.info("Balance for '%s' is '%s'" % (public_key, balance) )
return balance

View file

@ -16,8 +16,6 @@ import json
from robot.libraries.BuiltIn import BuiltIn
from neocore.KeyPair import KeyPair
from Crypto import Random
ROBOT_AUTO_KEYWORDS = False
@ -54,7 +52,6 @@ def generate_wallet(wallet: str):
@keyword('Dump Address')
def dump_address(wallet: str):
#"address": "Ngde6LSaBZ58p72trTNkgqEZmX8dTWBgHo",
address = ""
cmd = ( f"{NEOGO_CLI_PREFIX} wallet dump -w {wallet}" )
@ -82,8 +79,6 @@ def dump_privkey(wallet: str, address: str):
@keyword('Transfer Mainnet Gas')
# docker cp wallets/wallet.json main_chain:/wallets/
def transfer_mainnet_gas(wallet: str, address: str, address_to: str, amount: int):
cmd = ( f"{NEOGO_CLI_PREFIX} wallet nep5 transfer -w {wallet} -r http://main_chain.neofs.devenv:30333 --from {address} "
f"--to {address_to} --token gas --amount {amount}" )
@ -98,8 +93,6 @@ def transfer_mainnet_gas(wallet: str, address: str, address_to: str, amount: int
return out
@keyword('Withdraw Mainnet Gas')
# docker cp wallets/wallet.json main_chain:/wallets/
def withdraw_mainnet_gas(wallet: str, address: str, scripthash: str, amount: int):
cmd = ( f"{NEOGO_CLI_PREFIX} contract invokefunction -w {wallet} -a {address} -r http://main_chain.neofs.devenv:30333 "
f"{NEOFS_CONTRACT} withdraw {scripthash} int:{amount} -- {scripthash}" )
@ -113,8 +106,6 @@ def withdraw_mainnet_gas(wallet: str, address: str, scripthash: str, amount: int
return out
# neo-go contract invokefunction -w wallets/deploy_wallet.json -a NTrezR3C4X8aMLVg7vozt5wguyNfFhwuFx -r http://main_chain.neofs.devenv:30333
# 5f490fbd8010fd716754073ee960067d28549b7d withdraw 12b97a2206ae4b10c7e0194b7b655c32cc912057 int:10 -- 12b97a2206ae4b10c7e0194b7b655c32cc912057
@keyword('Mainnet Balance')
@ -145,10 +136,6 @@ def expected_mainnet_balance(address: str, expected: int):
raise Exception(f"Expected amount ({expected}) of GAS has not been found. Found {amount}.")
return True
# balance":[{"assethash":"668e0c1f9d7b70a99dd9e06eadd4c784d641afbc","amount":"50"
#curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "getnep5balances", "params": ["NTrezR3C4X8aMLVg7vozt5wguyNfFhwuFx"] }' main_chain.neofs.devenv:30333
#{"id":1,"jsonrpc":"2.0","result":{"balance":[{"assethash":"668e0c1f9d7b70a99dd9e06eadd4c784d641afbc","amount":"9237.47595500","lastupdatedblock":158}],"address":"NTrezR3C4X8aMLVg7vozt5wguyNfFhwuFx"}}
@ -168,35 +155,8 @@ def neofs_deposit(wallet: str, address: str, scripthash: str, amount: int):
tx = m.group(1)
# Sent invocation transaction
return tx
#docker exec -it main_chain \
# neo-go contract invokefunction \
# -w wallets/wallet.json \
# -a NTrezR3C4X8aMLVg7vozt5wguyNfFhwuFx \
# -r http://main_chain.${LOCAL_DOMAIN}:30333 \
# ${NEOFS_CONTRACT_MAINCHAIN} \
# deposit \
# 12b97a2206ae4b10c7e0194b7b655c32cc912057 \
# int:500 \
# bytes: \
# -- 12b97a2206ae4b10c7e0194b7b655c32cc912057
#neo-go contract invokefunction -w wallets/wallet.json -a NTrezR3C4X8aMLVg7vozt5wguyNfFhwuFx
#-r <http://main_chain.neofs.devenv:30333> af5dc5f7e6a6efc64d679098f328027591a2e518
#deposit 12b97a2206ae4b10c7e0194b7b655c32cc912057 int:60 bytes: --
#12b97a2206ae4b10c7e0194b7b655c32cc912057
# wallet nep5 transfer -w wallets/wallet.json -r http://main_chain.neofs.devenv:30333 --from NTrezR3C4X8aMLVg7vozt5wguyNfFhwuFx
# --to NULwe3UAHckN2fzNdcVg31tDiaYtMDwANt --token gas --amount 50
@keyword('Transaction accepted in block')
def transaction_accepted_in_block(tx_id):
@ -209,9 +169,6 @@ def transaction_accepted_in_block(tx_id):
logger.info("Transaction id: %s" % tx_id)
# curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "getnep5transfers", "params": ["NULwe3UAHckN2fzNdcVg31tDiaYtMDwANt"] }' main_chain.neofs.devenv:30333
TX_request = 'curl -X POST '+NEO_MAINNET_ENDPOINT+' --cacert ca/nspcc-ca.pem -H \'Content-Type: application/json\' -d \'{ "jsonrpc": "2.0", "id": 5, "method": "gettransactionheight", "params": [\"'+ tx_id +'\"] }\''
logger.info(f"Executing command: {TX_request}")