Exemplo n.º 1
0
class RaidenConfigurationTestCase(unittest.TestCase):
    def setUp(self):
        temp_folder_path = Path(tempfile.gettempdir())
        RaidenConfigurationFile.FOLDER_PATH = temp_folder_path

        self.account = Account.create(passphrase="test_raiden_config")
        self.network = Network.get_by_name("goerli")
        self.ethereum_client_rpc_endpoint = "http://localhost:8545"

        self.configuration_file = RaidenConfigurationFile(
            account=self.account,
            network=self.network,
            ethereum_client_rpc_endpoint=self.ethereum_client_rpc_endpoint,
        )

        passphrase_file = PassphraseFile(self.configuration_file.passphrase_file_path)
        passphrase_file.store(self.account.passphrase)

    def test_can_save_configuration(self):
        self.configuration_file.save()
        self.assertTrue(self.configuration_file.path.exists())

    def test_can_create_configuration(self):
        self.configuration_file.save()
        all_configs = RaidenConfigurationFile.get_available_configurations()
        self.assertEqual(len(all_configs), 1)

    def tearDown(self):
        for config in RaidenConfigurationFile.get_available_configurations():
            config.passphrase_file_path.unlink()
            config.path.unlink()
Exemplo n.º 2
0
    def _run_setup(self, **kw):
        form = QuickSetupForm(endpoint=kw.get("endpoint"))
        if form.validate():
            self._send_status_update(
                "Generating new wallet and configuration file for raiden")

            network = Network.get_by_name(form.data["network"])
            url_or_infura_id = form.data["endpoint"].strip()

            if Infura.is_valid_project_id(url_or_infura_id):
                ethereum_rpc_provider = Infura.make(network, url_or_infura_id)
            else:
                ethereum_rpc_provider = EthereumRPCProvider(url_or_infura_id)

            account = Account.create()

            conf_file = RaidenConfigurationFile(
                account,
                network,
                ethereum_rpc_provider.url,
                routing_mode="pfs" if form.data["use_rsb"] else "local",
                enable_monitoring=form.data["use_rsb"],
            )
            conf_file.save()

            if network.FAUCET_AVAILABLE:
                self._run_funding(configuration_file=conf_file)
                self._send_redirect(
                    self.reverse_url("launch", conf_file.file_name))
            else:
                self._send_redirect(
                    self.reverse_url("account", conf_file.file_name))
        else:
            self._send_error_message(
                f"Failed to create account. Error: {form.errors}")
Exemplo n.º 3
0
    def _run_setup(self, **kw):
        account_file = kw.get("account_file")
        account = Account(account_file, passphrase=get_passphrase())
        form = QuickSetupForm(
            meta=dict(network=self.installer_settings.network),
            endpoint=kw.get("endpoint"))
        if form.validate():
            self._send_status_update(
                "Generating new wallet and configuration file for raiden")

            network = Network.get_by_name(self.installer_settings.network)
            infura_url_or_id = form.data["endpoint"].strip()
            ethereum_rpc_provider = Infura.make(network, infura_url_or_id)

            try:
                check_eth_node_responsivity(ethereum_rpc_provider.url)
            except ValueError as e:
                self._send_error_message(f"Ethereum node unavailable: {e}.")
                return

            conf_file = RaidenConfigurationFile(
                account.keystore_file_path,
                self.installer_settings,
                ethereum_rpc_provider.url,
                routing_mode=self.installer_settings.routing_mode,
                enable_monitoring=self.installer_settings.monitoring_enabled,
            )
            conf_file.save()

            self._send_redirect(
                self.reverse_url("account", conf_file.file_name))
        else:
            self._send_error_message(
                f"Failed to create account. Error: {form.errors}")
Exemplo n.º 4
0
 def config(self, patch_config_folder, test_account, infura, settings):
     config = RaidenConfigurationFile(
         test_account.keystore_file_path,
         settings,
         infura.url,
     )
     config.save()
     yield config
     config.path.unlink()
Exemplo n.º 5
0
def run_action_configuration_setup():
    account = prompt_account_selection()
    network = prompt_network_selection()

    ethereum_rpc_questions = [
        {
            "name": "will_use_infura",
            "type": "confirm",
            "default": True,
            "message": Messages.input_use_infura,
        },
        {
            "name": "infura_project_id",
            "type": "input",
            "message": Messages.input_ethereum_infura_project_id,
            "when": lambda answers: answers["will_use_infura"],
            "filter": lambda answer: answer.strip(),
            "validator": InfuraProjectIdValidator,
        },
        {
            "name": "ethereum_rpc_endpoint",
            "type": "input",
            "message": Messages.input_ethereum_rpc_endpoint,
            "when": lambda answers: not answers["will_use_infura"],
        },
    ]

    ethereum_rpc_answers = validate_prompt(ethereum_rpc_questions)

    if ethereum_rpc_answers["will_use_infura"]:
        project_id = ethereum_rpc_answers["infura_project_id"]
        client_rpc_endpoint = Infura.make(network, project_id).url
    else:
        client_rpc_endpoint = ethereum_rpc_answers["ethereum_rpc_endpoint"]

    user_deposit_contract_address = get_contract_address(
        network.chain_id, CONTRACT_USER_DEPOSIT)

    config = RaidenConfigurationFile(
        account=account,
        network=network,
        ethereum_client_rpc_endpoint=client_rpc_endpoint,
        user_deposit_contract_address=user_deposit_contract_address,
    )
    config.save()

    return main_prompt()
Exemplo n.º 6
0
    def _run_setup(self, **kw):
        account_file = kw.get("account_file")
        account = Account(account_file)
        passphrase_path = RaidenConfigurationFile.FOLDER_PATH.joinpath(
            f"{account.address}.passphrase.txt")
        passphrase_file = PassphraseFile(passphrase_path)
        passphrase = passphrase_file.retrieve()
        account.passphrase = passphrase
        form = QuickSetupForm(endpoint=kw.get("endpoint"),
                              network=kw.get("network"))
        if form.validate():
            self._send_status_update(
                "Generating new wallet and configuration file for raiden")

            network = Network.get_by_name(form.data["network"])
            url_or_infura_id = form.data["endpoint"].strip()

            if Infura.is_valid_project_id_or_endpoint(url_or_infura_id):
                ethereum_rpc_provider = Infura.make(network, url_or_infura_id)
            else:
                ethereum_rpc_provider = EthereumRPCProvider(url_or_infura_id)

            try:
                check_eth_node_responsivity(ethereum_rpc_provider.url)
            except ValueError as e:
                self._send_error_message(f"Ethereum node unavailable: {e}.")
                return

            conf_file = RaidenConfigurationFile(
                account,
                network,
                ethereum_rpc_provider.url,
                routing_mode="pfs" if form.data["use_rsb"] else "local",
                enable_monitoring=form.data["use_rsb"],
            )
            conf_file.save()

            if network.FAUCET_AVAILABLE:
                self._run_funding(configuration_file=conf_file)
                self._send_redirect(
                    self.reverse_url("launch", conf_file.file_name))
            else:
                self._send_redirect(
                    self.reverse_url("account", conf_file.file_name))
        else:
            self._send_error_message(
                f"Failed to create account. Error: {form.errors}")
Exemplo n.º 7
0
class RaidenConfigurationTestCase(unittest.TestCase):
    def setUp(self):
        RaidenConfigurationFile.FOLDER_PATH = TESTING_TEMP_FOLDER.joinpath(
            "config")

        self.account = Account.create(TESTING_KEYSTORE_FOLDER,
                                      passphrase="test_raiden_config")
        self.network = Network.get_by_name("goerli")
        self.settings = load_settings("demo_env")

        self.configuration_file = RaidenConfigurationFile(
            self.account.keystore_file_path,
            self.settings,
            "http://localhost:8545",
        )

    def test_can_save_configuration(self):
        self.configuration_file.save()
        self.assertTrue(self.configuration_file.path.exists())

    def test_can_create_configuration(self):
        self.configuration_file.save()
        all_configs = RaidenConfigurationFile.get_available_configurations(
            self.settings)
        self.assertEqual(len(all_configs), 1)

    def test_can_get_by_filename(self):
        self.configuration_file.save()
        try:
            RaidenConfigurationFile.get_by_filename(
                self.configuration_file.file_name)
        except ValueError:
            self.fail("should load configuration by file name")

    def test_cannot_get_by_not_existing_filename(self):
        with self.assertRaises(ValueError):
            RaidenConfigurationFile.get_by_filename("invalid")

    def test_cannot_get_config_for_different_settings(self):
        self.configuration_file.save()
        settings = load_settings("mainnet")
        all_configs = RaidenConfigurationFile.get_available_configurations(
            settings)
        self.assertEqual(len(all_configs), 0)

    def tearDown(self):
        for config in RaidenConfigurationFile.get_available_configurations(
                self.settings):
            config.path.unlink()
        self.account.keystore_file_path.unlink()