Esempio n. 1
0
 def test_eth_rpc_address_property_prioritizes_cli_attr_over_scenario_definition(
         self, minimal_definition_dict):
     instance = SettingsConfig(minimal_definition_dict)
     instance._cli_rpc_address = "my_address"
     minimal_definition_dict["settings"][
         "eth-client-rpc-address"] = "http://ethnodes.io"
     assert instance.eth_client_rpc_address == "my_address"
Esempio n. 2
0
 def test_gas_price_strategy_property_returns_strategy_from_web3(
     self, strategy, expected_func, minimal_definition_dict
 ):
     """The gas price strategy is dynamically fetched."""
     minimal_definition_dict["settings"]["gas_price"] = strategy
     config = SettingsConfig(minimal_definition_dict, dummy_env)
     assert config.gas_price_strategy == expected_func
Esempio n. 3
0
    def __init__(
        self,
        yaml_path: pathlib.Path,
        data_path: pathlib.Path,
        environment: EnvironmentConfig,
    ) -> None:
        self._scenario_dir = None
        self.path = yaml_path
        # Use the scenario file as jinja template and only parse the yaml, afterwards.
        with yaml_path.open() as f:
            yaml_template = jinja2.Template(f.read(),
                                            undefined=jinja2.StrictUndefined)
            rendered_yaml = yaml_template.render(**asdict(environment))
            self._loaded = yaml.safe_load(rendered_yaml)

        self.settings = SettingsConfig(self._loaded, environment)
        self.settings.sp_root_dir = data_path
        self.token = TokenConfig(self._loaded,
                                 self.scenario_dir.joinpath("token.info"))
        deploy_token = self.token.address is None
        self.nodes = NodesConfig(
            self._loaded, environment="development" if deploy_token else None)
        self.scenario = ScenarioConfig(self._loaded)

        # If the environment sets a list of matrix servers, the nodes must not
        # choose other servers, so let's set the first server from the list as
        # default.
        self.nodes.dict["default_options"][
            "matrix-server"] = environment.matrix_servers[0]
        self.nodes.dict["default_options"][
            "environment-type"] = environment.environment_type
Esempio n. 4
0
 def test_gas_price_strategy_property_calls_getter_function(
         self, mock_get_strategy, minimal_yaml_dict):
     """The gas price strategy is dynamically fetched by calling
     :func:`get_gas_price_strategy` with :attr:`SettingsConfig.gas_price`."""
     config = SettingsConfig(minimal_yaml_dict)
     _ = config.gas_price_strategy
     mock_get_strategy.assert_called_once_with(config.gas_price)
Esempio n. 5
0
 def test_validate_raises_exception_for_invalid_gas_price_values(
         self, value, raises, minimal_yaml_dict):
     minimal_yaml_dict["settings"]["gas_price"] = value
     try:
         SettingsConfig(minimal_yaml_dict)
     except ScenarioConfigurationError:
         if not raises:
             pytest.fail("Raised ScenarioConfigurationError unexpectedly!")
Esempio n. 6
0
    def test_class_returns_expected_default_for_key(
        self, key, expected_defaults, minimal_definition_dict
    ):
        """If supported  keys are absent, sensible defaults are returned for them when accessing
        them as a class attribute."""
        config = SettingsConfig(minimal_definition_dict, dummy_env)

        try:
            actual = getattr(config, key)
        except AttributeError as e:
            raise AssertionError(e)

        assert expected_defaults["settings"][key] == actual
Esempio n. 7
0
 def test_gas_price_strategy_returns_a_callable(self, minimal_definition_dict):
     """The :attr:`SettingsConfig.gas_price_strategy` returns a callable."""
     config = SettingsConfig(minimal_definition_dict, dummy_env)
     assert callable(config.gas_price_strategy)
Esempio n. 8
0
 def test_settings_attr_returns_service_settings_config_instance(self, minimal_definition_dict):
     config = SettingsConfig(minimal_definition_dict, dummy_env)
     assert isinstance(config.services, ServiceSettingsConfig)
Esempio n. 9
0
 def test_settings_attr_returns_service_settings_config_instance(
         self, minimal_yaml_dict):
     config = SettingsConfig(minimal_yaml_dict)
     assert isinstance(config.services, ServiceSettingsConfig)
Esempio n. 10
0
 def test_is_subclass_of_config_mapping(self, minimal_yaml_dict):
     """The class is a subclass of :class:`ConfigMapping`."""
     assert isinstance(SettingsConfig(minimal_yaml_dict), ConfigMapping)
Esempio n. 11
0
 def test_chain_property_prioritizes_cli_attr_over_scenario_definition(
         self, minimal_definition_dict):
     minimal_definition_dict["chain"] = "kovan"
     instance = SettingsConfig(minimal_definition_dict)
     instance._cli_chain = "my_chain"
     assert instance.chain == "my_chain"