public async Task With_steps_from_here()
        {
            Runner.Ethereum.Api.NethermindApi runnerContext = new Runner.Ethereum.Api.NethermindApi(
                new ConfigProvider(),
                LimboLogs.Instance);

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

            using 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)}");
                }
            }
        }
Esempio n. 2
0
        public void RunMigration(int?migratedBlockNumber)
        {
            var chainLength            = 10;
            var configProvider         = Substitute.For <IConfigProvider>();
            var blockTreeBuilder       = Core.Test.Builders.Build.A.BlockTree().OfChainLength(chainLength);
            var inMemoryReceiptStorage = new InMemoryReceiptStorage()
            {
                MigratedBlockNumber = migratedBlockNumber != null ? 0 : long.MaxValue
            };
            var outMemoryReceiptStorage = new InMemoryReceiptStorage()
            {
                MigratedBlockNumber = migratedBlockNumber != null ? 0 : long.MaxValue
            };
            var context = new Runner.Ethereum.Api.NethermindApi(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.WaitingForBlock);

            int txIndex = 0;

            for (int i = 1; i < chainLength; i++)
            {
                var block = context.BlockTree.FindBlock(i);
                inMemoryReceiptStorage.Insert(block,
                                              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);

            if (migratedBlockNumber.HasValue)
            {
                migration.Run(migratedBlockNumber.Value);
            }
            else
            {
                migration.Run();
            }


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

            context.DbProvider.ReceiptsDb.Received(Quantity.Exactly(txCount)).Remove(Arg.Any <byte[]>());
            outMemoryReceiptStorage.Count.Should().Be(txCount);
        }
        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);
        }
Esempio n. 4
0
        public void Init_merge_plugin_does_not_throw_exception(bool enabled)
        {
            MergeConfig mergeConfig = new() { Enabled = enabled };

            Runner.Ethereum.Api.NethermindApi context = Build.ContextWithMocks();
            context.ConfigProvider.GetConfig <IMergeConfig>().Returns(mergeConfig);
            context.MemDbFactory = new MemDbFactory();
            MergePlugin plugin = new();

            Assert.DoesNotThrowAsync(async() => { await plugin.Init(context); });
            Assert.DoesNotThrow(() => { plugin.InitNetworkProtocol(); });
            Assert.DoesNotThrowAsync(async() => { await plugin.InitRpcModules(); });
            Assert.DoesNotThrowAsync(async() => { await plugin.DisposeAsync(); });
        }
    }
        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 async Task When_no_assemblies_defined()
        {
            Runner.Ethereum.Api.NethermindApi runnerContext = new Runner.Ethereum.Api.NethermindApi(
                new ConfigProvider(),
                new EthereumJsonSerializer(),
                LimboLogs.Instance);

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

            using CancellationTokenSource source = new CancellationTokenSource(TimeSpan.FromSeconds(1));
            await stepsManager.InitializeAll(source.Token);
        }
 public StepCStandard(Runner.Ethereum.Api.NethermindApi runnerContext)
 {
 }
 public StepB(Runner.Ethereum.Api.NethermindApi runnerContext)
 {
 }