示例#1
0
class TestTxSpec(unittest.TestCase):
    def setUp(self):
        self.colordef1 = EPOBCColorDefinition(1, {
            'txhash': 'genesis',
            'outindex': 0
        })
        self.colordef2 = OBColorDefinition(2, {
            'txhash': 'genesis',
            'outindex': 0
        })
        self.cv1 = SimpleColorValue(colordef=self.colordef1,
                                    value=1,
                                    label='test')
        self.cv2 = SimpleColorValue(colordef=self.colordef1,
                                    value=2,
                                    label='test2')
        self.cv3 = SimpleColorValue(colordef=self.colordef2, value=1)
        self.ct1 = ColorTarget('address1', self.cv1)
        self.ct2 = ColorTarget('address2', self.cv2)
        self.ct3 = ColorTarget('address3', self.cv3)
        self.txspec = MockOpTxSpec([self.ct1, self.ct2])

    def test_repr(self):
        self.assertEqual(self.ct1.__repr__(), 'address1: test: 1')

    def test_get_colordef(self):
        self.assertEqual(self.ct1.get_colordef(), self.colordef1)

    def test_get_value(self):
        self.assertEqual(self.ct1.get_value(), self.cv1.get_value())

    def test_sum(self):
        cts = [self.ct1, self.ct2, ColorTarget('address3', self.cv2)]
        self.assertEqual(ColorTarget.sum(cts).get_value(), 5)
        self.assertEqual(ColorTarget.sum([]), 0)

    def test_opspec(self):
        self.assertTrue(self.txspec.is_monocolor())
        spec = MockOpTxSpec([self.ct1, self.ct2, self.ct3])
        self.assertFalse(spec.is_monocolor())

    def test_cspec(self):
        txo1 = ComposedTxSpec.TxOut(1, 'addr')
        txo2 = ComposedTxSpec.TxOut(2, 'addr2')
        outs = [txo1, txo2]
        c = ComposedTxSpec(None)
        c.add_txins([])
        c.add_txouts([txo1, txo2])
        self.assertEqual(c.get_txins(), [])
        self.assertEqual(c.get_txouts(), outs)
示例#2
0
 def test_compose_tx_spec(self):
     cv1 = SimpleColorValue(colordef=UNCOLORED_MARKER, value=1)
     cv2 = SimpleColorValue(colordef=self.obc, value=1)
     target1 = ColorTarget('addr1', cv1)
     target2 = ColorTarget('addr2', cv2)
     targets = [target1, target2]
     txspec = MockOpTxSpec(targets)
     self.assertTrue(
         isinstance(self.obc.compose_tx_spec(txspec), ComposedTxSpec))
     non = POBColorDefinition(2, {'txhash': 'something', 'outindex': 0})
     cv3 = SimpleColorValue(colordef=non, value=1)
     target3 = ColorTarget('addr3', cv3)
     targets = [cv3, cv2]
     txspec = MockOpTxSpec(targets)
     self.assertRaises(InvalidColorError, self.obc.compose_tx_spec, txspec)
示例#3
0
 def test_compose_genesis_tx_spec(self):
     txspec = MockOpTxSpec([])
     cv = SimpleColorValue(colordef=UNCOLORED_MARKER, value=1)
     self.assertRaises(InvalidTargetError,
                       OBColorDefinition.compose_genesis_tx_spec, txspec)
     target = ColorTarget('addr', cv)
     txspec = MockOpTxSpec([target])
     self.assertRaises(InvalidColorError,
                       OBColorDefinition.compose_genesis_tx_spec, txspec)
     cv = SimpleColorValue(colordef=GENESIS_OUTPUT_MARKER, value=1)
     target = ColorTarget('addr', cv)
     txspec = MockOpTxSpec([target])
     self.assertTrue(
         isinstance(OBColorDefinition.compose_genesis_tx_spec(txspec),
                    ComposedTxSpec))
示例#4
0
class TestTxSpec(unittest.TestCase):
    def setUp(self):
        self.colordef1 = EPOBCColorDefinition(
            1, {'txhash': 'genesis', 'outindex': 0})
        self.colordef2 = OBColorDefinition(
            2, {'txhash': 'genesis', 'outindex': 0})
        self.cv1 = SimpleColorValue(colordef=self.colordef1,
                                    value=1, label='test')
        self.cv2 = SimpleColorValue(colordef=self.colordef1,
                                    value=2, label='test2')
        self.cv3 = SimpleColorValue(colordef=self.colordef2,
                                    value=1)
        self.ct1 = ColorTarget('address1', self.cv1)
        self.ct2 = ColorTarget('address2', self.cv2)
        self.ct3 = ColorTarget('address3', self.cv3)
        self.txspec = MockOpTxSpec([self.ct1, self.ct2])

    def test_repr(self):
        self.assertEqual(self.ct1.__repr__(), 'address1: test: 1')

    def test_get_colordef(self):
        self.assertEqual(self.ct1.get_colordef(), self.colordef1)

    def test_get_value(self):
        self.assertEqual(self.ct1.get_value(), self.cv1.get_value())

    def test_sum(self):
        cts = [self.ct1, self.ct2, ColorTarget('address3',self.cv2)]
        self.assertEqual(ColorTarget.sum(cts).get_value(), 5)
        self.assertEqual(ColorTarget.sum([]), 0)

    def test_opspec(self):
        self.assertTrue(self.txspec.is_monocolor())
        spec = MockOpTxSpec([self.ct1, self.ct2, self.ct3])
        self.assertFalse(spec.is_monocolor())

    def test_cspec(self):
        txo1 = ComposedTxSpec.TxOut(1, 'addr')
        txo2 = ComposedTxSpec.TxOut(2, 'addr2')
        outs = [txo1, txo2]
        c = ComposedTxSpec(None)
        c.add_txins([])
        c.add_txouts([txo1, txo2])
        self.assertEqual(c.get_txins(), [])
        self.assertEqual(c.get_txouts(), outs)
示例#5
0
 def setUp(self):
     self.colordef1 = EPOBCColorDefinition(1, {
         'txhash': 'genesis',
         'outindex': 0
     })
     self.colordef2 = OBColorDefinition(2, {
         'txhash': 'genesis',
         'outindex': 0
     })
     self.cv1 = SimpleColorValue(colordef=self.colordef1,
                                 value=1,
                                 label='test')
     self.cv2 = SimpleColorValue(colordef=self.colordef1,
                                 value=2,
                                 label='test2')
     self.cv3 = SimpleColorValue(colordef=self.colordef2, value=1)
     self.ct1 = ColorTarget('address1', self.cv1)
     self.ct2 = ColorTarget('address2', self.cv2)
     self.ct3 = ColorTarget('address3', self.cv3)
     self.txspec = MockOpTxSpec([self.ct1, self.ct2])
示例#6
0
 def setUp(self):
     self.colordef1 = EPOBCColorDefinition(
         1, {'txhash': 'genesis', 'outindex': 0})
     self.colordef2 = OBColorDefinition(
         2, {'txhash': 'genesis', 'outindex': 0})
     self.cv1 = SimpleColorValue(colordef=self.colordef1,
                                 value=1, label='test')
     self.cv2 = SimpleColorValue(colordef=self.colordef1,
                                 value=2, label='test2')
     self.cv3 = SimpleColorValue(colordef=self.colordef2,
                                 value=1)
     self.ct1 = ColorTarget('address1', self.cv1)
     self.ct2 = ColorTarget('address2', self.cv2)
     self.ct3 = ColorTarget('address3', self.cv3)
     self.txspec = MockOpTxSpec([self.ct1, self.ct2])
示例#7
0
 def test_sum(self):
     cts = [self.ct1, self.ct2, ColorTarget('address3', self.cv2)]
     self.assertEqual(ColorTarget.sum(cts).get_value(), 5)
     self.assertEqual(ColorTarget.sum([]), 0)
示例#8
0
 def test_sum(self):
     cts = [self.ct1, self.ct2, ColorTarget('address3',self.cv2)]
     self.assertEqual(ColorTarget.sum(cts).get_value(), 5)
     self.assertEqual(ColorTarget.sum([]), 0)