public void ProcessTwoBlocks() { Block genesis = new Block(0, null); Block block = new Block(1, genesis.Hash); BlockProcessor processor = new BlockProcessor(); processor.Process(genesis); processor.Process(block); Assert.IsNotNull(processor.BlockChain); Assert.AreEqual(1, processor.BlockChain.BestBlockNumber); Assert.AreEqual(genesis, processor.BlockChain.GetBlock(0)); Assert.AreEqual(block, processor.BlockChain.GetBlock(1)); }
public void Prepared_block_contains_author_field() { ISnapshotableDb stateDb = new StateDb(); ISnapshotableDb codeDb = new StateDb(); IDb traceDb = new MemDb(); IStateProvider stateProvider = new StateProvider(stateDb, codeDb, LimboLogs.Instance); ITransactionProcessor transactionProcessor = Substitute.For <ITransactionProcessor>(); BlockProcessor processor = new BlockProcessor( RinkebySpecProvider.Instance, TestBlockValidator.AlwaysValid, NoBlockRewards.Instance, transactionProcessor, stateDb, codeDb, traceDb, stateProvider, new StorageProvider(stateDb, stateProvider, LimboLogs.Instance), NullTxPool.Instance, NullReceiptStorage.Instance, LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithHeader(header).TestObject; Block[] processedBlocks = processor.Process(Keccak.EmptyTreeHash, new [] { block }, ProcessingOptions.None, NullBlockTracer.Instance); Assert.AreEqual(1, processedBlocks.Length, "length"); Assert.AreEqual(block.Author, processedBlocks[0].Author, "author"); }
public void Can_store_a_witness() { IDb stateDb = new MemDb(); IDb codeDb = new MemDb(); var trieStore = new TrieStore(stateDb, LimboLogs.Instance); IStateProvider stateProvider = new StateProvider(trieStore, codeDb, LimboLogs.Instance); ITransactionProcessor transactionProcessor = Substitute.For <ITransactionProcessor>(); IWitnessCollector witnessCollector = Substitute.For <IWitnessCollector>(); BlockProcessor processor = new BlockProcessor( RinkebySpecProvider.Instance, TestBlockValidator.AlwaysValid, NoBlockRewards.Instance, transactionProcessor, stateProvider, new StorageProvider(trieStore, stateProvider, LimboLogs.Instance), NullTxPool.Instance, NullReceiptStorage.Instance, witnessCollector, LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithHeader(header).TestObject; _ = processor.Process( Keccak.EmptyTreeHash, new List <Block> { block }, ProcessingOptions.None, NullBlockTracer.Instance); witnessCollector.Received(1).Persist(block.Hash); }
public void ProcessTwoBlocksAndTwoUncles() { Block genesis = new Block(0, null); Block block = new Block(1, genesis.Hash); Block uncle1 = new Block(1, genesis.Hash); Block uncle2 = new Block(2, uncle1.Hash); BlockProcessor processor = new BlockProcessor(); processor.Process(genesis); processor.Process(block); processor.Process(uncle1); processor.Process(uncle2); Assert.IsNotNull(processor.BlockChain); Assert.AreEqual(2, processor.BlockChain.BestBlockNumber); Assert.AreEqual(genesis, processor.BlockChain.GetBlock(0)); Assert.AreEqual(uncle1, processor.BlockChain.GetBlock(1)); Assert.AreEqual(uncle2, processor.BlockChain.GetBlock(2)); }
public void ProcessGenesisBlock() { Block genesis = new Block(0, null); BlockProcessor processor = new BlockProcessor(); processor.Process(genesis); Assert.IsNotNull(processor.BlockChain); Assert.AreEqual(0, processor.BlockChain.BestBlockNumber); Assert.AreEqual(genesis, processor.BlockChain.GetBlock(0)); }
public void Recovers_state_on_cancel() { IDb stateDb = new MemDb(); IDb codeDb = new MemDb(); TrieStore trieStore = new TrieStore(stateDb, LimboLogs.Instance); IStateProvider stateProvider = new StateProvider(trieStore, codeDb, LimboLogs.Instance); ITransactionProcessor transactionProcessor = Substitute.For <ITransactionProcessor>(); BlockProcessor processor = new BlockProcessor( RinkebySpecProvider.Instance, TestBlockValidator.AlwaysValid, new RewardCalculator(MainnetSpecProvider.Instance), transactionProcessor, stateProvider, new StorageProvider(trieStore, stateProvider, LimboLogs.Instance), NullTxPool.Instance, NullReceiptStorage.Instance, NullWitnessCollector.Instance, LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithTransactions(1, MuirGlacier.Instance).WithHeader(header).TestObject; Assert.Throws <OperationCanceledException>(() => processor.Process( Keccak.EmptyTreeHash, new List <Block> { block }, ProcessingOptions.None, AlwaysCancelBlockTracer.Instance)); Assert.Throws <OperationCanceledException>(() => processor.Process( Keccak.EmptyTreeHash, new List <Block> { block }, ProcessingOptions.None, AlwaysCancelBlockTracer.Instance)); }