private void EnsureJsonRpcUrl() { IJsonRpcConfig jsonRpcConfig = _api.Config <IJsonRpcConfig>(); if (!jsonRpcConfig.Enabled) { if (_logger.IsInfo) { _logger.Info("JsonRpc not enabled. Turning on JsonRpc URL with engine API."); } jsonRpcConfig.Enabled = true; EnsureEngineModuleIsConfigured(); if (!jsonRpcConfig.EnabledModules.Contains("engine")) { // Disable it jsonRpcConfig.EnabledModules = new string[] { }; } jsonRpcConfig.AdditionalRpcUrls = jsonRpcConfig.AdditionalRpcUrls .Where((url) => JsonRpcUrl.Parse(url).EnabledModules.Contains("engine")) .ToArray(); } else { EnsureEngineModuleIsConfigured(); } }
public void Parse_success(string packedUrlValue, string expectedScheme, string expectedHost, int expectedPort, RpcEndpoint expectedRpcEndpoint, string[] expectedEnabledModules) { JsonRpcUrl url = JsonRpcUrl.Parse(packedUrlValue); Assert.AreEqual(expectedScheme, url.Scheme); Assert.AreEqual(expectedHost, url.Host); Assert.AreEqual(expectedPort, url.Port); Assert.AreEqual(expectedRpcEndpoint, url.RpcEndpoint); CollectionAssert.AreEqual(expectedEnabledModules, url.EnabledModules); }
public void Method_resolution_is_scoped_to_url_enabled_modules() { _moduleProvider.Register(new SingletonModulePool <INetRpcModule>(Substitute.For <INetRpcModule>(), true)); _moduleProvider.Register(new SingletonModulePool <IProofRpcModule>(Substitute.For <IProofRpcModule>(), true)); JsonRpcUrl url = new JsonRpcUrl("http", "127.0.0.1", 8888, RpcEndpoint.Http, new[] { "net" }); ModuleResolution inScopeResolution = _moduleProvider.Check("net_version", JsonRpcContext.Http(url)); Assert.AreEqual(ModuleResolution.Enabled, inScopeResolution); ModuleResolution outOfScopeResolution = _moduleProvider.Check("proof_call", JsonRpcContext.Http(url)); Assert.AreEqual(ModuleResolution.Disabled, outOfScopeResolution); ModuleResolution fallbackResolution = _moduleProvider.Check("proof_call", new JsonRpcContext(RpcEndpoint.Http)); Assert.AreEqual(ModuleResolution.Enabled, fallbackResolution); }
public void Parse_fail(string packedUrlValue, Type expectedExceptionType) => Assert.Throws(expectedExceptionType, () => JsonRpcUrl.Parse(packedUrlValue));