How to use the scalecodec.base.ScaleDecoder.get_decoder_class function in scalecodec

To help you get started, we’ve selected a few scalecodec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkascan / py-scale-codec / test / test_type_encoding.py View on Github external
def test_compact_u32_4bytes(self):

        obj = ScaleDecoder.get_decoder_class('Compact')
        obj.encode(1000000)
        self.assertEqual(str(obj.data), "0x02093d00")
github polkascan / py-scale-codec / test / test_scale_types.py View on Github external
def test_compact_u32_1byte(self):
        obj = ScaleDecoder.get_decoder_class('Compact', ScaleBytes("0x18"))
        obj.decode()
        self.assertEqual(obj.value, 6)
github polkascan / py-scale-codec / test / test_scale_types.py View on Github external
})

        obj = ScaleDecoder.get_decoder_class('CustomU32Set', ScaleBytes("0x0100000000000000"))
        self.assertRaises(RemainingScaleBytesNotEmptyException, obj.decode)

        obj = ScaleDecoder.get_decoder_class('CustomU32Set', ScaleBytes("0x01000000"))
        obj.decode()

        self.assertEqual(obj.value, ["Value1"])

        obj = ScaleDecoder.get_decoder_class('CustomU32Set', ScaleBytes("0x03000000"))
        obj.decode()

        self.assertEqual(obj.value, ["Value1", "Value2"])

        obj = ScaleDecoder.get_decoder_class('CustomU32Set', ScaleBytes("0x16000000"))
        obj.decode()

        self.assertEqual(obj.value, ["Value2", "Value3", "Value5"])
github polkascan / py-scale-codec / test / test_scale_types.py View on Github external
def test_dynamic_fixed_array_type_encode(self):
        obj = ScaleDecoder.get_decoder_class('[u32; 1]')
        self.assertEqual('0x0100000002000000', str(obj.encode([1, 2])))

        obj = ScaleDecoder.get_decoder_class('[u8; 3]')
        self.assertEqual('0x010203', str(obj.encode('0x010203')))
github polkascan / py-scale-codec / test / test_type_encoding.py View on Github external
def test_hexbytes_encode_decode(self):

        value = '0x5468697320697320612074657374'

        obj = ScaleDecoder.get_decoder_class('HexBytes')
        data = obj.encode(value)

        obj_check = ScaleDecoder.get_decoder_class('HexBytes', data)

        self.assertEqual(obj_check.decode(), value)
github polkascan / py-scale-codec / test / test_scale_types.py View on Github external
def test_dynamic_fixed_array_type_decode(self):
        obj = ScaleDecoder.get_decoder_class('[u32; 1]', data=ScaleBytes("0x01000000"))
        self.assertEqual([1], obj.decode())

        obj = ScaleDecoder.get_decoder_class('[u32; 3]', data=ScaleBytes("0x010000000200000003000000"))
        self.assertEqual([1, 2, 3], obj.decode())

        obj = ScaleDecoder.get_decoder_class('[u32; 0]', data=ScaleBytes(bytes()))
        self.assertEqual([], obj.decode())
github polkascan / py-scale-codec / test / test_scale_types.py View on Github external
def test_dynamic_fixed_array_type_decode(self):
        obj = ScaleDecoder.get_decoder_class('[u32; 1]', data=ScaleBytes("0x01000000"))
        self.assertEqual([1], obj.decode())

        obj = ScaleDecoder.get_decoder_class('[u32; 3]', data=ScaleBytes("0x010000000200000003000000"))
        self.assertEqual([1, 2, 3], obj.decode())

        obj = ScaleDecoder.get_decoder_class('[u32; 0]', data=ScaleBytes(bytes()))
        self.assertEqual([], obj.decode())
github polkascan / py-scale-codec / test / test_type_encoding.py View on Github external
def test_option_bytes_encode_decode(self):
        value = "Test"

        obj = ScaleDecoder.get_decoder_class('Option')
        data = obj.encode(value)

        obj_check = ScaleDecoder.get_decoder_class('Option', data)

        self.assertEqual(obj_check.decode(), value)