Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial PR for integ test suite #594

Merged
merged 22 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ dbml-error.log

__pycache__

*sgx_linux_x64_sdk_2.9.101.2.bin
*sgx_linux_x64_sdk_2.9.101.2.bin

integ-tests/entropy_config
14 changes: 14 additions & 0 deletions cli/dataobjects.py
Original file line number Diff line number Diff line change
@@ -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'])
6 changes: 3 additions & 3 deletions cli/fullservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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="",
Expand Down
102 changes: 89 additions & 13 deletions integ-tests/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
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())
2 changes: 0 additions & 2 deletions integ-tests/config

This file was deleted.