def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    _tenant = Tenant(CONFIG.TENANT_INDEX)

    _exchange = _tenant.get_exchange()
    if not _exchange:
        _exchange = _tenant.create_exchange()

    audits = _staff.query_audits_tenant(uid=_tenant.account_id, status="audit")

    for au in audits:
        print(au)
    for audit in audits:
        _staff.audits_tenants(task_id=audit.id, approval="approved")

        result = _staff.get_tenant_indiv_audits_result(audit_id=audit.id)
        assert result.audit_status == "approved"

    re_audits = _staff.query_audits_tenant(uid=_tenant.account_id,
                                           status="re_audit")
    for re_audit in re_audits:
        _staff.reaudits_tenants(task_id=re_audit.id, approval="approved")

        result = _staff.get_tenant_indiv_re_audits_result(audit_id=re_audit.id)
        assert result.re_status == "approved"
    print("exchange ==============>", _tenant.get_exchange())
    assert _tenant.is_exchange_approved(), "exchange should be approved here"
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    sponsor_info = get_templated_attrs(Sponsor, CONFIG.SPONSOR_INDEX)
    if _staff.create_sponsor(**sponsor_info):
        _sponsor = Sponsor(CONFIG.SPONSOR_INDEX)
    else:
        assert 0, "staff create sponsor failed!"
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    _venture = Venture(CONFIG.VENTURE_INDEX)
    _venture.request_individual_cert()
    _venture.get_usdt_coin_id()
    _staff.verify_individual(identity=_venture.identity, approval="ACCEPTED")
    logger.info("==  Venture(%u) ready  ==" % CONFIG.VENTURE_INDEX)
    print(_venture.api_account.accounts_account_info_get())
    print("project[%u] ====> %s" % (CONFIG.PROJECT_INDEX, _venture.get_project(index=CONFIG.PROJECT_INDEX)))
Example #4
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    
    for t in tag_items:
        for item in _staff.list_tags():
            if item.name == t["name"]:
                break
        else:
            _staff.create_tag(tag=t["name"], other_language=[t["other_language"]])
        logger.info("==========  tag < %s > ready  ==========" % t["name"])
Example #5
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    for root, dirs, files in os.walk(CUR_DIR+"/data/"):
        for dirct in dirs:
            abs_path = root + f"{dirct}"
            photos = sorted(list_all_photos(abs_path), key=lambda path: int(os.path.basename(path)[:-4]))
            photo_json = retrieve_logo_data(abs_path+"/photo.json")
            if len(photos) > len(photo_json):
                photo_json = []
                for photo in photos:
                    key, url = _staff.upload(photo)
                    # key, url = "key", "url"
                    logger.info("upload %s with key:%s url:%s" % (photo, key, url))
                    photo_json.append(dict(key=key, url=url))
                with open(abs_path+"/photo.json", "w") as f:
                    f.write(json.dumps(photo_json))
            logger.info("==========  Upload %u photo done  ==========" % len(photo_json))
Example #6
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    _tenant = Tenant(CONFIG.TENANT_INDEX)
    _tenant.request_individual_cert()
    print("identity:%s, email:%s password:%s", _tenant.identity, _tenant.email,
          _tenant.password)
    _staff.verify_individual(identity=_tenant.identity, approval="approved")
    assert _tenant.audit_accepted()
    print(_tenant.api_account.accounts_account_info_get())
    for market in _tenant.list_markets():
        print(_tenant.get_market_details(market_id=market.id))
    # logger.info("==========  Tenant(%u) ready  ==========" % CONFIG.TENANT_INDEX)
    print("daily statistics ===>", _tenant.get_daily_statistics())
    print(
        "test photo:",
        _tenant.upload(
            path=
            "/home/xy/repos/gitlab/java-crush-test2.0/test/tenant/python.jpg"))
Example #7
0
def setup(request):
    _staff = Staff(CONFIG.STAFF_INDEX)
    _tenant = Tenant(CONFIG.TENANT_INDEX)
    _venture = Venture(CONFIG.VENTURE_INDEX)
    _sponsor = Sponsor(CONFIG.SPONSOR_INDEX)
    _main = Main(CONFIG.MAIN_INDEX)

    def finalize():
        pass

    request.addfinalizer(finalize)
    return _staff, _main, _tenant, _venture, _sponsor
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)

    pprint(project_items)

    _ventures = list()
    _projects = list()

    for i, prj in enumerate(project_items):
        _venture = Venture(i)
        _ventures.append(_venture)
        _project = _venture.get_project(0, project_name=prj["project_name"])
        _projects.append(_project)

    coins_id = dict()
    coins_id["USDT"] = 1
    for coin in COINS[1:]:
        for p in _projects:
            print("p.short_name:%s vs coin:%s" % (p.short_name, coin))
            if p.short_name == coin.upper():
                coins_id[coin.upper()] = p.coin_id
                break
        else:
            assert 0, "No such coin:%s" % coin

    pprint(coins_id)
    _tenants = list()
    for i, exch in enumerate(exchange_items):
        _tenant = Tenant(i)
        _exchange = _tenant.get_exchange()
        for _project in _projects:
            _tenant.contacts(project_id=_project.project_id,
                             exchange_id=_exchange.exchange_id,
                             sponsor="tenant")
        for market_index, market in enumerate(market_items[i]):
            to_sell = market[0].upper()
            to_buy = market[1].upper()
            print("try to create %s/%s" % (to_sell, to_buy))
            _market = _tenant.get_market(buy=coins_id[to_buy],
                                         sell=coins_id[to_sell])
            if not _market:
                _faucet = Faucet(
                    _tenant.token_mgr.token,
                    _tenant.api_account.api_client.configuration.host)
                _faucet.free_charge(coin_id=coins_id["USDT"],
                                    amount=1000000000)
                _market, order_id = _tenant.create_market(
                    coins_id[to_buy], coins_id[to_sell], "6", "0")
            logger.info(
                "==========  Tenant(%u) create Market(%s) Done ==========" %
                (i, _market.market_id))
def setup(request):
    _staff = Staff(CONFIG.STAFF_INDEX)
    _venture = Venture(CONFIG.VENTURE_INDEX)
    _project = _venture.get_project(CONFIG.PROJECT_INDEX)
    assert _project.project_id, "需要先创建一个项目"
    for ann in _venture.list_announcements(project_id=_project.project_id):
        _venture.delete_announcement(ann.id)

    _venture.post_announcement(**TEST_PROJECT_ANNOUNCEMENT, project_id=_project.project_id)

    def finalize():
        for ann in _venture.list_announcements(project_id=_project.project_id):
            _venture.delete_announcement(ann.id)

    request.addfinalizer(finalize)
    return _staff, _venture, _project
def setup(request):
    _staff = Staff(CONFIG.STAFF_INDEX)
    _tenant = Tenant(CONFIG.TENANT_INDEX)
    _exchange = _tenant.get_exchange()
    _main = Main(CONFIG.MAIN_INDEX)
    for ann in _tenant.list_announcements():
        _tenant.delete_announcement(ann.id)

    _tenant.post_announcement(**TEST_EXCHANGE_ANNOUNCEMENT)

    def finalize():
        for ann in _tenant.list_announcements():
            _tenant.delete_announcement(ann.id)

    request.addfinalizer(finalize)
    return _staff, _tenant, _exchange, _main
def setup():
    banner = dict(title="hello world",
                  banner="今晚打老虎",
                  platform="pc",
                  position="homepage",
                  language="zh_cn",
                  order=0,
                  status=True,
                  url="http://firer_on_fire.com")

    banner_modified = dict(title="go go go",
                           banner="夜上海, 夜上海",
                           platform="pc",
                           position="homepage",
                           language="zh_cn",
                           order=0,
                           status=True,
                           url="http://firer_on_fire.com")
    return Staff(CONFIG.STAFF_INDEX), Main(
        CONFIG.MAIN_INDEX), banner, banner_modified
Example #12
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    logger.info("==========  Staff(%u) ready  ==========" % CONFIG.STAFF_INDEX)
    with open(CUR_DIR + "/data/sponsor_logos/photo.json") as f:
        sponsor_logos = json.loads(f.read())
    if len(sponsor_logos) != len(sponsor_items):
        assert "sponsor logo count:%u vs sponsors count:%u" % (len(sponsor_logos), len(sponsor_items))
    
    for i, sponsor in enumerate(sponsor_items):
        info = get_templated_attrs(Sponsor, i)
        info["name"] = sponsor["name"]
        assert _staff.create_sponsor(**info), "Create sponsor:%u failed" % i
        s = Sponsor(i, attrs=info)
        print("%u ===> %s:" % (i,sponsor["name"]), s)
    
    for i, sponsor in enumerate(sponsor_items):
        for sp in _staff.list_sponsors():
            if sp.name == sponsor["name"]:
                info = get_templated_attrs(Sponsor, i)
                print("sponsor_id:", sp.id)
                _staff.update_sponsor(sponsor_id=sp.id, logo=sponsor_logos[i]["key"], website=sponsor["official_url"],
                                      summary=sponsor["summary"], phone=info["phone"])
Example #13
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    _main = Main(CONFIG.MAIN_INDEX)
    _tenant = Tenant(CONFIG.TENANT_INDEX)
    _main.request_individual_cert()
    _staff.verify_individual(identity=_main.identity, approval="ACCEPTED")

    _venture = Venture(CONFIG.VENTURE_INDEX)
    _venture.request_individual_cert()
    _staff.verify_individual(identity=_venture.identity, approval="ACCEPTED")

    print(_main.api_account.accounts_account_info_get())
    usdt_id = _venture.get_usdt_coin_id()
    print("usdt_id ==>", )
    _faucet = Faucet(_main.token_mgr.token,
                     _main.api_account.api_client.configuration.host)
    _faucet.free_charge(coin_id=usdt_id, amount=10000000000000)

    print("tenant:", _tenant.account_id)
    print("main usdt balance:", _main.query_coin_balance(usdt_id))
    print("tenant usdt balance:", _tenant.query_coin_balance(usdt_id))
    print("entrusts ===============>", _main.api_entrust.entrusts_get())
    print("projects list =============>", _main.list_projects())
    print("exchanges list=============>", _main.list_exchanges())
Example #14
0
def setup():
    CONFIG = Config()

    _staff = Staff(CONFIG.STAFF_INDEX)

    _tenant = Tenant(CONFIG.TENANT_INDEX)
    _venture = Venture(CONFIG.VENTURE_INDEX)
    _main = Main(CONFIG.MAIN_INDEX)

    _tenant.request_individual_cert()
    _venture.request_individual_cert()
    _main.request_individual_cert()

    _staff.verify_individual(identity=_tenant.identity, approval="approved")
    rsp = _staff.get_indiv_audits_result(account_id=_tenant.account_id)
    assert rsp.certification_status == "ACCEPTED"
    _staff.verify_individual(identity=_venture.identity, approval="approved")
    rsp = _staff.get_indiv_audits_result(account_id=_venture.account_id)
    assert rsp.certification_status == "ACCEPTED"

    sponsor_info = get_templated_attrs(Sponsor, CONFIG.SPONSOR_INDEX)
    if _staff.create_sponsor(**sponsor_info):
        _sponsor = Sponsor(CONFIG.SPONSOR_INDEX)
    else:
        assert 0, "staff create sponsor failed!"
    _sponsor = Sponsor(CONFIG.SPONSOR_INDEX)

    # =================== 创建 tags ========================
    for item in _staff.list_tags():
        if item.name == CONFIG.MY_TAG:
            break
    else:
        _staff.create_tag(tag=CONFIG.MY_TAG,
                          other_language=[{
                              "key": "英语",
                              "value": "public_chain"
                          }])
    logger.info("==========  tag < %s > ready  ==========" % CONFIG.MY_TAG)

    # =================== 创建 交易所 ========================
    _exchange = _tenant.get_exchange()
    if not _exchange:
        _exchange = _tenant.create_exchange()
    audits = _staff.query_audits_tenant(uid=_tenant.account_id, status="audit")

    for audit in audits:
        _staff.audits_tenants(task_id=audit.id, approval="approved")

        result = _staff.get_tenant_indiv_audits_result(audit_id=audit.id)
        assert result.audit_status == "approved"

    re_audits = _staff.query_audits_tenant(uid=_tenant.account_id,
                                           status="re_audit")
    for re_audit in re_audits:
        _staff.reaudits_tenants(task_id=re_audit.id, approval="approved")

        result = _staff.get_tenant_indiv_re_audits_result(audit_id=re_audit.id)
        assert result.re_status == "approved"

    if _tenant.is_exchange_approved():
        _exchange = _tenant.update_exchange_info()
    else:
        assert 0, "exchange should be approved here"

    logger.info("========== exchange_id:%s ready ==========" %
                _exchange.exchange_id)

    # ================ 创建项目 =============================
    _project = _venture.get_project(CONFIG.PROJECT_INDEX)

    if not _project:
        _project = _venture.create_project(CONFIG.PROJECT_INDEX)
    assert _project

    logger.info("==========  Project(%u) %s: %s(%s) Done ==========",
                CONFIG.PROJECT_INDEX, _project.project_name,
                _project.full_name, _project.short_name)

    # ======================= sponsor 保荐项目 ========================
    sponsor_id = _venture.query_sponsor_id(_sponsor.name)
    logger.info("sponsor id:%s ============>" % sponsor_id)

    for app in _venture.list_applications():
        _venture.set_sponsor(sponsor_id, app.id)

    app_id = _sponsor.query_project_application_id(_project.project_name)
    if app_id:
        _sponsor.sponsor_project(app_id)

    _project = _venture.update_project_info(CONFIG.PROJECT_INDEX)

    logger.info(
        "==========  Sponsor(%u) $$$ Project(%u) %s: %s(%s) Done ==========" %
        (CONFIG.SPONSOR_INDEX, CONFIG.PROJECT_INDEX, _project.project_name,
         _project.full_name, _project.short_name))

    # ========================= staff 初始化项目 ============================
    for config in _staff.get_coins_config_list():
        if config.coin_id == _project.coin_id:
            print("%s config id:%s" % (_project.coin_id, config.id))
            _staff.init_coin(usdt_price=1, config_id=config.id)
            _staff.config_coin_rechargable(config.id, rechargeable=True)
            _staff.config_coin_withdrawable(config.id, withdrawable=True)
    logger.info("==========  Init Project(%u) %s: %s(%s) Done  ==========" %
                (CONFIG.PROJECT_INDEX, _project.project_name,
                 _project.full_name, _project.short_name))

    return _staff, _tenant, _venture, _project, _exchange, CONFIG
Example #15
0
def main():

    _staff = Staff(CONFIG.STAFF_INDEX)
    _venture = Venture(CONFIG.VENTURE_INDEX)
    _tenant = Tenant(CONFIG.TENANT_INDEX)

    _tenant.request_individual_cert()
    _staff.verify_individual(identity=_tenant.identity, approval="ACCEPTED")
    _exchange = _tenant.get_exchange()
    assert _exchange, "Must have a exchange first"

    _sponsor = Sponsor(CONFIG.SPONSOR_INDEX)

    _exchange = _tenant.get_exchange()
    assert _tenant.is_exchange_approved(), "exchange must be approved first"

    _project = _venture.get_project(CONFIG.PROJECT_INDEX)
    if not _project:
        _project = _venture.create_project(CONFIG.PROJECT_INDEX)
    assert _project, "create project return must not null"
    logger.info("==========  Project(%u) %s: %s(%s) Done ==========",
                CONFIG.PROJECT_INDEX, _project.project_name,
                _project.full_name, _project.short_name)

    sponsor_id = _venture.query_sponsor_id(_sponsor.name)
    print("sponsor id ============>", sponsor_id)

    for app in _venture.list_applications():
        _venture.set_sponsor(sponsor_id, app.id)

    app_id = _sponsor.query_project_application_id(_project.project_name)
    if app_id:
        _sponsor.sponsor_project(app_id)
    _project = _venture.update_project_info(CONFIG.PROJECT_INDEX)
    assert _project
    logger.info(
        "==========  Sponsor(%u) $$$ Project(%u) %s: %s(%s) Done ==========" %
        (CONFIG.SPONSOR_INDEX, CONFIG.PROJECT_INDEX, _project.project_name,
         _project.full_name, _project.short_name))

    for config in _staff.get_coins_config_list():
        if config.coin_id == _project.coin_id:
            print("%s config id:%s" % (_project.coin_id, config.id))
            _staff.init_coin(usdt_price=1, config_id=config.id)
            _staff.config_coin_rechargable(config.id, rechargeable=True)
            _staff.config_coin_withdrawable(config.id, withdrawable=True)
    logger.info("==========  Init Project(%u) %s: %s(%s) Done  ==========" %
                (CONFIG.PROJECT_INDEX, _project.project_name,
                 _project.full_name, _project.short_name))

    _venture.contacts(project_id=_project.project_id,
                      exchange_id=_exchange.exchange_id,
                      sponsor="venture")

    for contact in _tenant.list_contacts(_exchange.exchange_id,
                                         status="pending"):
        _tenant.contact_accept(contact_id=contact.id, status="accepted")
    logger.info("==========  Venture(%u) contact Tenant(%u) Done  ==========" %
                (CONFIG.VENTURE_INDEX, CONFIG.TENANT_INDEX))
def setup():
    return Staff(CONFIG.STAFF_INDEX), Tenant(CONFIG.TENANT_INDEX)
def main():
    logger.info("========== Init USDT Start ==========")

    _staff = Staff(CONFIG.STAFF_INDEX)
    logger.info("==========  Staff(%u) ready  ==========" % CONFIG.STAFF_INDEX)

    _main = Main(CONFIG.MAIN_INDEX)
    _main.request_individual_cert()
    _staff.verify_individual(identity=_main.identity, approval="ACCEPTED")
    logger.info("==========  Main(%u) ready  ==========" % CONFIG.MAIN_INDEX)

    sponsor_info = get_templated_attrs(Sponsor, CONFIG.SPONSOR_INDEX)
    logger.info("template result: ", sponsor_info)
    if _staff.create_sponsor(**sponsor_info):
        _sponsor = Sponsor(CONFIG.SPONSOR_INDEX)
    else:
        assert 0, "staff create sponsor failed!"
    logger.info("==========  Sponsor(%u) Done  ==========" % CONFIG.SPONSOR_INDEX)

    _venture = Venture(1)
    _venture.request_individual_cert()
    _staff.verify_individual(identity=_venture.identity, approval="ACCEPTED")
    assert _venture.audit_accepted()
    logger.info("==========  Venture(%u) Done  ==========" % CONFIG.VENTURE_INDEX)
    project_name = "泰达币"
    full_name="Tether"
    short_name = "USDT"
    USDT_PRJ = {
            'project_name': project_name,
            'description': f'USDT almost is USD',
            'official_website': 'https://tether.to/',
            'white_paper_key': f'1234555',
            'area_code': '+86',
            'project_poster_key': "1234555",
            'cellphone': '13510022445',
            'telephone': '12874846',
            'email': '*****@*****.**',
            'full_name': full_name,
            'short_name': short_name,
            'issue_price': '2.24545',
            'issued_volume': '1000000',
            'circulation_volume': '1000000',
            'issued_date': '2018-08-08',
            "coin_logo_key": PHOTO_KEY,
            'blockchain_type': 'public_chain',
            'data_link': 'https://tether.to/',
            'block_browser': 'https://omniexplorer.info'
        }
    _project = _venture.create_project(attrs=USDT_PRJ)

    logger.info("==========  Project(%u) %s: %s(%s) Done ==========", CONFIG.PROJECT_INDEX, _project.project_name,
                _project.full_name,
                _project.short_name)

    sponsor_id = _venture.query_sponsor_id(_sponsor.name)
    logger.info("sponsor id:%s ============>" % sponsor_id)

    for app in _venture.list_applications():
        _venture.set_sponsor(sponsor_id, app.id)

    app_id = _sponsor.query_project_application_id(_project.project_name)
    if app_id:
        _sponsor.sponsor_project(app_id)

    _project = _venture.update_project_info(CONFIG.PROJECT_INDEX)

    logger.info("==========  Sponsor(%u) $$$ Project(%u) %s: %s(%s) Done =========="
                % (CONFIG.SPONSOR_INDEX, CONFIG.PROJECT_INDEX, _project.project_name, _project.full_name, _project.short_name))

    for config in _staff.get_coins_config_list():
        if config.coin_id == _project.coin_id:
            print("%s config id:%s" % (_project.coin_id, config.id))
            _staff.init_coin(usdt_price=1, config_id=config.id)
            _staff.config_coin_rechargable(config.id, rechargeable=True)
            _staff.config_coin_withdrawable(config.id, withdrawable=True)
    logger.info("==========  Init Project(%u) %s: %s(%s) Done  ==========" % (CONFIG.PROJECT_INDEX, _project.project_name,
                                                                              _project.full_name, _project.short_name))
    logger.info("========== Init USDT End ==========")
Example #18
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    for ban in _staff.list_banners():
        _staff.delete_banner(ban.id)

    for i, ban in enumerate(load_banners_json("web_front_banners")):
        _staff.add_banner(title=FRONT_PAGE_TITLE, platform="pc", position="homepage", banner=ban["key"], order=i,
                          url=FRONT_PAGE_URL, language="zh_cn", status=True)

    for i, ban in enumerate(load_banners_json("web_exchange_banners")):
        _staff.add_banner(title=FRONT_PAGE_TITLE, platform="pc", position="exchange_homepage", banner=ban["key"], order=i,
                          url=FRONT_PAGE_URL, language="zh_cn", status=True)

    for i, ban in enumerate(load_banners_json("app_front_banners")):
        _staff.add_banner(title=EXCHANGE_TITLE, platform="mobile", position="homepage", banner=ban["key"], order=i,
                          url=EXCHANGE_URL, language="zh_cn", status=True)

    for i, ban in enumerate(load_banners_json("app_exchange_banners")):
        _staff.add_banner(title=EXCHANGE_TITLE, platform="mobile", position="exchange_homepage", banner=ban["key"],
                          order=i, url=EXCHANGE_URL, language="zh_cn", status=True)

    for i, exchage in enumerate(exchange_items):
        _tenant = Tenant(i)
        for ban in _tenant.list_banners():
            _tenant.delete_banner(banner_id=ban.id)
        for ban in load_banners_json("web_exchange_private_banners"):
            _tenant.add_banner(title=EXCHANGE_INTERNAL_TITLE, url=EXCHANGE_INTERNAL_URL, banner=ban["key"])
Example #19
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    url, key = _staff.upload(CUR_DIR + "/data/white_paper_coin.pdf")
    print("white paper => url:%s key:%s" % (url, key))
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)

    with open(CUR_DIR + "/data/exchange_logos/photo.json", "r") as f:
        logos = json.loads(f.read())
        pprint(logos)

    assert len(logos) >= len(exchange_items), "Exchanges logo count is invalid"

    for i, exch in enumerate(exchange_items):
        _tenant = Tenant(i)
        exchange_logo = logos[i]
        _tenant.request_individual_cert()
        _staff.verify_individual(identity=_tenant.identity,
                                 approval="ACCEPTED")
        assert _tenant.audit_accepted(), "Audit not accepted!"
        _exchange = _tenant.get_exchange()
        if not _exchange:
            _exchange = _tenant.create_exchange(
                attrs=dict(exchange_name=exch["name"],
                           nationality=exch["nationality"],
                           tags=exch["tags"],
                           logo_url=exchange_logo["url"],
                           logo_key=exchange_logo["key"]))

        audits = _staff.query_audits_tenant(uid=_tenant.account_id,
                                            status="audit")

        for audit in audits:
            print("audit.id:", audit.id)
            _staff.audits_tenants(task_id=audit.id, approval="approved")

            result = _staff.get_tenant_indiv_audits_result(audit_id=audit.id)
            assert result.audit_status == "approved"

        re_audits = _staff.query_audits_tenant(uid=_tenant.account_id,
                                               status="re_audit")
        for re_audit in re_audits:
            _staff.reaudits_tenants(task_id=re_audit.id, approval="approved")

            result = _staff.get_tenant_indiv_re_audits_result(
                audit_id=re_audit.id)
            assert result.re_status == "approved"

        if _tenant.is_exchange_approved():
            _exchange = _tenant.update_exchange_info()
        else:
            assert 0, "exchange should be approved here"

        logger.info("==========  exchange_id:%s ready ==========" %
                    _exchange.exchange_id)
def setup():
    logger.info("++  Multi Market  ++")

    _staff = Staff(CONFIG.STAFF_INDEX)
    logger.info("==========  Staff(%u) ready  ==========" % CONFIG.STAFF_INDEX)

    for item in _staff.list_tags():
        if item.name == CONFIG.MY_TAG:
            break
    else:
        _staff.create_tag(tag=CONFIG.MY_TAG,
                          other_language=[{
                              "key": "英语",
                              "value": "public_chain"
                          }])
    logger.info("==========  tag < %s > ready  ==========" % CONFIG.MY_TAG)

    _main = Main(CONFIG.MAIN_INDEX)
    _main.request_individual_cert()
    _staff.verify_individual(identity=_main.identity, approval="approved")
    logger.info("==========  Main(%u) ready  ==========" % CONFIG.MAIN_INDEX)

    sponsor_info = get_templated_attrs(Sponsor, CONFIG.SPONSOR_INDEX)
    logger.info("template result: ", sponsor_info)
    if _staff.create_sponsor(**sponsor_info):
        _sponsor = Sponsor(CONFIG.SPONSOR_INDEX)
    else:
        assert 0, "staff create sponsor failed!"
    logger.info("==========  Sponsor(%u) Done  ==========" %
                CONFIG.SPONSOR_INDEX)

    _tenant = Tenant(CONFIG.TENANT_INDEX)
    _tenant.request_individual_cert()
    _staff.verify_individual(identity=_tenant.identity, approval="approved")
    assert _tenant.audit_accepted()
    logger.info("==========  Tenant(%u) Create Done  ==========" %
                CONFIG.TENANT_INDEX)

    _exchange = _tenant.get_exchange()
    if not _exchange:
        _exchange = _tenant.create_exchange()

    audits = _staff.query_audits_tenant(uid=_tenant.account_id, status="audit")

    for audit in audits:
        _staff.audits_tenants(task_id=audit.id, approval="approved")

        result = _staff.get_tenant_indiv_audits_result(audit_id=audit.id)
        assert result.audit_status == "approved"

    re_audits = _staff.query_audits_tenant(uid=_tenant.account_id,
                                           status="re_audit")
    for re_audit in re_audits:
        _staff.reaudits_tenants(task_id=re_audit.id, approval="approved")

        result = _staff.get_tenant_indiv_re_audits_result(audit_id=re_audit.id)
        assert result.re_status == "approved"

    if _tenant.is_exchange_approved():
        _exchange = _tenant.update_exchange_info()
    else:
        assert 0, "exchange should be approved here"

    logger.info("==========  exchange_id:%s ready ==========" %
                (_exchange.exchange_id))

    _venture = Venture(CONFIG.VENTURE_INDEX)
    _venture.request_individual_cert()
    _staff.verify_individual(identity=_venture.identity, approval="approved")
    assert _venture.audit_accepted()
    logger.info("==========  Venture(%u) Done  ==========" %
                CONFIG.VENTURE_INDEX)

    _project = _venture.get_project(CONFIG.PROJECT_INDEX)
    if not _project:
        _project = _venture.create_project(CONFIG.PROJECT_INDEX)

    logger.info("==========  Project(%u) %s: %s(%s) Done ==========",
                CONFIG.PROJECT_INDEX, _project.project_name,
                _project.full_name, _project.short_name)

    sponsor_id = _venture.query_sponsor_id(_sponsor.name)
    logger.info("sponsor id:%s ============>" % sponsor_id)

    for app in _venture.list_applications():
        _venture.set_sponsor(sponsor_id, app.id)

    app_id = _sponsor.query_project_application_id(_project.project_name)
    if app_id:
        _sponsor.sponsor_project(app_id)

    _project = _venture.update_project_info(CONFIG.PROJECT_INDEX)

    logger.info(
        "==========  Sponsor(%u) $$$ Project(%u) %s: %s(%s) Done ==========" %
        (CONFIG.SPONSOR_INDEX, CONFIG.PROJECT_INDEX, _project.project_name,
         _project.full_name, _project.short_name))

    for config in _staff.get_coins_config_list():
        if config.coin_id == _project.coin_id:
            print("%s config id:%s" % (_project.coin_id, config.id))
            _staff.init_coin(usdt_price=1, config_id=config.id)
            _staff.config_coin_rechargable(config.id, rechargeable=True)
            _staff.config_coin_withdrawable(config.id, withdrawable=True)
    logger.info("==========  Init Project(%u) %s: %s(%s) Done  ==========" %
                (CONFIG.PROJECT_INDEX, _project.project_name,
                 _project.full_name, _project.short_name))

    _venture.contacts(project_id=_project.project_id,
                      exchange_id=_exchange.exchange_id,
                      sponsor="venture")

    for contact in _tenant.list_contacts(_exchange.exchange_id,
                                         status="pending"):
        print("contact_id ====================>", contact.id)
        _tenant.contact_accept(contact_id=contact.id, status="accepted")
    logger.info("==========  Venture(%u) contact Tenant(%u) Done  ==========" %
                (CONFIG.VENTURE_INDEX, CONFIG.TENANT_INDEX))

    usdt_id = _venture.get_usdt_coin_id()
    _market = _tenant.get_market(buy=usdt_id, sell=_project.coin_id)
    _faucet = Faucet(_tenant.token_mgr.token,
                     _tenant.api_account.api_client.configuration.host)
    if not _market:
        _faucet.free_charge(coin_id=_venture.get_usdt_coin_id(),
                            amount=10000000000)
        logger.info(
            "==========  Faucet(%s) charge Tenant(%u) Done ==========" %
            (CONFIG.FAUCET_INDEX, CONFIG.TENANT_INDEX))
        _market, order_id = _tenant.create_market(usdt_id, _project.coin_id,
                                                  "6", "0")
    logger.info("==========  Tenant(%u) create Market(%s) Done ==========" %
                (CONFIG.TENANT_INDEX, _market.market_id))

    logger.info("========== Multi Market End ==========")
    return _staff, _tenant, _venture, _sponsor, _faucet, _exchange