# Path: ngcccbase/color.py
# class ColoredCoinContext(object):
#     """Interface to the Colored Coin Library's various offerings.
#     Specifically, this object provides access to a storage mechanism
#     (store_conn, cdstore, metastore), the color mapping (colormap)
#     and color data (Thick Color Data)
#     """
#     def __init__(self, config, blockchain_state):
#         """Creates a Colored Coin Context given a config <config>
#         """
#         params = config.get('ccc', {})
#         self.blockchain_state = blockchain_state
#         self.testnet = config.get('testnet', False)
#         thin = config.get('thin', True)
# 
#         if thin:
#             color_data_class = ThinColorData
#             color_data_builder = AidedColorDataBuilder
#         else:
#             color_data_class = ThickColorData
#             color_data_builder = FullScanColorDataBuilder
#             
#         self.store_conn = DataStoreConnection(
#             params.get("colordb_path", "color.db"))
#         self.cdstore = ColorDataStore(self.store_conn.conn)
#         self.metastore = ColorMetaStore(self.store_conn.conn)
#         self.colormap = ColorMap(self.metastore)
#         
#         cdbuilder = ColorDataBuilderManager(
#             self.colormap, self.blockchain_state, self.cdstore,
#             self.metastore, color_data_builder)
# 
#         self.colordata = color_data_class(
#             cdbuilder, self.blockchain_state, self.cdstore, self.colormap)
# 
#     def raw_to_address(self, raw_address):
#         prefix = self.testnet and b'\x6f' or b"\0"
#         return hash160_sec_to_bitcoin_address(raw_address,
#                                               address_prefix=prefix)


import os
import unittest
from pycoin.encoding import (a2b_hashed_base58, from_bytes_32,
                             public_pair_to_hash160_sec)
from pycoin.ecdsa.secp256k1 import generator_secp256k1 as BasePoint
from ngcccbase.color import ColoredCoinContext
#!/usr/bin/env python





class TestColor(unittest.TestCase):

    def setUp(self):
        self.path = ":memory:"
        c = {
            'ccc': {'colordb_path': self.path},
            'testnet': False,
            }
        self.address = '5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF'
        self.ccc = ColoredCoinContext(c)

    def test_init(self):
        self.assertTrue(self.ccc.colordata)

    def test_raw_to_address(self):
        privkey = from_bytes_32(a2b_hashed_base58(self.address)[1:])
        pubkey = BasePoint * privkey
        raw = public_pair_to_hash160_sec(pubkey.pair(), False)
        addr = self.ccc.raw_to_address(raw)
        self.assertEqual(addr,'1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj')


if __name__ == '__main__':

# Path: ngcccbase/color.py
# class ColoredCoinContext(object):
#     """Interface to the Colored Coin Library's various offerings.
#     Specifically, this object provides access to a storage mechanism
#     (store_conn, cdstore, metastore), the color mapping (colormap)
#     and color data (Thick Color Data)
#     """
#     def __init__(self, config, blockchain_state):
#         """Creates a Colored Coin Context given a config <config>
#         """
#         params = config.get('ccc', {})
#         self.blockchain_state = blockchain_state
#         self.testnet = config.get('testnet', False)
#         thin = config.get('thin', True)
# 
#         if thin:
#             color_data_class = ThinColorData
#             color_data_builder = AidedColorDataBuilder
#         else:
#             color_data_class = ThickColorData
#             color_data_builder = FullScanColorDataBuilder
#             
#         self.store_conn = DataStoreConnection(
#             params.get("colordb_path", "color.db"))
#         self.cdstore = ColorDataStore(self.store_conn.conn)
#         self.metastore = ColorMetaStore(self.store_conn.conn)
#         self.colormap = ColorMap(self.metastore)
#         
#         cdbuilder = ColorDataBuilderManager(
#             self.colormap, self.blockchain_state, self.cdstore,
#             self.metastore, color_data_builder)
# 
#         self.colordata = color_data_class(
#             cdbuilder, self.blockchain_state, self.cdstore, self.colormap)
# 
#     def raw_to_address(self, raw_address):
#         prefix = self.testnet and b'\x6f' or b"\0"
#         return hash160_sec_to_bitcoin_address(raw_address,
#                                               address_prefix=prefix)


# Path: ngcccbase/tests/test_color.py
import os
import unittest
from pycoin.encoding import (a2b_hashed_base58, from_bytes_32,
                             public_pair_to_hash160_sec)
from pycoin.ecdsa.secp256k1 import generator_secp256k1 as BasePoint
from ngcccbase.color import ColoredCoinContext

#!/usr/bin/env python





class TestColor(unittest.TestCase):

    def setUp(self):
        self.path = ":memory:"
        c = {
            'ccc': {'colordb_path': self.path},
            'testnet': False,
            }
        self.address = '5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF'
        self.ccc = ColoredCoinContext(c)

    def test_init(self):
        self.assertTrue(self.ccc.colordata)

    def test_raw_to_address(self):
        privkey = from_bytes_32(a2b_hashed_base58(self.address)[1:])
        pubkey = BasePoint * privkey
        raw = public_pair_to_hash160_sec(pubkey.pair(), False)
        addr = self.ccc.raw_to_address(raw)
        self.assertEqual(addr,'1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj')


if __name__ == '__main__':

    unittest.main()