Ejemplo n.º 1
0
        protected override void EndProcessing()
        {
            Console.WriteLine("Starting RPC test server...");

            var config = this.ReadConfig();

            var testNodeServer = new TestNodeServer(port: (int)config.NetworkPort, accountConfig: new AccountConfiguration
            {
                AccountGenerationCount     = config.AccountCount,
                DefaultAccountEtherBalance = config.AccountBalance
            });

            testNodeServer.RpcServer.Start();

            var serverAddress = testNodeServer.RpcServer.ServerAddresses[0];

            Console.WriteLine($"Started RPC test server at {serverAddress}\n");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Server instance information has been saved to the global variable $testNodeServer\n");
            Console.WriteLine("$testNodeServer can be used to control the server instance i.e $testNodeServer.RpcServer.Stop()...");
            Console.WriteLine("...or with the Stop-TestServer command i.e Stop-TestServer -TestNodeServer $testNodeServer");
            Console.ResetColor();

            SessionState.SetTestNodeServer(testNodeServer);

            WriteObject(new { TestNodeServer = testNodeServer });
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     try
     {
         RpcClient?.Dispose();
     }
     catch { }
     try
     {
         TestNodeServer?.Dispose();
     }
     catch { }
 }
Ejemplo n.º 3
0
        static async Task CreateRunIteration()
        {
            using (var server = new TestNodeServer())
            {
                await server.RpcServer.StartAsync();

                int port = server.RpcServer.ServerPort;

                var client = JsonRpcClient.Create(new Uri($"http://{IPAddress.Loopback}:{port}"), ArbitraryDefaults.DEFAULT_GAS_LIMIT, ArbitraryDefaults.DEFAULT_GAS_PRICE);

                await client.SetCoverageEnabled(true);

                var accounts = await client.Accounts();

                var contract = await BasicContract.New($"TestName", true, 34, client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);

                var snapshotID = await client.Snapshot();

                var initialValCounter = await contract.getValCounter().Call();

                await contract.incrementValCounter();

                var valCounter2 = await contract.getValCounter().Call();

                await client.Revert(snapshotID);

                var finalValCounter = await contract.getValCounter().Call();

                Assert.Equal(0, initialValCounter);
                Assert.Equal(2, valCounter2);
                Assert.Equal(0, finalValCounter);

                var snapshotID2 = await client.Snapshot();

                var contract2 = await BasicContract.New($"TestName", true, 34, client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);

                await contract2.incrementValCounter();

                await client.Revert(snapshotID2);

                var coverage = await client.GetCoverageMap(contract.ContractAddress);
            }
        }
Ejemplo n.º 4
0
        protected override void EndProcessing()
        {
            Console.WriteLine("Starting RPC test server...");

            var config = this.ReadConfig();

            var testNodeServer = new TestNodeServer((int)config.NetworkPort, new AccountConfiguration
            {
                AccountGenerationCount     = config.AccountCount,
                DefaultAccountEtherBalance = config.AccountBalance
            });

            testNodeServer.RpcServer.Start();

            var serverAddress = testNodeServer.RpcServer.ServerAddresses[0];

            Console.WriteLine($"Started RPC test server at {serverAddress}");

            SessionState.SetTestNodeServer(testNodeServer);
        }
Ejemplo n.º 5
0
        public async Task ProxyIntegrationTest(string protocol)
        {
            // create test node server
            using (var server = new TestNodeServer())
            {
                await server.RpcServer.StartAsync();

                // create proxy server pointed to test node server
                var httpServerEndPoint = new Uri($"{protocol}://{IPAddress.Loopback}:{server.RpcServer.ServerPort}");
                using (var proxyServer = new RpcServerProxy(httpServerEndPoint))
                {
                    await proxyServer.StartServerAsync();

                    // create rpc client pointed to proxy server
                    var proxyServerUri = new Uri($"{protocol}://{IPAddress.Loopback}:{proxyServer.ProxyServerPort}");
                    using (var client = JsonRpcClient.Create(proxyServerUri, 100, 100))
                    {
                        var version = await client.Version();
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public TestServices(IJsonRpcClient testNodeClient, TestNodeServer testNodeServer, Address[] accounts)
 {
     TestNodeClient = testNodeClient;
     TestNodeServer = testNodeServer;
     Accounts       = accounts;
 }
Ejemplo n.º 7
0
        static async Task Main(string[] args)
        {
            var opts = ProcessArgs.Parse(args);

            if (!string.IsNullOrWhiteSpace(opts.Proxy))
            {
                // TODO: testnode.host proxy support
                throw new NotImplementedException();
            }

            IPAddress host;

            if (string.IsNullOrWhiteSpace(opts.Host) || opts.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
            {
                host = IPAddress.Loopback;
            }
            else if (opts.Host == "*")
            {
                host = IPAddress.Any;
            }
            else if (IPAddress.TryParse(opts.Host, out var addr))
            {
                host = addr;
            }
            else
            {
                var entry = await Dns.GetHostEntryAsync(opts.Host);

                host = entry.AddressList[0];
            }

            // Setup account derivation / keys
            IAccountDerivation accountDerivation;

            if (string.IsNullOrWhiteSpace(opts.Mnemonic))
            {
                var hdWalletAccountDerivation = HDAccountDerivation.Create();
                accountDerivation = hdWalletAccountDerivation;
                Console.WriteLine($"Using mnemonic phrase: '{hdWalletAccountDerivation.MnemonicPhrase}'");
                Console.WriteLine("Warning: this private key generation is not secure and should not be used in production.");
            }
            else
            {
                accountDerivation = new HDAccountDerivation(opts.Mnemonic);
            }


            var accountConfig = new AccountConfiguration
            {
                AccountGenerationCount     = (int)opts.AccountCount,
                DefaultAccountEtherBalance = opts.AccountBalance,
                AccountDerivationMethod    = accountDerivation
            };

            // Create our local test node.
            using (var testNodeServer = new TestNodeServer(
                       port: (int)opts.Port,
                       address: host,
                       accountConfig: accountConfig))
            {
                Console.WriteLine("Starting server...");

                testNodeServer.RpcServer.DebugLogger = Console.WriteLine;

                // Start our local test node.
                await testNodeServer.RpcServer.StartAsync();

                // Create an RPC client for our local test node.
                var serverAddresses = string.Join(", ", testNodeServer.RpcServer.ServerAddresses);
                Console.WriteLine($"Test node server listening on: {serverAddresses}");

                // Listen for exit request.
                var exitEvent = new SemaphoreSlim(0, 1);
                Console.CancelKeyPress += (s, e) =>
                {
                    exitEvent.Release();
                    e.Cancel = true;
                };

                // Shutdown.
                await exitEvent.WaitAsync();

                Console.WriteLine("Stopping server and exiting...");
                await testNodeServer.RpcServer.StopAsync();
            }
        }