public async Task newBlock_accepts_first_block() { using MergeTestBlockchain chain = await CreateBlockChain(); IConsensusRpcModule rpc = CreateConsensusModule(chain); BlockRequestResult blockRequestResult = CreateBlockRequest( CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper <NewBlockResult> resultWrapper = await rpc.consensus_newBlock(blockRequestResult); resultWrapper.Data.Valid.Should().BeTrue(); new BlockRequestResult(chain.BlockTree.BestSuggestedBody).Should().BeEquivalentTo(blockRequestResult); }
public async Task newBlock_accepts_already_known_block() { using MergeTestBlockchain chain = await CreateBlockChain(); IConsensusRpcModule rpc = CreateConsensusModule(chain); Block block = Build.A.Block.WithNumber(1).WithParent(chain.BlockTree.Head).TestObject; block.Header.Hash = new Keccak("0xdc3419cbd81455372f3e576f930560b35ec828cd6cdfbd4958499e43c68effdf"); chain.BlockTree.SuggestBlock(block); ResultWrapper <NewBlockResult> newBlockResult = await rpc.consensus_newBlock(new BlockRequestResult(block)); newBlockResult.Data.Valid.Should().BeTrue(); }
public async Task newBlock_rejects_incorrect_input(Action <BlockRequestResult> breakerAction) { using MergeTestBlockchain chain = await CreateBlockChain(); IConsensusRpcModule rpc = CreateConsensusModule(chain); BlockRequestResult assembleBlockResult = await GetAssembleBlockResult(chain, rpc); Keccak blockHash = assembleBlockResult.BlockHash; breakerAction(assembleBlockResult); if (blockHash == assembleBlockResult.BlockHash && TryCalculateHash(assembleBlockResult, out var hash)) { assembleBlockResult.BlockHash = hash; } ResultWrapper <NewBlockResult> newBlockResult = await rpc.consensus_newBlock(assembleBlockResult); newBlockResult.Data.Valid.Should().BeFalse(); }
public async Task setHead_should_change_head() { using MergeTestBlockchain chain = await CreateBlockChain(); IConsensusRpcModule rpc = CreateConsensusModule(chain); Keccak startingHead = chain.BlockTree.HeadHash; BlockRequestResult blockRequestResult = CreateBlockRequest( CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper <NewBlockResult> newBlockResult = await rpc.consensus_newBlock(blockRequestResult); newBlockResult.Data.Valid.Should().BeTrue(); Keccak newHeadHash = blockRequestResult.BlockHash; ResultWrapper <Result> setHeadResult = await rpc.consensus_setHead(newHeadHash !); setHeadResult.Data.Should().Be(Result.OK); Keccak actualHead = chain.BlockTree.HeadHash; actualHead.Should().NotBe(startingHead); actualHead.Should().Be(newHeadHash); }