Beispiel #1
0
        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);
        }
Beispiel #2
0
        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)
            {
                ConfigProvider    = configProvider,
                RpcModuleProvider = rpcModuleProvider,
                TxPool            = Substitute.For <ITxPool>(),
                BlockTree         = Substitute.For <IBlockTree>(),
                Wallet            = Substitute.For <IWallet>(),
                SpecProvider      = Substitute.For <ISpecProvider>()
            };

            RegisterRpcModules registerRpcModules = new RegisterRpcModules(context);

            registerRpcModules.Execute(CancellationToken.None);

            rpcModuleProvider.DidNotReceiveWithAnyArgs().Register <IProofModule>(null);
        }
        public static EthereumRunnerContext ContextWithMocks()
        {
            EthereumRunnerContext context = new EthereumRunnerContext(Substitute.For <IConfigProvider>(), LimboLogs.Instance);

            context.LogManager             = LimboLogs.Instance;
            context.Enode                  = Substitute.For <IEnode>();
            context.TxPool                 = Substitute.For <ITxPool>();
            context.Wallet                 = Substitute.For <IWallet>();
            context.BlockTree              = Substitute.For <IBlockTree>();
            context.SyncServer             = Substitute.For <ISyncServer>();
            context.DbProvider             = Substitute.For <IDbProvider>();
            context.PeerManager            = Substitute.For <IPeerManager>();
            context.SpecProvider           = Substitute.For <ISpecProvider>();
            context.EthereumEcdsa          = Substitute.For <IEthereumEcdsa>();
            context.MainBlockProcessor     = Substitute.For <IBlockProcessor>();
            context.ReceiptStorage         = Substitute.For <IReceiptStorage>();
            context.BlockValidator         = Substitute.For <IBlockValidator>();
            context.RewardCalculatorSource = Substitute.For <IRewardCalculatorSource>();
            context.RecoveryStep           = Substitute.For <IBlockDataRecoveryStep>();
            context.TxPoolInfoProvider     = Substitute.For <ITxPoolInfoProvider>();
            context.StaticNodesManager     = Substitute.For <IStaticNodesManager>();
            context.BloomStorage           = Substitute.For <IBloomStorage>();

            return(context);
        }
        public EthereumRunner(
            IRpcModuleProvider rpcModuleProvider,
            IConfigProvider configurationProvider,
            ILogManager logManager,
            IGrpcServer?grpcServer,
            INdmConsumerChannelManager?ndmConsumerChannelManager,
            INdmDataPublisher?ndmDataPublisher,
            INdmInitializer?ndmInitializer,
            IWebSocketsManager webSocketsManager,
            IJsonSerializer ethereumJsonSerializer,
            IMonitoringService monitoringService)
        {
            _logger             = logManager.GetClassLogger();
            _context            = new EthereumRunnerContextFactory(configurationProvider, ethereumJsonSerializer, logManager).Context;
            _context.LogManager = logManager;
            _context.GrpcServer = grpcServer;
            _context.NdmConsumerChannelManager = ndmConsumerChannelManager;
            _context.NdmDataPublisher          = ndmDataPublisher;
            _context.NdmInitializer            = ndmInitializer;
            _context.WebSocketsManager         = webSocketsManager;
            _context.EthereumJsonSerializer    = ethereumJsonSerializer;
            _context.MonitoringService         = monitoringService;

            _context.ConfigProvider    = configurationProvider ?? throw new ArgumentNullException(nameof(configurationProvider));
            _context.RpcModuleProvider = rpcModuleProvider ?? throw new ArgumentNullException(nameof(rpcModuleProvider));

            INetworkConfig networkConfig = _context.Config <INetworkConfig>();

            _context.IpResolver      = new IPResolver(networkConfig, _context.LogManager);
            networkConfig.ExternalIp = _context.IpResolver.ExternalIp.ToString();
            networkConfig.LocalIp    = _context.IpResolver.LocalIp.ToString();
        }
Beispiel #5
0
        public async Task With_steps_from_here()
        {
            EthereumRunnerContext runnerContext = new EthereumRunnerContext(
                new ConfigProvider(),
                LimboLogs.Instance);

            IEthereumStepsLoader stepsLoader  = new EthereumStepsLoader(GetType().Assembly);
            EthereumStepsManager stepsManager = new EthereumStepsManager(
                stepsLoader,
                runnerContext,
                LimboLogs.Instance);

            CancellationTokenSource source = new CancellationTokenSource(TimeSpan.FromSeconds(1));

            try
            {
                await stepsManager.InitializeAll(source.Token);
            }
            catch (Exception e)
            {
                if (!(e is OperationCanceledException))
                {
                    throw new AssertionFailedException($"Exception should be {nameof(OperationCanceledException)}");
                }
            }
        }
Beispiel #6
0
 public InitializeNetwork(EthereumRunnerContext context)
 {
     _ctx           = context;
     _logger        = _ctx.LogManager.GetClassLogger();
     _networkConfig = _ctx.Config <INetworkConfig>();
     _syncConfig    = _ctx.Config <ISyncConfig>();
 }
Beispiel #7
0
 public ApplyMemoryHint(EthereumRunnerContext context)
 {
     _context       = context ?? throw new ArgumentNullException(nameof(context));
     _initConfig    = context.Config <IInitConfig>();
     _dbConfig      = context.Config <IDbConfig>();
     _networkConfig = context.Config <INetworkConfig>();
     _syncConfig    = context.Config <ISyncConfig>();
 }
Beispiel #8
0
        public StartGrpcProducer(EthereumRunnerContext context)
        {
            _context = context;
            EthereumSubsystemState newState = _context.Config <IGrpcConfig>().Enabled
                ? EthereumSubsystemState.AwaitingInitialization
                : EthereumSubsystemState.Disabled;

            SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(newState));
        }
Beispiel #9
0
        public StartKafkaProducer(EthereumRunnerContext context)
        {
            _context = context;
            _logger  = context.LogManager.GetClassLogger();
            EthereumSubsystemState newState = _context.Config <IKafkaConfig>().Enabled
                ? EthereumSubsystemState.AwaitingInitialization
                : EthereumSubsystemState.Disabled;

            SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(newState));
        }
Beispiel #10
0
        public void RunMigration()
        {
            var chainLength            = 10;
            var configProvider         = Substitute.For <IConfigProvider>();
            var blockTreeBuilder       = Core.Test.Builders.Build.A.BlockTree().OfChainLength(chainLength);
            var inMemoryReceiptStorage = new InMemoryReceiptStorage()
            {
                MigratedBlockNumber = long.MaxValue
            };
            var outMemoryReceiptStorage = new InMemoryReceiptStorage()
            {
                MigratedBlockNumber = long.MaxValue
            };
            var context = new EthereumRunnerContext(configProvider, LimboLogs.Instance)
            {
                ReceiptStorage           = new TestReceiptStorage(inMemoryReceiptStorage, outMemoryReceiptStorage),
                DbProvider               = Substitute.For <IDbProvider>(),
                BlockTree                = blockTreeBuilder.TestObject,
                Synchronizer             = Substitute.For <ISynchronizer>(),
                ChainLevelInfoRepository = blockTreeBuilder.ChainLevelInfoRepository,
                SyncModeSelector         = Substitute.For <ISyncModeSelector>()
            };

            configProvider.GetConfig <IInitConfig>().StoreReceipts.Returns(true);
            configProvider.GetConfig <IInitConfig>().ReceiptsMigration.Returns(true);
            context.SyncModeSelector.Current.Returns(SyncMode.Full);

            int txIndex = 0;

            for (int i = 1; i < chainLength; i++)
            {
                var block = context.BlockTree.FindBlock(i);
                inMemoryReceiptStorage.Insert(block,
                                              false,
                                              Core.Test.Builders.Build.A.Receipt.WithTransactionHash(TestItem.Keccaks[txIndex++]).TestObject,
                                              Core.Test.Builders.Build.A.Receipt.WithTransactionHash(TestItem.Keccaks[txIndex++]).TestObject);
            }

            ManualResetEvent guard           = new ManualResetEvent(false);
            Keccak           lastTransaction = TestItem.Keccaks[txIndex - 1];

            context.DbProvider.ReceiptsDb.When(x => x.Remove(lastTransaction.Bytes)).Do(c => guard.Set());
            var migration = new ReceiptMigration(context);

            migration.Run();

            guard.WaitOne(TimeSpan.FromSeconds(5));
            var txCount = (chainLength - 1 - 1) * 2;

            context.DbProvider.ReceiptsDb.Received(Quantity.Exactly(txCount)).Remove(Arg.Any <byte[]>());
            outMemoryReceiptStorage.Count.Should().Be(txCount);
        }
Beispiel #11
0
        public async Task When_no_assemblies_defined()
        {
            EthereumRunnerContext runnerContext = new EthereumRunnerContext(
                new ConfigProvider(),
                LimboLogs.Instance);

            IEthereumStepsLoader stepsLoader  = new EthereumStepsLoader();
            EthereumStepsManager stepsManager = new EthereumStepsManager(
                stepsLoader,
                runnerContext,
                LimboLogs.Instance);

            CancellationTokenSource source = new CancellationTokenSource(TimeSpan.FromSeconds(1));
            await stepsManager.InitializeAll(source.Token);
        }
        public EthereumStepsManager(
            IEthereumStepsLoader loader,
            EthereumRunnerContext context,
            ILogManager logManager)
        {
            if (loader == null)
            {
                throw new ArgumentNullException(nameof(loader));
            }

            _context = context ?? throw new ArgumentNullException(nameof(context));
            _logger  = logManager?.GetClassLogger <EthereumStepsManager>()
                       ?? throw new ArgumentNullException(nameof(logManager));

            _allSteps           = loader.LoadSteps(_context.GetType()).ToList();
            _allStepsByBaseType = _allSteps.ToDictionary(s => s.StepBaseType, s => s);
        }
Beispiel #13
0
        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 InitializeBlockchain(EthereumRunnerContext context)
 {
     _context = context;
 }
Beispiel #16
0
 public StepForever(EthereumRunnerContext runnerContext)
 {
 }
Beispiel #17
0
 public StepB(EthereumRunnerContext runnerContext)
 {
 }
Beispiel #18
0
 protected StartBlockProducer(EthereumRunnerContext context)
 {
     _context = context;
 }
Beispiel #19
0
 public DatabaseMigrations(EthereumRunnerContext context)
 {
     _context = context;
 }
 public InitializeNodeStats(EthereumRunnerContext context)
 {
     _context = context;
 }
Beispiel #21
0
 public SetupHive(EthereumRunnerContext context)
 {
     _context = context;
 }
 public InitDatabase(EthereumRunnerContext context)
 {
     _context = context;
 }
Beispiel #23
0
 public StartBlockProducer(EthereumRunnerContext context)
 {
     _context = context;
 }
 public ReceiptMigration(EthereumRunnerContext context)
 {
     _context = context;
     _logger  = context.LogManager.GetClassLogger <ReceiptMigration>();
 }
Beispiel #25
0
 public InitRlp(EthereumRunnerContext context)
 {
 }
Beispiel #26
0
 public StepCStandard(EthereumRunnerContext runnerContext)
 {
 }
Beispiel #27
0
 public SetupKeyStore(EthereumRunnerContext context)
 {
     _context = context;
 }
Beispiel #28
0
 public RegisterRpcModules(EthereumRunnerContext context)
 {
     _context = context;
 }
Beispiel #29
0
 public ReviewBlockTree(EthereumRunnerContext context)
 {
     _context = context;
     _logger  = _context.LogManager.GetClassLogger();
 }
Beispiel #30
0
 public AddSubscription(EthereumRunnerContext context)
 {
     _context = context;
 }