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 run_test_mother(self, app, demo_apps):
        print("Contacting MOTHER FOR: ", app)

        eos_client = Client(nodes=[self.cleos.get_nodeos_url()])
        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("Signed by MOTHER: ", um.signed_by_mother())
        assert um.signed_by_mother() is True

        print("RPC IP: ", um.get_haiku_rpc_ip())
        assert um.get_haiku_rpc_ip() == demo_apps[app]['rpc_server']

        print("RPC Port: ", um.get_haiku_rpc_port())
        assert int(um.get_haiku_rpc_port()) == int(
            demo_apps[app]['rpc_server_port'])

        print("RPC Server: ", um.get_haiku_rpc_server())
        print("-----------------------------------")
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 run_test_uapp(self, app):
        print("Loading UApp Contract for: ", app)

        eos_client = Client(nodes=[self.cleos.get_nodeos_url()])
        u_uapp = UnificationUapp(eos_client, app)

        print("Data Schemas:")
        print(u_uapp.get_all_db_schemas())

        print("-----------------------------------")
Ejemplo n.º 5
0
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 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])
Ejemplo n.º 9
0
import pprint
import time
from eosapi import Client

c = Client(nodes=['https://geo.eosasia.one'])

def check_order(lower_bound=1):
    expired_orders = []
    now = time.time()
    new_lower_bound = lower_bound
    r = c.get_table_rows(**{"code": "bankofstaked", "scope": "921459758687", "table": "order", "json": True, "limit": 100, "upper_bound": None, "lower_bound": lower_bound, "table_key": "id"})
    more = r["more"]
    total_count = 0
    count = 0
    free_count = 0
    paid = []
    for line in r["rows"]:
        total_count += 1
        if line["expire_at"] < now:
            expired_orders.append(line)
            count+=1
            #print(line)
            if line["is_free"]:
                #print("free id:", line["id"])
                free_count += 1
            else:
                paid.append(line["id"])
        if line["id"] > lower_bound:
            new_lower_bound = line["id"]
    print("total orders: %d" % total_count)
    print("expired orders: %d" % count)
Ejemplo n.º 10
0
import pprint
import time
from eosapi import Client

c = Client(nodes=['https://api.eoslaomao.com'])


def check_order(lower_bound=1):
    expired_orders = []
    now = time.time()
    new_lower_bound = lower_bound
    r = c.get_table_rows(
        **{
            "code": "bankofstaked",
            "scope": "921459758687",
            "table": "order",
            "json": True,
            "limit": 10000,
            "upper_bound": None,
            "lower_bound": lower_bound,
            "table_key": "id"
        })
    more = r["more"]
    count = 0
    free_count = 0
    for line in r["rows"]:
        if line["expire_at"] < now:
            expired_orders.append(line)
            count += 1
            print(line)
            if line["is_free"]:
Ejemplo n.º 11
0
from eosapi import Client
from config import HTTP_ENDPOINT

client = Client(nodes=[HTTP_ENDPOINT])
Ejemplo n.º 12
0
#! /usr/bin/python3
import time
from pymongo import MongoClient
from eosapi import Client
import json
import bp_json_inspector
import threading
import sys
import os
from chainlogger import log
import datetime

mongodb_prefix = ''
bp_json_inspector.set_mongodb_prefix(mongodb_prefix)

c = Client(nodes=['https://node2.eosphere.io'])

if len(sys.argv) != 2:
    raise Exception(
        "You must provide the IP address of the mongodb server on the commandline"
    )

mongodb_server = sys.argv[1]

client = MongoClient('mongodb://{}:27017/'.format(mongodb_server))
db = client.eos_producers
producers = db[mongodb_prefix + 'producers']
owners = {}
last_owner = ''
more = None
bp_json_thread_running = False
Ejemplo n.º 13
0
#! /usr/bin/python3
import time
from pymongo import MongoClient
from eosapi import Client
import json
import bp_json_inspector
import threading
import sys
import os
from chainlogger import log
import datetime

c = Client(nodes=['http://221.122.119.226:8888'])

if len(sys.argv) != 2:
    raise Exception(
        "You must provide the IP address of the mongodb server on the commandline"
    )

mongodb_server = sys.argv[1]

client = MongoClient('mongodb://{}:27017/'.format(mongodb_server))
db = client.eos_producers
producers = db.producers
owners = {}
last_owner = ''
more = None
bp_json_thread_running = False
chain_id = ''

Ejemplo n.º 14
0
def createAccount():
    c = Client(nodes=['http://localhost:8888'])
    info = c.get_info()
    info_dict = json.loads(info)