Ejemplo n.º 1
0
        public void Sets_clique_block_producer_properly()
        {
            CliqueConfig        cliqueConfig = new CliqueConfig();
            IBlockTree          blockTree    = Substitute.For <IBlockTree>();
            Signer              signer       = new Signer(ChainId.Ropsten, TestItem.PrivateKeyA, LimboLogs.Instance);
            CliqueBlockProducer producer     = new CliqueBlockProducer(
                Substitute.For <ITxSource>(),
                Substitute.For <IBlockchainProcessor>(),
                Substitute.For <IStateProvider>(),
                blockTree,
                Substitute.For <ITimestamper>(),
                Substitute.For <ICryptoRandom>(),
                Substitute.For <ISnapshotManager>(),
                new CliqueSealer(signer, cliqueConfig, Substitute.For <ISnapshotManager>(), LimboLogs.Instance),
                new TargetAdjustedGasLimitCalculator(GoerliSpecProvider.Instance, new MiningConfig()),
                MainnetSpecProvider.Instance,
                cliqueConfig,
                LimboLogs.Instance);

            SnapshotManager snapshotManager = new SnapshotManager(CliqueConfig.Default, new MemDb(), Substitute.For <IBlockTree>(), NullEthereumEcdsa.Instance, LimboLogs.Instance);

            CliqueRpcModule bridge = new CliqueRpcModule(producer, snapshotManager, blockTree);

            Assert.DoesNotThrow(() => bridge.CastVote(TestItem.AddressB, true));
            Assert.DoesNotThrow(() => bridge.UncastVote(TestItem.AddressB));
            Assert.DoesNotThrow(() => bridge.CastVote(TestItem.AddressB, false));
            Assert.DoesNotThrow(() => bridge.UncastVote(TestItem.AddressB));
        }
        public void Can_ask_for_block_signer_when_hash_is_null()
        {
            ISnapshotManager snapshotManager = Substitute.For <ISnapshotManager>();
            IBlockFinder     blockFinder     = Substitute.For <IBlockFinder>();
            CliqueRpcModule  module          = new CliqueRpcModule(Substitute.For <ICliqueBlockProducer>(), snapshotManager, blockFinder);

            module.clique_getBlockSigner(null).Result.ResultType.Should().Be(ResultType.Failure);
        }
        public void Can_ask_for_block_signer_when_block_is_unknown()
        {
            ISnapshotManager snapshotManager = Substitute.For <ISnapshotManager>();
            IBlockFinder     blockFinder     = Substitute.For <IBlockFinder>();

            blockFinder.FindHeader(Arg.Any <Keccak>()).Returns((BlockHeader)null);
            CliqueRpcModule module = new CliqueRpcModule(Substitute.For <ICliqueBlockProducer>(), snapshotManager, blockFinder);

            module.clique_getBlockSigner(Keccak.Zero).Result.ResultType.Should().Be(ResultType.Failure);
        }
        public void Can_ask_for_block_signer()
        {
            ISnapshotManager snapshotManager = Substitute.For <ISnapshotManager>();
            IBlockFinder     blockFinder     = Substitute.For <IBlockFinder>();
            BlockHeader      header          = Build.A.BlockHeader.TestObject;

            blockFinder.FindHeader(Arg.Any <Keccak>()).Returns(header);
            snapshotManager.GetBlockSealer(header).Returns(TestItem.AddressA);
            CliqueRpcModule module = new CliqueRpcModule(Substitute.For <ICliqueBlockProducer>(), snapshotManager, blockFinder);

            module.clique_getBlockSigner(Keccak.Zero).Result.ResultType.Should().Be(ResultType.Success);
            module.clique_getBlockSigner(Keccak.Zero).Data.Should().Be(TestItem.AddressA);
        }