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_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 assembleBlock_should_create_block_on_top_of_genesis() { using MergeTestBlockchain chain = await CreateBlockChain(); IConsensusRpcModule rpc = CreateConsensusModule(chain); Keccak startingHead = chain.BlockTree.HeadHash; UInt256 timestamp = Timestamper.UnixTime.Seconds; AssembleBlockRequest assembleBlockRequest = new() { ParentHash = startingHead, Timestamp = timestamp }; ResultWrapper <BlockRequestResult?> response = await rpc.consensus_assembleBlock(assembleBlockRequest); BlockRequestResult expected = CreateParentBlockRequestOnHead(chain.BlockTree); expected.GasLimit = 4000000L; expected.BlockHash = new Keccak("0xfe37027d377e75ffb161f11733d8880083378fe6236270c7a2ee1fc7efe71cfd"); expected.LogsBloom = Bloom.Empty; expected.Miner = chain.MinerAddress; expected.Number = 1; expected.ParentHash = startingHead; expected.SetTransactions(Array.Empty <Transaction>()); expected.Timestamp = timestamp; response.Data.Should().BeEquivalentTo(expected); }
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); }