コード例 #1
0
ファイル: MinerLifetime.cs プロジェクト: wyk125/AElf
        public async Task SyncGenesisBlock_False_Rollback()
        {
            var chain = await _mock.CreateChain();

            ChainConfig.Instance.ChainId    = chain.Id.DumpHex();
            NodeConfig.Instance.NodeAccount = Address.Generate().DumpHex();

            var block = GenerateBlock(chain.Id, chain.GenesisBlockHash, GlobalConfig.GenesisBlockHeight + 1);

            var txs = CreateTxs(chain.Id);

            block.Body.Transactions.Add(txs[0].GetHash());
            block.Body.Transactions.Add(txs[2].GetHash());

            block.Body.TransactionList.Add(txs[0]);
            block.Body.TransactionList.Add(txs[2]);
            block.FillTxsMerkleTreeRootInHeader();
            block.Body.BlockHeader = block.Header.GetHash();
            block.Sign(new KeyPairGenerator().Generate());

            var manager       = _mock.MinerClientManager();
            var blockExecutor = _mock.GetBlockExecutor(manager);

            var res = await blockExecutor.ExecuteBlock(block);

            Assert.NotEqual(BlockExecutionResult.Success, res);

            var blockchain = _mock.GetBlockChain(chain.Id);
            var curHash    = await blockchain.GetCurrentBlockHashAsync();

            var index = ((BlockHeader)await blockchain.GetHeaderByHashAsync(curHash)).Index;

            Assert.Equal(GlobalConfig.GenesisBlockHeight, index);
            Assert.Equal(chain.GenesisBlockHash.DumpHex(), curHash.DumpHex());
        }