Esempio n. 1
0
class TestEWalletController(unittest.TestCase):
    def setUp(self):
        self.pwallet = PersistentWallet(None, True)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        adm = self.model.get_asset_definition_manager()

        # make sure you have the asset 'testobc' in your testnet.wallet !!
        self.asset = adm.get_asset_by_moniker('testobc')
        self.color_spec = self.asset.get_color_set().get_data()[0]

        self.wc = WalletController(self.model)
        self.ewc = EWalletController(self.model, self.wc)

        def null(a):
            pass

        self.wc.publish_tx = null

    def test_resolve_color_spec(self):
        self.cd = self.ewc.resolve_color_spec('')
        self.assertRaises(KeyError, self.ewc.resolve_color_spec, 'nonexistent')
        self.assertTrue(isinstance(self.cd, ColorDefinition))
        self.assertEqual(self.cd.get_color_id(), 0)

    def test_select_inputs(self):
        cv = SimpleColorValue(colordef=UNCOLORED_MARKER, value=10000000000000)
        self.assertRaises(InsufficientFundsError, self.ewc.select_inputs, cv)

    def test_tx_spec(self):
        alice_cv = {'color_spec': self.color_spec, 'value': 10}
        bob_cv = {'color_spec': "", 'value': 500}
        alice_offer = MyEOffer(None, alice_cv, bob_cv)
        bob_offer = MyEOffer(None, bob_cv, alice_cv)
        bob_etx = self.ewc.make_etx_spec(bob_cv, alice_cv)
        self.assertTrue(isinstance(bob_etx, ETxSpec))
        for target in bob_etx.targets:
            # check address
            address = target[0]
            self.assertTrue(isinstance(address, type(u"unicode")))
            # TODO check address is correct format

            # check color_spec
            color_spec = target[1]
            self.assertTrue(isinstance(color_spec, type("str")))
            color_spec_parts = len(color_spec.split(":"))
            self.assertTrue(color_spec_parts == 4 or color_spec_parts == 1)

            # check value
            value = target[2]
            self.assertTrue(isinstance(value, type(10)))
        signed = self.ewc.make_reply_tx(bob_etx, alice_cv, bob_cv)
        self.assertTrue(isinstance(signed, RawTxSpec))

        self.ewc.publish_tx(signed, alice_offer)

        alice_etx = self.ewc.make_etx_spec(alice_cv, bob_cv)
        self.assertTrue(isinstance(alice_etx, ETxSpec))
        for target in alice_etx.targets:
            # check address
            address = target[0]
            self.assertTrue(isinstance(address, type(u"unicode")))
            # TODO check address is correct format

            # check color_spec
            color_spec = target[1]
            self.assertTrue(isinstance(color_spec, type("str")))
            color_spec_parts = len(color_spec.split(":"))
            self.assertTrue(color_spec_parts == 4 or color_spec_parts == 1)

            # check value
            value = target[2]
            self.assertTrue(isinstance(value, type(10)))
        signed = self.ewc.make_reply_tx(alice_etx, bob_cv, alice_cv)
        self.assertTrue(isinstance(signed, RawTxSpec))

        oets = OperationalETxSpec(self.model, self.ewc)
        oets.set_our_value_limit(bob_cv)
        oets.prepare_inputs(alice_etx)
        zero = SimpleColorValue(colordef=UNCOLORED_MARKER, value=0)
        self.assertRaises(ZeroSelectError, oets.select_coins, zero)
        toomuch = SimpleColorValue(colordef=UNCOLORED_MARKER,
                                   value=10000000000000)
        self.assertRaises(InsufficientFundsError, oets.select_coins, toomuch)
Esempio n. 2
0
class TestEWalletController(unittest.TestCase):

    def setUp(self):
        self.path = ":memory:"
        self.config = {
            'hdw_master_key':
                '91813223e97697c42f05e54b3a85bae601f04526c5c053ff0811747db77cfdf5f1accb50b3765377c379379cd5aa512c38bf24a57e4173ef592305d16314a0f4',
            'testnet': True,
            'ccc': {'colordb_path' : self.path},
            }
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.wc = WalletController(self.model)

        self.ewc = EWalletController(self.model, self.wc)
        self.bcolorset =self.ewc.resolve_color_spec('')
        self.cspec = "obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"

    def add_coins(self):
        self.config['asset_definitions'] = [
            {"color_set": [""], "monikers": ["bitcoin"], "unit": 100000000},  
            {"color_set": [self.cspec], "monikers": ['test'], "unit": 1},]
        self.config['hdwam'] = {
            "genesis_color_sets": [ 
                [self.cspec],
                ],
            "color_set_states": [
                {"color_set": [""], "max_index": 1},
                {"color_set": [self.cspec], "max_index": 7},
                ]
            }
        self.config['bip0032'] = True
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.ewc.model = self.model
        self.wc.model = self.model
        # modify model colored coin context, so test runs faster
        ccc = self.model.ccc
        cdbuilder = ColorDataBuilderManager(
            ccc.colormap, ccc.blockchain_state, ccc.cdstore,
            ccc.metastore, AidedColorDataBuilder)

        ccc.colordata = ThinColorData(
            cdbuilder, ccc.blockchain_state, ccc.cdstore, ccc.colormap)

        # need to query the blockchain
        self.model.utxo_man.update_all()

        adm = self.model.get_asset_definition_manager()
        asset = adm.get_asset_by_moniker('test')
        cq = self.model.make_coin_query({"asset": asset})
        utxo_list = cq.get_result()


    def test_resolve_color_spec(self):
        self.assertRaises(InvalidColorIdError,
                          self.ewc.resolve_color_spec, 'nonexistent')
        self.assertTrue(isinstance(self.bcolorset, ColorSet))
        self.assertEqual(self.bcolorset.color_id_set, set([0]))

    def test_select_inputs(self):
        cv = SimpleColorValue(colordef=UNCOLORED_MARKER, value=1)
        self.assertRaises(InsufficientFundsError, self.ewc.select_inputs, cv)
        
    def test_tx_spec(self):
        self.add_colors()

        our = SimpleColorValue(colordef=UNCOLORED_MARKER, value=500)
        colormap = self.model.get_color_map()
        colordef = colormap.get_color_def(self.cspec)
        their = SimpleColorValue(colordef=colordef, value=10)
        etx = self.ewc.make_etx_spec(our, their)
        self.assertTrue(isinstance(etx, ETxSpec))
        for target in etx.targets:
            self.assertTrue(isinstance(target, ColorTarget))
        signed = self.ewc.make_reply_tx(etx, our, their)
        self.assertTrue(isinstance(signed, RawTxSpec))

        self.ewc.publish_tx(signed)

        etx = self.ewc.make_etx_spec(their, our)
        self.assertTrue(isinstance(etx, ETxSpec))
        for target in etx.targets:
            self.assertTrue(isinstance(target, ColorTarget))
        signed = self.ewc.make_reply_tx(etx, their, our)
        self.assertTrue(isinstance(signed, RawTxSpec))

        oets = OperationalETxSpec(self.model, self.ewc)
        zero = SimpleColorValue(colordef=UNCOLORED_MARKER, value=0)
        self.assertRaises(ZeroSelectError, oets.select_coins, zero)
        toomuch = SimpleColorValue(colordef=UNCOLORED_MARKER, value=10000000000000)
        self.assertRaises(InsufficientFundsError, oets.select_coins, toomuch)
Esempio n. 3
0
class TestEWalletController(unittest.TestCase):
    def setUp(self):
        self.path = ":memory:"
        self.config = {
            'hdw_master_key':
            '91813223e97697c42f05e54b3a85bae601f04526c5c053ff0811747db77cfdf5f1accb50b3765377c379379cd5aa512c38bf24a57e4173ef592305d16314a0f4',
            'testnet': True,
            'ccc': {
                'colordb_path': self.path
            },
        }
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.wc = WalletController(self.model)

        self.ewc = EWalletController(self.model, self.wc)
        self.bcolorset = self.ewc.resolve_color_spec('')
        self.cspec = "obc:03524a4d6492e8d43cb6f3906a99be5a1bcd93916241f759812828b301f25a6c:0:153267"

    def add_coins(self):
        self.config['asset_definitions'] = [
            {
                "color_set": [""],
                "monikers": ["bitcoin"],
                "unit": 100000000
            },
            {
                "color_set": [self.cspec],
                "monikers": ['test'],
                "unit": 1
            },
        ]
        self.config['hdwam'] = {
            "genesis_color_sets": [
                [self.cspec],
            ],
            "color_set_states": [
                {
                    "color_set": [""],
                    "max_index": 1
                },
                {
                    "color_set": [self.cspec],
                    "max_index": 7
                },
            ]
        }
        self.config['bip0032'] = True
        self.pwallet = PersistentWallet(self.path, self.config)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        self.ewc.model = self.model
        self.wc.model = self.model
        # modify model colored coin context, so test runs faster
        ccc = self.model.ccc
        cdbuilder = ColorDataBuilderManager(ccc.colormap, ccc.blockchain_state,
                                            ccc.cdstore, ccc.metastore,
                                            AidedColorDataBuilder)

        ccc.colordata = ThinColorData(cdbuilder, ccc.blockchain_state,
                                      ccc.cdstore, ccc.colormap)

        # need to query the blockchain
        self.model.utxo_man.update_all()

        adm = self.model.get_asset_definition_manager()
        asset = adm.get_asset_by_moniker('test')
        cq = self.model.make_coin_query({"asset": asset})
        utxo_list = cq.get_result()

    def test_resolve_color_spec(self):
        self.assertRaises(InvalidColorIdError, self.ewc.resolve_color_spec,
                          'nonexistent')
        self.assertTrue(isinstance(self.bcolorset, ColorSet))
        self.assertEqual(self.bcolorset.color_id_set, set([0]))

    def test_select_inputs(self):
        cv = SimpleColorValue(colordef=UNCOLORED_MARKER, value=1)
        self.assertRaises(InsufficientFundsError, self.ewc.select_inputs, cv)

    def test_tx_spec(self):
        self.add_colors()

        our = SimpleColorValue(colordef=UNCOLORED_MARKER, value=500)
        colormap = self.model.get_color_map()
        colordef = colormap.get_color_def(self.cspec)
        their = SimpleColorValue(colordef=colordef, value=10)
        etx = self.ewc.make_etx_spec(our, their)
        self.assertTrue(isinstance(etx, ETxSpec))
        for target in etx.targets:
            self.assertTrue(isinstance(target, ColorTarget))
        signed = self.ewc.make_reply_tx(etx, our, their)
        self.assertTrue(isinstance(signed, RawTxSpec))

        self.ewc.publish_tx(signed)

        etx = self.ewc.make_etx_spec(their, our)
        self.assertTrue(isinstance(etx, ETxSpec))
        for target in etx.targets:
            self.assertTrue(isinstance(target, ColorTarget))
        signed = self.ewc.make_reply_tx(etx, their, our)
        self.assertTrue(isinstance(signed, RawTxSpec))

        oets = OperationalETxSpec(self.model, self.ewc)
        zero = SimpleColorValue(colordef=UNCOLORED_MARKER, value=0)
        self.assertRaises(ZeroSelectError, oets.select_coins, zero)
        toomuch = SimpleColorValue(colordef=UNCOLORED_MARKER,
                                   value=10000000000000)
        self.assertRaises(InsufficientFundsError, oets.select_coins, toomuch)
Esempio n. 4
0
class TestEWalletController(unittest.TestCase):

    def setUp(self):
        self.pwallet = PersistentWallet(None, True)
        self.pwallet.init_model()
        self.model = self.pwallet.get_model()
        adm = self.model.get_asset_definition_manager()

        # make sure you have the asset 'testobc' in your testnet.wallet !!
        self.asset = adm.get_asset_by_moniker('testobc')
        self.color_spec = self.asset.get_color_set().get_data()[0]

        self.wc = WalletController(self.model)
        self.ewc = EWalletController(self.model, self.wc)

        def null(a):
            pass
        self.wc.publish_tx = null

    def test_resolve_color_spec(self):
        self.cd =self.ewc.resolve_color_spec('')
        self.assertRaises(KeyError, self.ewc.resolve_color_spec, 'nonexistent')
        self.assertTrue(isinstance(self.cd, ColorDefinition))
        self.assertEqual(self.cd.get_color_id(), 0)

    def test_select_inputs(self):
        cv = SimpleColorValue(colordef=UNCOLORED_MARKER, value=10000000000000)
        self.assertRaises(InsufficientFundsError, self.ewc.select_inputs, cv)
        
    def test_tx_spec(self):
        alice_cv = { 'color_spec' : self.color_spec, 'value' : 10 }
        bob_cv = { 'color_spec' : "", 'value' : 500 }
        alice_offer = MyEOffer(None, alice_cv, bob_cv)
        bob_offer = MyEOffer(None, bob_cv, alice_cv)
        bob_etx = self.ewc.make_etx_spec(bob_cv, alice_cv)
        self.assertTrue(isinstance(bob_etx, ETxSpec))
        for target in bob_etx.targets:
            # check address
            address = target[0]
            self.assertTrue(isinstance(address, type(u"unicode")))
            # TODO check address is correct format

            # check color_spec
            color_spec = target[1]
            self.assertTrue(isinstance(color_spec, type("str")))
            color_spec_parts = len(color_spec.split(":"))
            self.assertTrue(color_spec_parts == 4 or color_spec_parts == 1)

            # check value
            value = target[2]
            self.assertTrue(isinstance(value, type(10)))
        signed = self.ewc.make_reply_tx(bob_etx, alice_cv, bob_cv)
        self.assertTrue(isinstance(signed, RawTxSpec))

        self.ewc.publish_tx(signed, alice_offer)

        alice_etx = self.ewc.make_etx_spec(alice_cv, bob_cv)
        self.assertTrue(isinstance(alice_etx, ETxSpec))
        for target in alice_etx.targets:
            # check address
            address = target[0]
            self.assertTrue(isinstance(address, type(u"unicode")))
            # TODO check address is correct format

            # check color_spec
            color_spec = target[1]
            self.assertTrue(isinstance(color_spec, type("str")))
            color_spec_parts = len(color_spec.split(":"))
            self.assertTrue(color_spec_parts == 4 or color_spec_parts == 1)

            # check value
            value = target[2]
            self.assertTrue(isinstance(value, type(10)))
        signed = self.ewc.make_reply_tx(alice_etx, bob_cv, alice_cv)
        self.assertTrue(isinstance(signed, RawTxSpec))

        oets = OperationalETxSpec(self.model, self.ewc)
        oets.set_our_value_limit(bob_cv)
        oets.prepare_inputs(alice_etx)
        zero = SimpleColorValue(colordef=UNCOLORED_MARKER, value=0)
        self.assertRaises(ZeroSelectError, oets.select_coins, zero)
        toomuch = SimpleColorValue(colordef=UNCOLORED_MARKER, value=10000000000000)
        self.assertRaises(InsufficientFundsError, oets.select_coins, toomuch)