Ejemplo n.º 1
0
    def test_simple(self):
        vh0 = VersionedSimpleHeader(SimpleHeaderV0(0, 123))
        barray = vh0.serialize(bytearray())

        bb = ByteBuffer(barray)
        vh0d = VersionedSimpleHeader.deserialize(bb)
        h0d = vh0d.header

        self.assertEqual(0, h0d.version)
        self.assertEqual(123, h0d.value)

        vh1 = VersionedSimpleHeader(SimpleHeaderV1(1, 456, bytes(32)))
        barray = vh1.serialize(bytearray())

        bb = ByteBuffer(barray)
        vh1d = VersionedSimpleHeader.deserialize(bb)
        h1d = vh1d.header

        self.assertEqual(1, h1d.version)
        self.assertEqual(456, h1d.value)
        self.assertEqual(bytes(32), h1d.hash_trie)

        # Old versioned serializer cannot serialize new data
        with self.assertRaises(ValueError):
            vh = VersionedSimpleHeaderOld(SimpleHeaderV1(1, 456, bytes(32)))
            vh.serialize(bytearray())

        # Old versioned serializer cannot deserialize new data
        with self.assertRaises(ValueError):
            bb = ByteBuffer(barray)
            vhd = VersionedSimpleHeaderOld.deserialize(bb)
Ejemplo n.º 2
0
    def test_transaction(self):
        id1 = Identity.create_random_identity()
        acc2 = Address.create_random_account()

        tx = create_random_test_transaction(id1, acc2)

        barray = tx.serialize(bytearray())

        bb = ByteBuffer(barray)
        tx1 = Transaction.deserialize(bb)
        self.assertEqual(bb.remaining(), 0)
        self.assertEqual(tx, tx1)
        self.assertTrue(tx1.verify_signature([id1.get_recipient()]))
Ejemplo n.º 3
0
    def test_simple(self):
        m = dict()
        m[0] = True
        m[1] = False
        m[2] = False

        md = MapData(m)

        bmd = md.serialize(bytearray())

        bb = ByteBuffer(bmd)
        md1 = MapData.deserialize(bb)
        self.assertEqual(md.m, md1.m)
        self.assertEqual(len(md1.m), 3)