Exemplo n.º 1
0
    def test_generic_vote(self):
        runtime_config = RuntimeConfigurationObject(ss58_format=2)

        vote = runtime_config.create_scale_object('GenericVote')
        data = vote.encode({'aye': True, 'conviction': 'Locked2x'})

        self.assertEqual('0x82', data.to_hex())

        vote.decode(ScaleBytes('0x04'))

        self.assertEqual(vote.value, {'aye': False, 'conviction': 'Locked4x'})
    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)
Exemplo n.º 3
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_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))
Exemplo n.º 5
0
 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
    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'))
Exemplo n.º 7
0
    def setUpClass(cls):
        cls.runtime_config = RuntimeConfigurationObject()
        cls.runtime_config.update_type_registry(load_type_registry_preset("metadata_types"))

        module_path = os.path.dirname(__file__)
        cls.metadata_fixture_dict = load_type_registry_file(
            os.path.join(module_path, 'fixtures', 'metadata_hex.json')
        )
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    def setUpClass(cls):
        module_path = os.path.dirname(__file__)
        cls.metadata_fixture_dict = load_type_registry_file(
            os.path.join(module_path, 'fixtures', 'metadata_hex.json'))
        cls.runtime_config = RuntimeConfigurationObject(
            implements_scale_info=True)
        cls.runtime_config.update_type_registry(
            load_type_registry_preset("metadata_types"))

        cls.metadata_obj = cls.runtime_config.create_scale_object(
            'MetadataVersioned',
            data=ScaleBytes(cls.metadata_fixture_dict['V14']))
        cls.metadata_obj.decode()
Exemplo n.º 10
0
    def setUpClass(cls):
        module_path = os.path.dirname(__file__)

        # scale_info_defaults = load_type_registry_file(os.path.join(module_path, 'fixtures', 'scale_info_defaults.json'))

        cls.runtime_config = RuntimeConfigurationObject(ss58_format=42)
        cls.runtime_config.update_type_registry(
            load_type_registry_preset("metadata_types"))
        # cls.runtime_config.update_type_registry(scale_info_defaults)

        cls.metadata_fixture_dict = load_type_registry_file(
            os.path.join(module_path, 'fixtures', 'metadata_hex.json'))

        cls.metadata_obj = cls.runtime_config.create_scale_object(
            'MetadataVersioned',
            data=ScaleBytes(cls.metadata_fixture_dict['V14']))
        cls.metadata_obj.decode()

        cls.runtime_config.add_portable_registry(cls.metadata_obj)
 def setUpClass(cls):
     cls.runtime_config = RuntimeConfigurationObject()
     cls.runtime_config.clear_type_registry()
     cls.runtime_config.update_type_registry(load_type_registry_preset("metadata_types"))
     cls.runtime_config.update_type_registry(load_type_registry_preset("default"))