public void Skips_AdditionalUrl_with_engine_module_enabled_when_EngineUrl_specified() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules, AdditionalRpcUrls = new [] { "http://127.0.0.1:8551|http|eth;web3;engine", "http://127.0.0.1:1234|http|eth;web3" }, EngineHost = "127.0.0.1", EnginePort = 8552, EngineEnabledModules = new [] { "eth" } }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, false); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http, false, _enabledModules) }, { 8552, new JsonRpcUrl("http", "127.0.0.1", 8552, RpcEndpoint.Http, true, new [] { "eth", "engine" }) }, { 1234, new JsonRpcUrl("http", "127.0.0.1", 1234, RpcEndpoint.Http, false, new [] { "eth", "web3" }) } }, urlCollection);; }
public void Initialize() { var keystoreConfig = new KeyStoreConfig(); var networkConfig = new NetworkConfig(); var jsonRpcConfig = new JsonRpcConfig(); var statsConfig = new StatsConfig(); }
public void Proof_module_is_registered_if_configured() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); jsonRpcConfig.Enabled = true; IConfigProvider configProvider = Substitute.For <IConfigProvider>(); configProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); IRpcModuleProvider rpcModuleProvider = Substitute.For <IRpcModuleProvider>(); NethermindApi context = Build.ContextWithMocks(); context.ConfigProvider = configProvider; context.RpcModuleProvider = rpcModuleProvider; var signer = new Signer(ChainId.Mainnet, TestItem.PrivateKeyA, LimboLogs.Instance); context.TxSender = new NullTxSender(); context.EngineSignerStore = signer; context.KeyStore = Substitute.For <IKeyStore>(); context.SyncModeSelector = Substitute.For <ISyncModeSelector>(); context.ChainLevelInfoRepository = Substitute.For <IChainLevelInfoRepository>(); RegisterRpcModules registerRpcModules = new RegisterRpcModules(context); registerRpcModules.Execute(CancellationToken.None); rpcModuleProvider.ReceivedWithAnyArgs().Register <IProofModule>(null); }
public void Skips_additional_urls_with_port_conficts() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules, WebSocketsPort = 9876, AdditionalRpcUrls = new [] { "http://localhost:8545|http;ws|admin;debug", "https://127.0.0.1:1234|https;wss|eth;web3", "https://127.0.0.1:9876|https;wss|net;proof", "http://localhost:1234|http;ws|db;erc20" } }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http, _enabledModules) }, { 9876, new JsonRpcUrl("http", "127.0.0.1", 9876, RpcEndpoint.Ws, _enabledModules) }, { 1234, new JsonRpcUrl("https", "127.0.0.1", 1234, RpcEndpoint.Https | RpcEndpoint.Wss, new [] { "eth", "web3" }) } }, urlCollection); }
public void Proof_module_is_not_registered_when_json_rpc_not_enabled() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); jsonRpcConfig.Enabled = false; IConfigProvider configProvider = Substitute.For <IConfigProvider>(); configProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); IRpcModuleProvider rpcModuleProvider = Substitute.For <IRpcModuleProvider>(); NethermindApi context = new NethermindApi(configProvider, LimboLogs.Instance) { ConfigProvider = configProvider, RpcModuleProvider = rpcModuleProvider, TxPool = Substitute.For <ITxPool>(), BlockTree = Substitute.For <IBlockTree>(), Wallet = Substitute.For <IWallet>(), SpecProvider = Substitute.For <ISpecProvider>(), TxSender = Substitute.For <ITxSender>() }; RegisterRpcModules registerRpcModules = new RegisterRpcModules(context); registerRpcModules.Execute(CancellationToken.None); rpcModuleProvider.DidNotReceiveWithAnyArgs().Register <IProofModule>(null); }
public void Initialize() { ISpecProvider specProvider = MainnetSpecProvider.Instance; ITxPool txPool = NullTxPool.Instance; MemDbProvider dbProvider = new MemDbProvider(); IJsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); BlockTree blockTree = new BlockTree( dbProvider.BlocksDb, dbProvider.HeadersDb, dbProvider.BlockInfosDb, new ChainLevelInfoRepository(dbProvider.BlockInfosDb), specProvider, txPool, new BloomStorage(new BloomConfig(), dbProvider.HeadersDb, new InMemoryDictionaryFileStoreFactory()), new SyncConfig(), LimboLogs.Instance); _modulePool = new BoundedModulePool <IEthModule>( 1, new EthModuleFactory( dbProvider, txPool, Substitute.For <ITxSender>(), NullWallet.Instance, blockTree, new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance), NullBlockProcessor.Instance, new InMemoryReceiptStorage(), specProvider, new JsonRpcConfig(), NullBloomStorage.Instance, LimboLogs.Instance, false)); }
public void Proof_module_is_registered_if_configured() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); jsonRpcConfig.Enabled = true; IConfigProvider configProvider = Substitute.For <IConfigProvider>(); configProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); IRpcModuleProvider rpcModuleProvider = Substitute.For <IRpcModuleProvider>(); EthereumRunnerContext context = Build.ContextWithMocks(); context.ConfigProvider = configProvider; context.RpcModuleProvider = rpcModuleProvider; context.Signer = new Signer(ChainId.Mainnet, TestItem.PrivateKeyA, LimboLogs.Instance); context.KeyStore = Substitute.For <IKeyStore>(); RegisterRpcModules registerRpcModules = new RegisterRpcModules(context); registerRpcModules.Execute(CancellationToken.None); rpcModuleProvider.ReceivedWithAnyArgs().Register <IProofModule>(null); }
public void Initialize() { var keystoreConfig = new KeystoreConfig(); var networkConfig = new NetworkConfig(); var jsonRpcConfig = new JsonRpcConfig(); _configProvider = new JsonConfigProvider(); }
public void Initialize() { var keystoreConfig = new KeyStoreConfig(); var networkConfig = new NetworkConfig(); var jsonRpcConfig = new JsonRpcConfig(); var statsConfig = new StatsConfig(); _configProvider = new JsonConfigProvider("SampleJsonConfig.cfg"); }
public void Empty_when_disabled() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = false }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.IsEmpty(urlCollection); }
public void Module_provider_will_recognize_disabled_modules() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); jsonRpcConfig.EnabledModules = new string[0]; _moduleProvider = new RpcModuleProvider(jsonRpcConfig, LimboLogs.Instance); _moduleProvider.Register(new SingletonModulePool <IProofModule>(Substitute.For <IProofModule>(), false)); ModuleResolution resolution = _moduleProvider.Check("proof_call"); Assert.AreEqual(ModuleResolution.Disabled, resolution); }
public TestRpcModuleProvider(T module) { _jsonRpcConfig = new JsonRpcConfig(); _provider = new RpcModuleProvider(new FileSystem(), _jsonRpcConfig, LimboLogs.Instance); _provider.Register(new SingletonModulePool <INetRpcModule>(new SingletonFactory <INetRpcModule>(typeof(INetRpcModule).IsAssignableFrom(typeof(T)) ? (INetRpcModule)module : Substitute.For <INetRpcModule>()), true)); _provider.Register(new SingletonModulePool <IEthRpcModule>(new SingletonFactory <IEthRpcModule>(typeof(IEthRpcModule).IsAssignableFrom(typeof(T)) ? (IEthRpcModule)module : Substitute.For <IEthRpcModule>()), true)); _provider.Register(new SingletonModulePool <IWeb3RpcModule>(new SingletonFactory <IWeb3RpcModule>(typeof(IWeb3RpcModule).IsAssignableFrom(typeof(T)) ? (IWeb3RpcModule)module : Substitute.For <IWeb3RpcModule>()), true)); _provider.Register(new SingletonModulePool <IDebugRpcModule>(new SingletonFactory <IDebugRpcModule>(typeof(IDebugRpcModule).IsAssignableFrom(typeof(T)) ? (IDebugRpcModule)module : Substitute.For <IDebugRpcModule>()), true)); _provider.Register(new SingletonModulePool <ITraceRpcModule>(new SingletonFactory <ITraceRpcModule>(typeof(ITraceRpcModule).IsAssignableFrom(typeof(T)) ? (ITraceRpcModule)module : Substitute.For <ITraceRpcModule>()), true)); _provider.Register(new SingletonModulePool <IParityRpcModule>(new SingletonFactory <IParityRpcModule>(typeof(IParityRpcModule).IsAssignableFrom(typeof(T)) ? (IParityRpcModule)module : Substitute.For <IParityRpcModule>()), true)); }
public async Task Proof_module_is_registered_if_configured() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig { Enabled = true }; Runner.Ethereum.Api.NethermindApi context = Build.ContextWithMocks(); context.ConfigProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); RegisterRpcModules registerRpcModules = new RegisterRpcModules(context); await registerRpcModules.Execute(CancellationToken.None); context.RpcModuleProvider.Check("proof_call", RpcEndpoint.Http).Should().Be(ModuleResolution.Enabled); }
public async Task Proof_module_is_not_registered_when_json_rpc_not_enabled() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig { Enabled = false }; Runner.Ethereum.Api.NethermindApi context = Build.ContextWithMocks(); context.ConfigProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); context.RpcModuleProvider.Enabled.Returns(Array.Empty <ModuleType>()); RegisterRpcModules registerRpcModules = new RegisterRpcModules(context); await registerRpcModules.Execute(CancellationToken.None); context.RpcModuleProvider.DidNotReceiveWithAnyArgs().Register <IProofRpcModule>(null); }
public void Contains_single_default_url() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http | RpcEndpoint.Ws, _enabledModules) } }, urlCollection); }
public void Skips_additional_ws_only_urls_when_ws_disabled() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules, AdditionalRpcUrls = new [] { "http://localhost:1234|ws|admin;debug" } }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, false); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http, _enabledModules) } }, urlCollection); }
public void With_filter_can_reject(string regex, ModuleResolution expectedResult) { JsonRpcConfig config = new JsonRpcConfig(); _fileSystem.File.Exists(Arg.Any <string>()).Returns(true); _fileSystem.File.ReadLines(Arg.Any <string>()).Returns(new[] { regex }); _moduleProvider = new RpcModuleProvider(_fileSystem, config, LimboLogs.Instance); SingletonModulePool <INetModule> pool = new SingletonModulePool <INetModule>(new NetModule(LimboLogs.Instance, Substitute.For <INetBridge>()), true); _moduleProvider.Register(pool); ModuleResolution resolution = _moduleProvider.Check("net_version"); resolution.Should().Be(expectedResult); }
public void Contains_single_default_http_url_when_ws_disabled() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, WebSocketsPort = 1234, EnabledModules = _enabledModules }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, false); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http, _enabledModules) }, }, urlCollection); }
public void Contains_multiple_default_urls_with_different_ws_port() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, WebSocketsPort = 1234, EnabledModules = _enabledModules }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http, _enabledModules) }, { 1234, new JsonRpcUrl("http", "127.0.0.1", 1234, RpcEndpoint.Ws, _enabledModules) } }, urlCollection); }
public void Contains_single_default_url_overridden_by_environment_variable() { Environment.SetEnvironmentVariable("NETHERMIND_URL", "http://localhost:1234", EnvironmentVariableTarget.Process); JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 1234, new JsonRpcUrl("http", "localhost", 1234, RpcEndpoint.Http | RpcEndpoint.Ws, _enabledModules) } }, urlCollection); }
public void Contains_additional_urls() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules, AdditionalRpcUrls = new [] { "https://localhost:1234|https;wss|admin;debug" } }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http | RpcEndpoint.Ws, _enabledModules) }, { 1234, new JsonRpcUrl("https", "localhost", 1234, RpcEndpoint.Https | RpcEndpoint.Wss, new[] { "admin", "debug" }) } }, urlCollection); }
public void Setup() { _mergeConfig = new MergeConfig() { Enabled = true }; MiningConfig? miningConfig = new() { Enabled = true }; IJsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = new[] { "engine" } }; _context = Build.ContextWithMocks(); _context.SealEngineType = SealEngineType.Clique; _context.ConfigProvider.GetConfig <IMergeConfig>().Returns(_mergeConfig); _context.ConfigProvider.GetConfig <ISyncConfig>().Returns(new SyncConfig()); _context.ConfigProvider.GetConfig <IMiningConfig>().Returns(miningConfig); _context.ConfigProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); _context.BlockProcessingQueue?.IsEmpty.Returns(true); _context.MemDbFactory = new MemDbFactory(); _context.BlockProducerEnvFactory = new BlockProducerEnvFactory( _context.DbProvider !, _context.BlockTree !, _context.ReadOnlyTrieStore !, _context.SpecProvider !, _context.BlockValidator !, _context.RewardCalculatorSource !, _context.ReceiptStorage !, _context.BlockPreprocessor !, _context.TxPool !, _context.TransactionComparerProvider, miningConfig, _context.LogManager !); _context.ChainSpec !.Clique = new CliqueParameters() { Epoch = CliqueConfig.Default.Epoch, Period = CliqueConfig.Default.BlockPeriod }; _plugin = new MergePlugin(); _consensusPlugin = new(); }
public void Skips_additional_urls_when_invalid() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules, AdditionalRpcUrls = new [] { string.Empty, "test", "http://localhost:1234|http|db;erc20;web3" } }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http | RpcEndpoint.Ws, _enabledModules) }, { 1234, new JsonRpcUrl("http", "localhost", 1234, RpcEndpoint.Http, new [] { "db", "erc20", "web3" }) } }, urlCollection);; }
public void EngineHost_and_EnginePort_specified() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = true, EnabledModules = _enabledModules, AdditionalRpcUrls = new [] { "http://127.0.0.1:8551|http|eth;web3;engine" }, EngineHost = "127.0.0.1", EnginePort = 8551, EngineEnabledModules = new[] { "eth" } }; JsonRpcUrlCollection urlCollection = new JsonRpcUrlCollection(Substitute.For <ILogManager>(), jsonRpcConfig, true); CollectionAssert.AreEquivalent(new Dictionary <int, JsonRpcUrl>() { { 8545, new JsonRpcUrl("http", "127.0.0.1", 8545, RpcEndpoint.Http | RpcEndpoint.Ws, false, _enabledModules) }, { 8551, new JsonRpcUrl("http", "127.0.0.1", 8551, RpcEndpoint.Http | RpcEndpoint.Ws, true, new [] { "eth", "engine" }) }, }, urlCollection);; }
public void Initialize() { ISpecProvider specProvider = MainnetSpecProvider.Instance; ITxPool txPool = NullTxPool.Instance; MemDbProvider dbProvider = new MemDbProvider(); IJsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); BlockTree blockTree = new BlockTree(dbProvider.BlocksDb, dbProvider.HeadersDb, dbProvider.BlockInfosDb, new ChainLevelInfoRepository(dbProvider.BlockInfosDb), specProvider, txPool, NullBloomStorage.Instance, new SyncConfig(), LimboLogs.Instance); _factory = new EthModuleFactory( dbProvider, txPool, NullWallet.Instance, jsonRpcConfig, blockTree, new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance), NullBlockProcessor.Instance, new InMemoryReceiptStorage(), specProvider, new JsonRpcConfig(), NullBloomStorage.Instance, LimboLogs.Instance, false); }
public void Proof_module_is_not_registered_when_json_rpc_not_enabled() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); jsonRpcConfig.Enabled = false; IConfigProvider configProvider = Substitute.For <IConfigProvider>(); configProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); IRpcModuleProvider rpcModuleProvider = Substitute.For <IRpcModuleProvider>(); EthereumRunnerContext context = new EthereumRunnerContext(configProvider, LimboLogs.Instance); context.ConfigProvider = configProvider; context.RpcModuleProvider = rpcModuleProvider; RegisterRpcModules registerRpcModules = new RegisterRpcModules(context); registerRpcModules.Execute(); rpcModuleProvider.DidNotReceiveWithAnyArgs().Register <IProofModule>(null); }
public void Proof_module_is_registered_if_configured() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); jsonRpcConfig.Enabled = true; IConfigProvider configProvider = Substitute.For <IConfigProvider>(); configProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); IRpcModuleProvider rpcModuleProvider = Substitute.For <IRpcModuleProvider>(); EthereumRunnerContext context = Build.ContextWithMocks(); context.ConfigProvider = configProvider; context.RpcModuleProvider = rpcModuleProvider; RegisterRpcModules registerRpcModules = new RegisterRpcModules(context); registerRpcModules.Execute(CancellationToken.None); rpcModuleProvider.ReceivedWithAnyArgs().Register <IProofModule>(null); }
public void Initialize() { IJsonRpcService service = Substitute.For <IJsonRpcService>(); service.SendRequestAsync(Arg.Any <JsonRpcRequest>()).Returns(ci => _returnErrors ? (JsonRpcResponse) new JsonRpcErrorResponse { Id = ci.Arg <JsonRpcRequest>().Id } : new JsonRpcSuccessResponse { Id = ci.Arg <JsonRpcRequest>().Id }); service.GetErrorResponse(0, null).ReturnsForAnyArgs(_errorResponse); service.Converters.Returns(new JsonConverter[] { new AddressConverter() }); // just to test converter loader _fileSystem = Substitute.For <IFileSystem>(); /* we enable recorder always to have an easy smoke test for recording * and this is fine because recorder is non-critical component */ JsonRpcConfig configWithRecorder = new JsonRpcConfig(); configWithRecorder.RpcRecorderEnabled = true; _jsonRpcProcessor = new JsonRpcProcessor(service, new EthereumJsonSerializer(), configWithRecorder, _fileSystem, LimboLogs.Instance); }
public async Task InitDisableJsonRpcUrlWithNoEngineUrl() { JsonRpcConfig jsonRpcConfig = new JsonRpcConfig() { Enabled = false, EnabledModules = new string[] { "eth", "subscribe" }, AdditionalRpcUrls = new [] { "http://localhost:8550|http;ws|net;eth;subscribe;web3;client|no-auth", "http://localhost:8551|http;ws|net;eth;subscribe;web3;engine;client", } }; _context.ConfigProvider.GetConfig <IJsonRpcConfig>().Returns(jsonRpcConfig); await _plugin.Init(_context); jsonRpcConfig.Enabled.Should().BeTrue(); jsonRpcConfig.EnabledModules.Should().BeEquivalentTo(new string[] { }); jsonRpcConfig.AdditionalRpcUrls.Should().BeEquivalentTo(new string[] { "http://localhost:8551|http;ws|net;eth;subscribe;web3;engine;client" }); }