Tests_python: add integration tests for Sapling

Co-authored-by: Marc Beunardeau's avatarMarc beunardeau <[email protected]>
Co-authored-by: Mehdi Bouaziz's avatarMehdi Bouaziz <[email protected]>
parent 4780bc99
......@@ -454,6 +454,12 @@ integration:rpc:
- pytest tests_python/tests/test_rpc.py -s --log-dir=tmp
stage: test
integration:sapling:
<<: *integration_definition
script:
- pytest tests_python/tests/test_sapling.py
stage: test
integration:tls:
<<: *integration_python_definition
script:
......
......@@ -694,3 +694,144 @@ class Client:
def expand_macros(self, src: str) -> str:
cmd = ['expand', 'macros', 'in', src]
return self.run(cmd)
def sapling_gen_key(self,
key_name: str,
contract_name: str,
force: bool = False,
args: List[str] = None
) -> client_output.SaplingGenKeyResult:
cmd = ['sapling', 'gen', 'key', key_name,
'--for-contract', contract_name,
'--unencrypted']
if force:
args += ['--force']
if args is None:
args = []
cmd += args
return client_output.SaplingGenKeyResult(self.run(cmd))
def sapling_gen_address(self,
key_name: str,
index=None,
args: List[str] = None
) -> client_output.SaplingGenAddressResult:
cmd = ['sapling', 'gen', 'address', key_name]
if index is not None:
cmd += ['--index', str(index)]
if args is None:
args = []
cmd += args
return client_output.SaplingGenAddressResult(self.run(cmd))
def sapling_import_key(self,
key_name: str,
contract_name: str,
mnemonic: List[str],
force: bool = False,
args: List[str] = None) -> None:
mnemonic_str = " ".join(mnemonic)
cmd = ['sapling', 'import', 'key', key_name,
'--for-contract', contract_name,
'--unencrypted',
'--mnemonic', mnemonic_str]
if force:
cmd += ['--force']
if args is None:
args = []
cmd += args
self.run(cmd)
def sapling_derive_key(self,
source_key_name: str,
target_key_name: str,
contract_name: str,
index: int,
force: bool = False
) -> client_output.SaplingDeriveKeyResult:
cmd = ['sapling', 'derive', 'key', target_key_name,
'from', source_key_name, 'at', 'index', str(index),
'--for-contract', contract_name,
'--unencrypted']
if force:
cmd += ['--force']
return client_output.SaplingDeriveKeyResult(self.run(cmd))
def sapling_get_balance(self,
key_name: str,
contract_name: str,
args: List[str] = None
) -> client_output.SaplingGetBalanceResult:
cmd = ['sapling', 'get', 'balance', 'for', key_name,
'--for-contract', contract_name]
if args is None:
args = []
cmd += args
return client_output.SaplingGetBalanceResult(self.run(cmd))
def sapling_shield(self,
amount: float,
src: str,
dest: str,
contract: str,
args: List[str] = None
) -> None:
cmd = ['sapling', 'shield',
str(amount), 'from', src, 'to', dest,
'using', contract]
if args is None:
args = []
cmd += args
self.run(cmd)
def sapling_unshield(self,
amount: float,
src: str,
dest: str,
contract: str,
args: List[str] = None
) -> None:
cmd = ['sapling', 'unshield',
str(amount), 'from', src, 'to', dest,
'using', contract]
if args is None:
args = []
cmd += args
self.run(cmd)
def sapling_forge_transaction(self,
amount: float,
src: str,
dest: str,
contract: str,
file: str,
args: List[str] = None) -> None:
cmd = ['sapling', 'forge', 'transaction',
str(amount), 'from', src, 'to', dest,
'using', contract, '--file', file]
if args is None:
args = []
cmd += args
self.run(cmd)
def sapling_submit(self,
file: str,
fee_payer: str,
contract: str,
args: List[str] = None) -> None:
cmd = ['sapling', 'submit', file,
'from', fee_payer,
'using', contract]
if args is None:
args = []
cmd += args
self.run(cmd)
def sapling_list_keys(self) -> List[str]:
cmd = ['sapling', 'list', 'keys']
return self.run(cmd).strip().split("\n")
......@@ -229,6 +229,54 @@ class SignBytesResult:
self.signature = match.groups()[0]
class SaplingGenKeyResult:
"""Result of a 'sapling gen key' operation."""
def __init__(self, client_output: str):
pattern = (r'It is important to save this menemonic in a secure '
r'place:\n\n([\w\s]+)\n\nThe mnemonic')
match = re.search(pattern, client_output)
if match is None:
raise InvalidClientOutput(client_output)
self.mnemonic = match.groups()[0].split()
class SaplingGenAddressResult:
"""Result of a 'sapling gen address' operation."""
def __init__(self, client_output: str):
address_match = re.search(r"Generated address:\n(\w+)\n",
client_output)
if address_match is None:
raise InvalidClientOutput(client_output)
self.address = address_match.groups()[0]
index_match = re.search(r"at index (\d+)", client_output)
if index_match is None:
raise InvalidClientOutput(client_output)
self.index = int(index_match.groups()[0])
class SaplingDeriveKeyResult:
"""Result of a 'sapling derive key' operation."""
def __init__(self, client_output: str):
path_match = re.search(r"with path (\S+)", client_output)
if path_match is None:
raise InvalidClientOutput(client_output)
self.path = path_match.groups()[0]
class SaplingGetBalanceResult:
"""Result of a 'sapling get balance' query."""
def __init__(self, client_output: str):
balance_match = re.search(r"Total Sapling funds ([\d\.]+)",
client_output)
if balance_match is None:
raise InvalidClientOutput(client_output)
self.balance = float(balance_match.groups()[0])
def extract_rpc_answer(client_output: str) -> dict:
"""Convert json client output to a dict representation.
......
......@@ -20,7 +20,7 @@ def scenario():
# Wait for second node to update its protocol to alpha, if not
# it may not know yet the `wait_for_inclusion` operation which is
# protocol specific
time.sleep(15)
time.sleep(20)
# first client tells node 0 to transfer money for an account to another
# receipt is an object representing the client answer
receipt = sandbox.client(0).transfer(500, 'bootstrap1', 'bootstrap3')
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment