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_decode_invalid_metadata_v1(self):
metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v1_hex))
self.assertRaises(Exception, metadata_decoder.decode())
def setUpClass(cls):
RuntimeConfiguration().clear_type_registry()
RuntimeConfiguration().update_type_registry(load_type_registry_preset("default"))
RuntimeConfiguration().update_type_registry(load_type_registry_preset("kusama"))
RuntimeConfiguration().set_active_spec_version_id(1045)
cls.metadata_decoder = MetadataDecoder(ScaleBytes(metadata_1045_hex))
cls.metadata_decoder.decode()
def test_decode_metadata_v1(self):
metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v1_hex))
metadata_decoder.decode()
self.assertEqual(metadata_decoder.version.value, "MetadataV1Decoder")
def test_all_scale_type_supported_v2(self):
metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v2_hex))
metadata_decoder.decode()
self.assertEqual(metadata_decoder.version.value, "MetadataV2Decoder")
for module in metadata_decoder.metadata.modules:
if module.calls:
for call in module.calls:
for arg in call.args:
decoder_class = ScaleDecoder.get_decoder_class(arg.type, ScaleBytes('0x00'))
self.assertIsNotNone(decoder_class, msg='{} is not supported by metadata'.format(arg.type))
def test_decode_metadata_v3(self):
metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v3_hex))
metadata_decoder.decode()
self.assertEqual(metadata_decoder.version.value, "MetadataV3Decoder")
def setUpClass(cls):
RuntimeConfiguration().clear_type_registry()
RuntimeConfiguration().update_type_registry(load_type_registry_preset("default"))
RuntimeConfiguration().update_type_registry(load_type_registry_preset("kusama"))
RuntimeConfiguration().set_active_spec_version_id(1045)
cls.metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v10_hex))
cls.metadata_decoder.decode()
def test_all_scale_type_supported_v1(self):
metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v1_hex))
metadata_decoder.decode()
self.assertEqual(metadata_decoder.version.value, "MetadataV1Decoder")
for module in metadata_decoder.metadata.modules:
if module.calls:
for call in module.calls:
for arg in call.args:
decoder_class = ScaleDecoder.get_decoder_class(arg.type, ScaleBytes('0x00'))
self.assertIsNotNone(decoder_class, msg='{} is not supported by metadata'.format(arg.type))
def test_decode_metadata_v2(self):
metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v2_hex))
metadata_decoder.decode()
self.assertEqual(metadata_decoder.version.value, "MetadataV2Decoder")
def __init__(self, data, metadata=None, **kwargs):
assert (not metadata or type(metadata) == MetadataDecoder)
self.metadata = metadata
self.elements = []
super().__init__(data, metadata=metadata, **kwargs)
def on_post(self, req, resp):
metadata = MetadataDecoder(ScaleBytes(req.media.get('result')))
resp.status = falcon.HTTP_200
resp.media = metadata.process()