Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_compact_u32_4bytes(self):
obj = ScaleDecoder.get_decoder_class('Compact')
obj.encode(1000000)
self.assertEqual(str(obj.data), "0x02093d00")
def test_compact_u32_1byte(self):
obj = ScaleDecoder.get_decoder_class('Compact', ScaleBytes("0x18"))
obj.decode()
self.assertEqual(obj.value, 6)
})
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"])
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')))
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)
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())
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())
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)