def test_runtime_id_cache_lookup(self): runtime_config = RuntimeConfigurationObject() runtime_config.update_type_registry(load_type_registry_preset("default")) runtime_config.update_type_registry(load_type_registry_preset("kusama")) self.assertEqual(1023, runtime_config.get_runtime_id_from_upgrades(54248)) self.assertEqual(1020, runtime_config.get_runtime_id_from_upgrades(0))
def test_set_head(self): runtime_config = RuntimeConfigurationObject() runtime_config.update_type_registry(load_type_registry_preset("default")) runtime_config.update_type_registry(load_type_registry_preset("kusama")) self.assertIsNone(runtime_config.get_runtime_id_from_upgrades(99999999998)) # Set head to block runtime_config.set_runtime_upgrades_head(99999999999) # Check updated cache self.assertGreater(runtime_config.get_runtime_id_from_upgrades(99999999998), 0)
def test_multiaddress_ss58_address_as_str_runtime_config(self): runtime_config = RuntimeConfigurationObject(ss58_format=2) runtime_config.update_type_registry(load_type_registry_preset("default")) obj = RuntimeConfiguration().create_scale_object('Multiaddress', runtime_config=runtime_config) ss58_address = "CdVuGwX71W4oRbXHsLuLQxNPns23rnSSiZwZPN4etWf6XYo" data = obj.encode(ss58_address) decode_obj = RuntimeConfiguration().create_scale_object('MultiAddress', data=data, runtime_config=runtime_config) self.assertEqual(decode_obj.decode(), ss58_address)
def test_multiple_instances(self): runtime_config1 = RuntimeConfigurationObject() runtime_config1.update_type_registry({ 'types': { 'MyNewType': 'Vec<u8>' } }) runtime_config2 = RuntimeConfigurationObject() self.assertIsNone(RuntimeConfigurationObject().get_decoder_class('MyNewType')) self.assertIsNotNone(runtime_config1.get_decoder_class('MyNewType')) self.assertIsNone(runtime_config2.get_decoder_class('MyNewType'))
def test_account_id_runtime_config(self): ss58_address = "CdVuGwX71W4oRbXHsLuLQxNPns23rnSSiZwZPN4etWf6XYo" public_key = '0x' + ss58_decode(ss58_address) runtime_config = RuntimeConfigurationObject(ss58_format=2) runtime_config.update_type_registry(load_type_registry_preset("default")) # Encode obj = RuntimeConfiguration().create_scale_object('AccountId', runtime_config=runtime_config) data = obj.encode(ss58_address) # Decode decode_obj = RuntimeConfiguration().create_scale_object('AccountId', data=data, runtime_config=runtime_config) decode_obj.decode() self.assertEqual(decode_obj.value, ss58_address) self.assertEqual(decode_obj.ss58_address, ss58_address) self.assertEqual(decode_obj.public_key, public_key)
def load_type_registry(self): runtime_config = RuntimeConfigurationObject() runtime_config.update_type_registry( load_type_registry_preset("metadata_types")) runtime_config.update_type_registry( load_type_registry_preset("default")) runtime_config.update_type_registry( load_type_registry_preset(self.chain)) self.runtime_config = runtime_config