diff --git a/pyrgov/rgov.py b/pyrgov/rgov.py index 371256b0..c5646ac7 100644 --- a/pyrgov/rgov.py +++ b/pyrgov/rgov.py @@ -70,7 +70,8 @@ def render_contract_template(template_file: pathlib, substitutions: Mapping[str, file = template_file.open() template = file.read() file.close() - return string.Template(template).substitute(substitutions) + contract = string.Template(template).substitute(substitutions) + return contract class rgovAPI: @@ -109,6 +110,8 @@ def import_shared_private_keys(self) -> Mapping[str, str]: return keys def get_private_key(self, name: str) -> PrivateKey: + if name == 'anonymous': + return PrivateKey.generate() # Warning potential Ambient Access, if account is given REV if name in self.keyVault: return PrivateKey.from_hex(self.keyVault[name]) reason = 'No key found in vault for ' + name @@ -128,10 +131,14 @@ def propose(self) -> None: def checkBalance(self, rev_addr: str, block_hash: str='') -> int: contract = render_contract_template( CHECK_BALANCE_RHO_TPL, - {'addr': rev_addr, 'myBalance': "mybal"}, + {'addr': rev_addr, 'myBalance': "mybal", + 'rev': "${rev}", 'fraction': "${fraction}", 'num': "${num}"}, ) result = self.client.exploratory_deploy(contract, block_hash) - return result[0].exprs[0].e_list_body.ps[2].exprs[0].g_int + if result[0].exprs[0].HasField("e_list_body"): + return result[0].exprs[0].e_list_body.ps[2].exprs[0].g_int + if result[1].exprs[0].HasField("e_list_body"): + return result[1].exprs[0].e_list_body.ps[2].exprs[0].g_int def transfer(self, from_addr: str, to_addr: str, amount: int, key: PrivateKey) -> str: contract = render_contract_template( diff --git a/testing/unit_test/test_balance.py b/testing/unit_test/test_balance.py index 769b9ddc..ec01a5b1 100755 --- a/testing/unit_test/test_balance.py +++ b/testing/unit_test/test_balance.py @@ -1,10 +1,13 @@ #!/usr/bin/python3 -from rchain.crypto import PrivateKey from pyrgov.rgov import rgovAPI +import pathlib + +if __name__ != pathlib.Path(__file__).stem and __name__ != '__main__': + assert False rgov = rgovAPI('localhost') -new1 = PrivateKey.generate() +new1 = rgov.get_private_key('anonymous') admin = rgov.get_private_key('bootstrap') balance = rgov.checkBalance(new1.get_public_key().get_rev_address())