def systest_smart_contract_uapp(): log.info('Running systest smart contract UApp') d_conf = json.loads(Path('data/demo_config.json').read_text()) appnames = ['app1', 'app2', 'app3'] d_apps = d_conf['demo_apps'] conf = UnificationConfig() eos_client = Client( nodes=[f"http://{conf['eos_rpc_ip']}:{conf['eos_rpc_port']}"]) for appname in appnames: log.info("------------------------------------------") app_data = d_apps[appname] conf_db_schemas = app_data['db_schemas'] uapp_sc = UnificationUapp(eos_client, app_data['eos_sc_account']) log.info("Check DB Schemas are correctly configured") for schema_obj in conf_db_schemas: log.info(f"Check schema {schema_obj['schema_name']}") conf_schema = schema_obj['schema'] log.info(f"Expecting - config.json: {conf_schema}") # version set to 1, since that's the hard coded version used in # accounts.validate_with_mother uapp_contract_schema = uapp_sc.get_db_schema_by_pkey(0) log.info(f"Actual - UApp Smart Contract: " f"{uapp_contract_schema['schema']}") assert (conf_schema == uapp_contract_schema['schema']) is True
def __init__(self, eos_client, uapp_contract_acc, requesting_app, users): """ :param users: A list of users we want to obtain data for. If an empty list is provided, then data for all permissible users are provided. """ self.__uapp_contract_acc = uapp_contract_acc self.__requesting_app = requesting_app self.__haiku_conf = UnificationConfig() self.__my_mother = UnificationMother(eos_client, uapp_contract_acc, get_cleos(), get_ipfs_client()) self.__my_uapp_sc = UnificationUapp(eos_client, uapp_contract_acc) self.__my_lookup = UnificationLookup(default_lookup_db()) self.__users = None if len(users) == 0 else users self.__my_db_schemas = self.__my_uapp_sc.get_all_db_schemas() self.__db_schema_maps = {} self.__granted = [] self.__granted_field_lookup = {} self.__revoked = [] self.__raw_data = None self.__native_user_meta = self.__my_lookup.get_native_user_meta() for pkey, db_schema in self.__my_db_schemas.items(): schema_map = self.__my_lookup.get_schema_map(pkey) self.__db_schema_maps[pkey] = schema_map self.__generate_data()
def run_test(requesting_app): conf = UnificationConfig() eos_client = Client( nodes=[f"http://{conf['eos_rpc_ip']}:{conf['eos_rpc_port']}"]) print("THIS app is", conf['uapp_contract']) v = UnificationAppScValidation(eos_client, requesting_app) app_valid = v.valid_app() print(f"Requesting App {requesting_app} Valid according to MOTHER: " f"{app_valid}") code_valid = v.valid_code() print(requesting_app, "contract code hash valid:", code_valid) both_valid = v.valid() print(requesting_app, "is considered valid:", both_valid) if both_valid: print("App valid according to MOTHER. App code hash valid.") else: if app_valid is False: print("App not valid according to MOTHER") if code_valid is False: print("Code hash did not match hash held by MOTHER")
def get_eos_rpc_client(): haiku_env = get_enum() conf = UnificationConfig() if haiku_env == Environment.HOST: eos_host = '127.0.0.1' eos_port = '8888' else: eos_host = conf['eos_rpc_ip'] eos_port = conf['eos_rpc_port'] return Client(nodes=[f"http://{eos_host}:{eos_port}"])
def systest_smart_contract_mother(): log.info('Running systest smart contract MOTHER') d_conf = json.loads(Path('data/demo_config.json').read_text()) appnames = ['app1', 'app2', 'app3'] d_apps = d_conf['demo_apps'] conf = UnificationConfig() eos_client = Client( nodes=[f"http://{conf['eos_rpc_ip']}:{conf['eos_rpc_port']}"]) for appname in appnames: log.info("------------------------------------------") app_data = d_apps[appname] log.info(f"Contacting MOTHER for {app_data['eos_sc_account']}") mother = UnificationMother(eos_client, app_data['eos_sc_account'], get_cleos(), get_ipfs_client()) log.info("App is Valid") log.info("Expecting: True") log.info(f"Actual - MOTHER: {mother.valid_app()}") assert mother.valid_app() is True log.info("App Code is Valid") log.info("Expecting: True") log.info(f"Actual - MOTHER: {mother.valid_code()}") assert mother.valid_app() is True log.info("Code Hash") log.info( f"Expecting - config.json: {mother.get_deployed_contract_hash()}") log.info(f"Actual - MOTHER: {mother.get_hash_in_mother()}") assert (mother.get_deployed_contract_hash() == mother.get_hash_in_mother()) is True log.info("RPC IP") log.info(f"Expecting - config.json: {app_data['rpc_server']}") log.info(f"Actual - MOTHER: {mother.get_haiku_rpc_ip()}") assert (app_data['rpc_server'] == mother.get_haiku_rpc_ip()) is True log.info("RPC Port") log.info(f"Expecting - config.json: {app_data['rpc_server_port']}") log.info(f"Actual - MOTHER: {mother.get_haiku_rpc_port()}") assert (int(app_data['rpc_server_port']) == int( mother.get_haiku_rpc_port())) is True log.info("------------------------------------------")
def init(): """ Initialize the Haiku Server. """ config = UnificationConfig() if config['server_initialised']: click.echo(f'Server already initialized') else: pw = Fernet.generate_key() click.echo("Generated password:\n") click.echo(bold(pw.decode('utf-8'))) click.echo("\n") click.echo("IMPORTANT: KEEP THIS SAFE!! YOU WILL NEED IT TO RUN THE " "SERVER") click.echo("Run again with pw") config["server_initialised"] = True
def serve(password): """ Serve the Haiku RPC service. """ config = UnificationConfig() if not config['server_initialised']: click.echo(f'Server not initialized: Run {bold("haiku init")}') else: if password: spawn_haiku_node(password, config) else: env_password = os.environ.get('keystore') if not env_password: click.echo('Password to keystore not provided in args nor set ' 'as the keystore ENV VAR') else: spawn_haiku_node(env_password, config)
def __init__(self, uapp_acc: str, und_amt: int): """ :param uapp_acc: The account name of the payer. :param und_amt: The amount of UND to be processed """ self.__my_uapp_acc = uapp_acc self.__cleos = get_cleos() #TODO: I think I can deprecate the following conf = UnificationConfig() self.__eos_client_pre = [ "/opt/eosio/bin/cleos", "--url", f"http://{conf['eos_rpc_ip']}:{conf['eos_rpc_port']}", "--wallet-url", f"http://{conf['eos_wallet_ip']}:{conf['eos_wallet_port']}" ] self.__und_amt = und_amt
def systest_ingest(requesting_app, providing_app, user, balances): log.info(f'Testing Fetch ingestion: {requesting_app} ' f'is requesting data from {providing_app}') request_hash = f'data-request-{providing_app}-{requesting_app}' app_config = demo_config['demo_apps'][providing_app] port = app_config['rpc_server_port'] eos_client = get_eos_rpc_client() mother = UnificationMother(eos_client, providing_app, get_cleos(), get_ipfs_client()) provider_obj = Provider(providing_app, 'https', mother) password = demo_config['system'][requesting_app]['password'] encoded_password = str.encode(password) keystore = UnificationKeystore(encoded_password, app_name=requesting_app, keystore_path=Path('data/keys')) conf = UnificationConfig() eos_client = Client( nodes=[f"http://{conf['eos_rpc_ip']}:{conf['eos_rpc_port']}"]) consumer_uapp_sc = UnificationUapp(eos_client, requesting_app) price_sched = demo_config['demo_apps'][providing_app]['db_schemas'][0][ 'price_sched'] latest_req_id = consumer_uapp_sc.init_data_request(provider_obj.name, "0", "0", price_sched) client = HaikuDataClient(keystore) client.make_data_request(requesting_app, provider_obj, user, request_hash, latest_req_id) client.read_data_from_store(provider_obj, request_hash) # Update the system test record of the balances balances[requesting_app] = balances[requesting_app] - price_sched und_rewards = UndRewards(providing_app, price_sched) balances[providing_app] = (balances[providing_app] + und_rewards.calculate_reward(is_user=False)) return balances
def test_data_factory(): conf = UnificationConfig() eos_client = Client(nodes=[f"{conf['eos_rpc_ip']}:{conf['eos_rpc_port']}"]) print("Bulk data request from app3") data_factory = UnificationDataFactory(eos_client, os.environ['app_name'], 'app3') # encrypted_data = data_factory.get_encrypted_data() raw_data = data_factory.get_raw_data() print(raw_data[:50]) # print(encrypted_data[:50]) print("request from app3 for user1's data") data_factory = UnificationDataFactory(eos_client, os.environ['app_name'], 'app3', ['user1']) # encrypted_data = data_factory.get_encrypted_data() raw_data = data_factory.get_raw_data() print(raw_data[:50])
def get_self_uapp(): conf = UnificationConfig() eos_client = get_eos_rpc_client() return UnificationUapp(eos_client, conf['uapp_contract'])
import json from pathlib import Path from haiku_node.blockchain.eos.mother import UnificationMother from haiku_node.config.config import UnificationConfig from haiku_node.network.eos import (get_cleos, get_eos_rpc_client, get_ipfs_client) apps_to_test = ['app1', 'app2', 'app3'] config = UnificationConfig() demo_config = json.loads(Path('test/data/demo_config.json').read_text()) demo_apps = demo_config["demo_apps"] def run_test(app): print("Contacting MOTHER FOR: ", app) eos_client = get_eos_rpc_client() um = UnificationMother(eos_client, app, get_cleos(), get_ipfs_client()) print("Valid app: ", um.valid_app()) assert um.valid_app() is True print("UApp SC Hash in MOTHER: ", um.get_hash_in_mother()) print("Deployed UApp SC hash: ", um.get_deployed_contract_hash()) assert um.get_hash_in_mother() == um.get_deployed_contract_hash() print("Valid Code: ", um.valid_code()) assert um.valid_code() is True print("RPC IP: ", um.get_haiku_rpc_ip()) assert um.get_haiku_rpc_ip() == demo_apps[app]['rpc_server']
"/haiku/haiku_node/keystore/keys.store") shutil.copy(f"/haiku/test/data/lookups/{app_name}.unification_lookup.db", "/haiku/haiku_node/dbs/unification_lookup.db") shutil.copy(f"/haiku/test/data/sqlite/{app_name}.db", "/haiku/haiku_node/dbs/Data.db") shutil.copy(f"/haiku/test/data/perm_batch/{app_name}.perm_batches.db", "/haiku/haiku_node/dbs/perm_batches.db") shutil.copy(f"/haiku/test/data/adhoc/{app_name}.adhoc.db", "/haiku/haiku_node/dbs/adhoc.db") print(f"set config/config.json values for host {app_name}") uc = UnificationConfig() uc["uapp_contract"] = app_name uc["eos_rpc_ip"] = "nodeosd" # set up DB config values dbs = {} for schemas in demo_config['demo_apps'][app_name]['db_schemas']: db = { 'filename': schemas['filename'], } dbs[schemas['sc_schema_pkey']] = db uc['db_conn'] = dbs print("config.json:")