diff --git a/.gitignore b/.gitignore index 4dee8c010..68fbe05cb 100644 --- a/.gitignore +++ b/.gitignore @@ -78,4 +78,6 @@ dbml-error.log __pycache__ -*sgx_linux_x64_sdk_2.9.101.2.bin \ No newline at end of file +*sgx_linux_x64_sdk_2.9.101.2.bin + +integ-tests/entropy_config \ No newline at end of file diff --git a/cli/dataobjects.py b/cli/dataobjects.py new file mode 100644 index 000000000..94b16fdb5 --- /dev/null +++ b/cli/dataobjects.py @@ -0,0 +1,14 @@ +class Account(object): + def __init__(self, d): + self.__dict__ = d + +class Response(object): + def __init__(self, d): + self.__dict__ = d + if self.method == 'get_accounts': + self.account_ids = self.result['account_ids'] + self.accounts = {} + for acc in self.account_ids: + self.accounts[acc] = Account(self.result['account_map'][acc]) + if self.method == 'get_account_status': + self.account = Account(self.result['account']) diff --git a/cli/fullservice.py b/cli/fullservice.py index 072da37e1..edd93f6ea 100644 --- a/cli/fullservice.py +++ b/cli/fullservice.py @@ -31,7 +31,7 @@ class Request: def __init__(self, logLevel = logging.ERROR): self.logger = utils.logger url = utils.get_secret('URL') - + async def req(self, request_data: dict) -> dict: logging.info("request: %s", request_data.get("method")) if len(request_data["params"]) > 0: @@ -518,8 +518,8 @@ async def get_txo_membership_proofs(self, outputs=""): async def import_account( self, - mnemonic="", - key_derivation_version="", + mnemonic, + key_derivation_version, name="", first_block_index="", next_subaddress_index="", diff --git a/integ-tests/basic.py b/integ-tests/basic.py index 125513cea..8a4bd1af8 100644 --- a/integ-tests/basic.py +++ b/integ-tests/basic.py @@ -2,31 +2,107 @@ # the mob went through # the transaction log updatedx # Ideally all of the endpoints (v2) that actually hit the mobilecoin network -# +# # get_network_status # get_wallet_status # build, build_and_submit, build_split_txo .. etc -import sys import os -sys.path.append(os.path.abspath("../cli")) - -from fullservice import FullServiceAPIv2 as v2 +import sys import asyncio import json -import subprocess -from pathlib import Path -with open('config') as json_file: +sys.path.append(os.path.abspath("../cli")) + +from fullservice import FullServiceAPIv2 as v2 +from dataobjects import Response, Account # TODO rename as FSDataObjects + +with open("config") as json_file: config = json.load(json_file) +fs = v2() +account_ids = [] + + +def get_mnemonics(n=2): + if n > len(config["Account Mnemonics"]): + raise ValueError("Not enough account available in config") + return config["Account Mnemonics"][:n] + + +async def get_account(i): + global account_ids + + mnemonic = config["Account Mnemonics"][i]["mnemonic"] + account = await fs.import_account( + mnemonic, "2" + ) # this is importing the second mnemonic? + + if "error" not in account.keys(): + return Account(account["result"]["account"]) + else: + if len(account_ids) <= i: + accounts_response = Response(await fs.get_accounts()) + account_ids = accounts_response.account_ids + return accounts_response.accounts[account_ids[i]] + else: + return Response(await fs.get_account_status(account_ids[i])).account + async def main(): - fs = v2() + print(await does_it_go()) + +async def does_it_go(amount_pmob: int = 5) -> bool: network_status = await fs.get_network_status() - print(network_status) - -if __name__ == '__main__': - asyncio.run(main()) \ No newline at end of file + alice = await get_account(0) + bob = await get_account(1) + await fs.get_wallet_status() + + pmob_to_send = amount_pmob + bob_status_0 = ( + (await fs.get_account_status(bob.id)) + .get("result") + .get("balance_per_token") + .get("0") + .get("unspent") + ) + alice_status_0 = ( + (await fs.get_account_status(alice.id)) + .get("result") + .get("balance_per_token") + .get("0") + .get("unspent") + ) + + first_transaction = await fs.build_and_submit_transaction( + alice.id, + recipient_public_address=bob.main_address, + amount={"value": str(pmob_to_send), "token_id": str(0)}, + ) + + # TODO: replace this with a poll loop that waits a block or two + await asyncio.sleep(15) + alice_status_1 = ( + (await fs.get_account_status(alice.id)) + .get("result") + .get("balance_per_token") + .get("0") + .get("unspent") + ) + bob_status_1 = ( + (await fs.get_account_status(bob.id)) + .get("result") + .get("balance_per_token") + .get("0") + .get("unspent") + ) + # decreases by fee and amount_pmob + # print(int(alice_status_1)-int(alice_status_0)) + bob_increase = int(bob_status_1) - int(bob_status_0) + return bob_increase == pmob_to_send + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/integ-tests/config b/integ-tests/config deleted file mode 100644 index 7a73a41bf..000000000 --- a/integ-tests/config +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file