# Path: jmbase/jmbase/support.py
# def hextobin(h):
#     """Convert a hex string to bytes"""
#     return binascii.unhexlify(h.encode('utf8'))
# 
# Path: jmclient/jmclient/configure.py
# def jm_single():
#     return global_singleton


from jmbase import hextobin
from jmclient.configure import validate_address, load_test_config
from jmclient import jm_single
from bitcointx.wallet import CCoinAddress
from bitcointx import ChainParams
import jmbitcoin as btc
import json
import pytest
import os
testdir = os.path.dirname(os.path.realpath(__file__))

def address_valid_somewhere(addr):
    for x in ["bitcoin", "bitcoin/testnet", "bitcoin/regtest"]:
        btc.select_chain_params(x)
        if validate_address(addr)[0]:
            return True
    return False

def test_non_addresses(setup_addresses):
    #could flesh this out with other examples
    res, msg = validate_address(2)
    assert res == False, "Incorrectly accepted number"

def test_b58_invalid_addresses(setup_addresses):
    #none of these are valid as any kind of key or address
    with open(os.path.join(testdir,"base58_keys_invalid.json"), "r") as f:
        json_data = f.read()
    invalid_key_list = json.loads(json_data)
    for k in invalid_key_list:
        bad_key = k[0]
        res = address_valid_somewhere(bad_key)
        assert res == False, "Incorrectly validated address: " + bad_key

def test_b58_valid_addresses():
    with open(os.path.join(testdir,"base58_keys_valid.json"), "r") as f:

# Path: jmbase/jmbase/support.py
# def hextobin(h):
#     """Convert a hex string to bytes"""
#     return binascii.unhexlify(h.encode('utf8'))
# 
# Path: jmclient/jmclient/configure.py
# def jm_single():
#     return global_singleton


# Path: jmclient/test/test_valid_addresses.py
from jmbase import hextobin
from jmclient.configure import validate_address, load_test_config
from jmclient import jm_single
from bitcointx.wallet import CCoinAddress
from bitcointx import ChainParams
import jmbitcoin as btc
import json
import pytest
import os

testdir = os.path.dirname(os.path.realpath(__file__))

def address_valid_somewhere(addr):
    for x in ["bitcoin", "bitcoin/testnet", "bitcoin/regtest"]:
        btc.select_chain_params(x)
        if validate_address(addr)[0]:
            return True
    return False

def test_non_addresses(setup_addresses):
    #could flesh this out with other examples
    res, msg = validate_address(2)
    assert res == False, "Incorrectly accepted number"

def test_b58_invalid_addresses(setup_addresses):
    #none of these are valid as any kind of key or address
    with open(os.path.join(testdir,"base58_keys_invalid.json"), "r") as f:
        json_data = f.read()
    invalid_key_list = json.loads(json_data)
    for k in invalid_key_list:
        bad_key = k[0]
        res = address_valid_somewhere(bad_key)
        assert res == False, "Incorrectly validated address: " + bad_key

def test_b58_valid_addresses():
    with open(os.path.join(testdir,"base58_keys_valid.json"), "r") as f:

        json_data = f.read()