# Path: jmclient/jmclient/configure.py
# def load_test_config(**kwargs):
#     if "config_path" not in kwargs:
#         load_program_config(config_path=".", **kwargs)
#     else:
#         load_program_config(**kwargs)
# 
# def get_irc_mchannels():
#     SECTION_NAME = 'MESSAGING'
#     # FIXME: remove in future release
#     if jm_single().config.has_section(SECTION_NAME):
#         log.warning("Old IRC configuration detected. Please adopt your "
#                     "joinmarket.cfg as documented in 'docs/config-irc-"
#                     "update.md'. Support for the old setting will be removed "
#                     "in a future version.")
#         return _get_irc_mchannels_old()
# 
#     SECTION_NAME += ':'
#     irc_sections = []
#     for s in jm_single().config.sections():
#         if s.startswith(SECTION_NAME):
#             irc_sections.append(s)
#     assert irc_sections
# 
#     req_fields = [("host", str), ("port", int), ("channel", str), ("usessl", str)]
# 
#     configs = []
#     for section in irc_sections:
#         server_data = {}
# 
#         # check if socks5 is enabled for tor and load relevant config if so
#         try:
#             server_data["socks5"] = jm_single().config.get(section, "socks5")
#         except NoOptionError:
#             server_data["socks5"] = "false"
#         if server_data["socks5"].lower() == 'true':
#             server_data["socks5_host"] = jm_single().config.get(section, "socks5_host")
#             server_data["socks5_port"] = jm_single().config.get(section, "socks5_port")
# 
#         for option, otype in req_fields:
#             val = jm_single().config.get(section, option)
#             server_data[option] = otype(val)
#         server_data['btcnet'] = get_network()
#         configs.append(server_data)
#     return configs


import pytest
from jmdaemon.orderbookwatch import OrderbookWatch
from jmdaemon import IRCMessageChannel, fidelity_bond_cmd_list
from jmclient import get_irc_mchannels, load_test_config
from jmdaemon.protocol import JM_VERSION, ORDER_KEYS
from jmbase.support import hextobin
from jmclient.fidelity_bond import FidelityBondProof
     ("abcd|def"),
     ("abc| 0 a qvd"),
     ])
def test_ob(badtopic):
    ob = get_ob()
    topic = ("JoinMarket open outcry pit. /r/joinmarket Discussion in #joinmarket"
             "| 0 5 LATEST RELEASE v0.2.2. Useful new features. Update ASAP, and "
             "do not use pre-0.2.0! https://bitcointalk.org/index.php?topic=91911"
             "6.msg16714124#msg16714124")
    ob.on_set_topic(topic)
    #should not throw:
    ob.on_set_topic(badtopic)
    #test old version
    future_ver = str(JM_VERSION + 2)
    
    deprecated = topic.replace("| 0 5", "| 0 "+future_ver)
    ob.on_set_topic(deprecated)

@pytest.mark.parametrize(
    "counterparty, oid, ordertype, minsize, maxsize, txfee, cjfee, expected",
    [
        #good absoffer
        ("test", "0", "absoffer", "3000", "4000", "2", "300", True),
        #good reloffer
        ("test", "0", "reloffer", "3000", "4000", "2", "0.3", True),
        #dusty minsize OK
        ("test", "0", "reloffer", "1000", "4000", "2", "0.3", True),
        #invalid oid
        ("test", "-2", "reloffer", "3000", "4000", "2", "0.3", False),
        #invalid minsize

# Path: jmclient/jmclient/configure.py
# def load_test_config(**kwargs):
#     if "config_path" not in kwargs:
#         load_program_config(config_path=".", **kwargs)
#     else:
#         load_program_config(**kwargs)
# 
# def get_irc_mchannels():
#     SECTION_NAME = 'MESSAGING'
#     # FIXME: remove in future release
#     if jm_single().config.has_section(SECTION_NAME):
#         log.warning("Old IRC configuration detected. Please adopt your "
#                     "joinmarket.cfg as documented in 'docs/config-irc-"
#                     "update.md'. Support for the old setting will be removed "
#                     "in a future version.")
#         return _get_irc_mchannels_old()
# 
#     SECTION_NAME += ':'
#     irc_sections = []
#     for s in jm_single().config.sections():
#         if s.startswith(SECTION_NAME):
#             irc_sections.append(s)
#     assert irc_sections
# 
#     req_fields = [("host", str), ("port", int), ("channel", str), ("usessl", str)]
# 
#     configs = []
#     for section in irc_sections:
#         server_data = {}
# 
#         # check if socks5 is enabled for tor and load relevant config if so
#         try:
#             server_data["socks5"] = jm_single().config.get(section, "socks5")
#         except NoOptionError:
#             server_data["socks5"] = "false"
#         if server_data["socks5"].lower() == 'true':
#             server_data["socks5_host"] = jm_single().config.get(section, "socks5_host")
#             server_data["socks5_port"] = jm_single().config.get(section, "socks5_port")
# 
#         for option, otype in req_fields:
#             val = jm_single().config.get(section, option)
#             server_data[option] = otype(val)
#         server_data['btcnet'] = get_network()
#         configs.append(server_data)
#     return configs


# Path: jmdaemon/test/test_orderbookwatch.py
import pytest
from jmdaemon.orderbookwatch import OrderbookWatch
from jmdaemon import IRCMessageChannel, fidelity_bond_cmd_list
from jmclient import get_irc_mchannels, load_test_config
from jmdaemon.protocol import JM_VERSION, ORDER_KEYS
from jmbase.support import hextobin
from jmclient.fidelity_bond import FidelityBondProof

     ("abcd|def"),
     ("abc| 0 a qvd"),
     ])
def test_ob(badtopic):
    ob = get_ob()
    topic = ("JoinMarket open outcry pit. /r/joinmarket Discussion in #joinmarket"
             "| 0 5 LATEST RELEASE v0.2.2. Useful new features. Update ASAP, and "
             "do not use pre-0.2.0! https://bitcointalk.org/index.php?topic=91911"
             "6.msg16714124#msg16714124")
    ob.on_set_topic(topic)
    #should not throw:
    ob.on_set_topic(badtopic)
    #test old version
    future_ver = str(JM_VERSION + 2)
    
    deprecated = topic.replace("| 0 5", "| 0 "+future_ver)
    ob.on_set_topic(deprecated)

@pytest.mark.parametrize(
    "counterparty, oid, ordertype, minsize, maxsize, txfee, cjfee, expected",
    [
        #good absoffer
        ("test", "0", "absoffer", "3000", "4000", "2", "300", True),
        #good reloffer
        ("test", "0", "reloffer", "3000", "4000", "2", "0.3", True),
        #dusty minsize OK
        ("test", "0", "reloffer", "1000", "4000", "2", "0.3", True),
        #invalid oid
        ("test", "-2", "reloffer", "3000", "4000", "2", "0.3", False),
        #invalid minsize

        ("test", "2", "reloffer", "-3000", "4000", "2", "0.3", False),