public EthereumClientIntegrationFixture()
        {
            var config = InitConfiguration();

            if (config != null)
            {
                var ethereumTestSection = config.GetSection("EthereumTestSettings");

                if (ethereumTestSection != null)
                {
                    var ethereumTestSettings = new EthereumTestSettings();
                    ethereumTestSection.Bind(ethereumTestSettings);
                    if (!string.IsNullOrEmpty(ethereumTestSettings.GethPath))
                    {
                        GethClientPath = ethereumTestSettings.GethPath;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.ParityPath))
                    {
                        ParityClientPath = ethereumTestSettings.ParityPath;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.HardhatPath))
                    {
                        HardhatClientPath = ethereumTestSettings.HardhatPath;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.HardhatParams))
                    {
                        HardhatParams = ethereumTestSettings.HardhatParams;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.AccountAddress))
                    {
                        AccountAddress = ethereumTestSettings.AccountAddress;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.AccountPrivateKey))
                    {
                        AccountPrivateKey = ethereumTestSettings.AccountPrivateKey;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.ChainId))
                    {
                        ChainId = BigInteger.Parse(ethereumTestSettings.ChainId);
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.ManagedAccountPassword))
                    {
                        ManagedAccountPassword = ethereumTestSettings.ManagedAccountPassword;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.Client))
                    {
                        EthereumClient = (EthereumClient)Enum.Parse(typeof(EthereumClient), ethereumTestSettings.Client);
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.InfuraNetwork))
                    {
                        InfuraNetwork = (InfuraNetwork)Enum.Parse(typeof(InfuraNetwork), ethereumTestSettings.InfuraNetwork);
                    }
                    ;
                    if (!string.IsNullOrEmpty(ethereumTestSettings.InfuraId))
                    {
                        InfuraId = ethereumTestSettings.InfuraId;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.HttpUrl))
                    {
                        HttpUrl = ethereumTestSettings.HttpUrl;
                    }
                }
            }

            var client = Environment.GetEnvironmentVariable("ETHEREUM_CLIENT");

            if (client == null)
            {
                Console.WriteLine("**************TEST CLIENT NOT CONFIGURED IN ENVIRONMENT USING DEFAULT");
            }
            else
            {
                Console.WriteLine("************ENVIRONMENT CONFIGURED WITH CLIENT: " + client.ToString());
            }

            if (string.IsNullOrEmpty(client))
            {
            }
            else if (client == "geth")
            {
                EthereumClient = EthereumClient.Geth;
                Console.WriteLine("********TESTING WITH GETH****************");
            }
            else if (client == "parity")
            {
                EthereumClient = EthereumClient.OpenEthereum;
                Console.WriteLine("******* TESTING WITH PARITY ****************");
            }
            else if (client == "ganache")
            {
                EthereumClient = EthereumClient.Ganache;
                Console.WriteLine("******* TESTING WITH GANACHE ****************");
            }
            else if (client == "hardhat")
            {
                EthereumClient = EthereumClient.Hardhat;
                Console.WriteLine("******* TESTING WITH HARDHat ****************");
            }

            if (EthereumClient == EthereumClient.Geth)
            {
                var location = typeof(EthereumClientIntegrationFixture).GetTypeInfo().Assembly.Location;
                var dirPath  = Path.GetDirectoryName(location);
                _exePath = Path.GetFullPath(Path.Combine(dirPath, GethClientPath));

                DeleteData();

                var psiSetup = new ProcessStartInfo(_exePath,
                                                    @" --datadir=devChain init genesis_clique.json ")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = Path.GetDirectoryName(_exePath)
                };

                Process.Start(psiSetup);
                Thread.Sleep(3000);

                var psi = new ProcessStartInfo(_exePath,
                                               @" --nodiscover --http --datadir=devChain  --http.corsdomain ""*"" --mine  --ws --http.api ""eth,web3,personal,net,miner,admin,debug"" --http.addr ""0.0.0.0"" --allow-insecure-unlock --unlock 0x12890d2cce102216644c59daE5baed380d84830c --password ""pass.txt"" --verbosity 0 console")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = Path.GetDirectoryName(_exePath)
                };
                _process = Process.Start(psi);
            }
            else if (EthereumClient == EthereumClient.OpenEthereum)
            {
                var location = typeof(EthereumClientIntegrationFixture).GetTypeInfo().Assembly.Location;
                var dirPath  = Path.GetDirectoryName(location);
                _exePath = Path.GetFullPath(Path.Combine(dirPath, ParityClientPath));

                DeleteData();

                var psi = new ProcessStartInfo(_exePath,
                                               @" --config node0.toml") // --logging debug")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = Path.GetDirectoryName(_exePath)
                };
                _process = Process.Start(psi);
                Thread.Sleep(10000);
            }
            else if (EthereumClient == EthereumClient.Ganache)
            {
                var psi = new ProcessStartInfo("ganache-cli")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = _exePath,
                    Arguments        = " --account=" + AccountPrivateKey + ",10000000000000000000000"
                };
                _process = Process.Start(psi);
                Thread.Sleep(10000);
            }
            else if (EthereumClient == EthereumClient.Hardhat)
            {
                var location = typeof(EthereumClientIntegrationFixture).GetTypeInfo().Assembly.Location;
                var dirPath  = Path.GetDirectoryName(location);
                _exePath = Path.GetFullPath(Path.Combine(dirPath, HardhatClientPath));

                var psi = new ProcessStartInfo("npx")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = _exePath,
                    Arguments        = "hardhat node " + HardhatParams
                };
                _process = Process.Start(psi);
                Thread.Sleep(10000);
            }


            Thread.Sleep(3000);
        }
Exemple #2
0
        public EthereumClientIntegrationFixture()
        {
            var config = InitConfiguration();

            if (config != null)
            {
                var ethereumTestSection = config.GetSection("EthereumTestSettings");

                if (ethereumTestSection != null)
                {
                    var ethereumTestSettings = new EthereumTestSettings();
                    ethereumTestSection.Bind(ethereumTestSettings);
                    if (!string.IsNullOrEmpty(ethereumTestSettings.GethPath))
                    {
                        GethClientPath = ethereumTestSettings.GethPath;
                    }
                    if (!string.IsNullOrEmpty(ethereumTestSettings.ParityPath))
                    {
                        ParityClientPath = ethereumTestSettings.ParityPath;
                    }
                }
            }


            var client = Environment.GetEnvironmentVariable("ETHEREUM_CLIENT");

            if (client == null)
            {
                Console.WriteLine("**************TEST CLIENT NOT CONFIGURED IN ENVIRONMENT USING DEFAULT");
            }
            else
            {
                Console.WriteLine("************ ENVIRONMENT CONFIGURED WITH CLIENT: " + client.ToString());
            }

            if (string.IsNullOrEmpty(client))
            {
                EthereumClient = EthereumClient.Geth;
            }
            else if (client == "geth")
            {
                EthereumClient = EthereumClient.Geth;
                Console.WriteLine("********TESTING WITH GETH****************");
            }
            else
            {
                EthereumClient = EthereumClient.Parity;
                Console.WriteLine("******* TESTING WITH PARITY ****************");
            }

            if (EthereumClient == EthereumClient.Geth)
            {
                var location = typeof(EthereumClientIntegrationFixture).GetTypeInfo().Assembly.Location;
                var dirPath  = Path.GetDirectoryName(location);
                _exePath = Path.GetFullPath(Path.Combine(dirPath, GethClientPath));

                DeleteData();

                var psiSetup = new ProcessStartInfo(Path.Combine(_exePath, "geth.exe"),
                                                    @"--datadir=devChain init genesis_clique.json ")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = _exePath
                };

                Process.Start(psiSetup);
                Thread.Sleep(3000);

                var psi = new ProcessStartInfo(Path.Combine(_exePath, "geth.exe"),
                                               @" --nodiscover --rpc --datadir=devChain  --rpccorsdomain "" * "" --mine --rpcapi ""eth, web3, personal, net, miner, admin, debug"" --rpcaddr ""0.0.0.0"" --allow-insecure-unlock --unlock 0x12890d2cce102216644c59daE5baed380d84830c --password ""pass.txt""  --ws  --wsaddr ""0.0.0.0"" --wsapi ""eth, web3, personal, net, miner, admin, debug"" --wsorigins "" * "" --verbosity 0 console  ")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = _exePath
                };
                _process = Process.Start(psi);
            }
            else
            {
                var location = typeof(EthereumClientIntegrationFixture).GetTypeInfo().Assembly.Location;
                var dirPath  = Path.GetDirectoryName(location);
                _exePath = Path.GetFullPath(Path.Combine(dirPath, ParityClientPath));

                //DeleteData();

                var psi = new ProcessStartInfo(Path.Combine(_exePath, "parity.exe"),
                                               @" --config node0.toml") // --logging debug")
                {
                    CreateNoWindow   = false,
                    WindowStyle      = ProcessWindowStyle.Normal,
                    UseShellExecute  = true,
                    WorkingDirectory = _exePath
                };
                _process = Process.Start(psi);
                Thread.Sleep(10000);
            }


            Thread.Sleep(3000);
        }