Exemplo n.º 1
0
        public async Task CalculateFunctionMap_Test()
        {
            var genesisBlock = KernelTestHelper.GenerateBlock(0, Hash.Empty, new List <Transaction>());
            var chain        = await BlockchainService.CreateChainAsync(genesisBlock, new List <Transaction>());

            var blockStateSet = new BlockStateSet
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            };
            await BlockStateSetManger.SetBlockStateSetAsync(blockStateSet);

            var functionMapDict = new Dictionary <string, Dictionary <string, CalculateFunction> >();
            var functionMap     = GenerateFunctionMap();

            functionMapDict.Add(GetBlockExecutedDataKey(), functionMap);

            await _calculateFunctionExecutedDataService.AddBlockExecutedDataAsync(new BlockIndex
            {
                BlockHash   = blockStateSet.BlockHash,
                BlockHeight = blockStateSet.BlockHeight
            },
                                                                                  functionMapDict);

            var newBlockStateSet = await BlockStateSetManger.GetBlockStateSetAsync(chain.BestChainHash);

            newBlockStateSet.BlockHash.ShouldBe(blockStateSet.BlockHash);
            newBlockStateSet.BlockHeight.ShouldBe(blockStateSet.BlockHeight);
            newBlockStateSet.BlockExecutedData.Count.ShouldBe(1);
            newBlockStateSet.BlockExecutedData.Keys.ShouldContain(key =>
                                                                  key.Contains(typeof(AllCalculateFeeCoefficients).Name));

            blockStateSet = await AddBlockStateSetAsync(blockStateSet);

            CheckBlockExecutedData(blockStateSet, functionMap);
            await BlockchainStateService.MergeBlockStateAsync(chain.BestChainHeight, chain.BestChainHash);

            CheckBlockExecutedData(blockStateSet, functionMap);

            blockStateSet = await AddBlockStateSetAsync(blockStateSet);

            CheckBlockExecutedData(blockStateSet, functionMap);
        }
Exemplo n.º 2
0
        public async Task CalculateFunctionMap_Test()
        {
            var genesisBlock = KernelTestHelper.GenerateBlock(0, Hash.Empty, new List <Transaction>());
            var chain        = await BlockchainService.CreateChainAsync(genesisBlock, new List <Transaction>());

            var blockStateSet = new BlockStateSet
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            };
            await BlockStateSetManger.SetBlockStateSetAsync(blockStateSet);

            var blockExecutedDataKey = "BlockExecutedData/AllCalculateFeeCoefficients";

            blockStateSet.BlockExecutedData.ShouldNotContainKey(blockExecutedDataKey);
            var functionMap = GenerateFunctionMap();
            await _calculateFunctionProvider.AddCalculateFunctions(new BlockIndex
            {
                BlockHash   = blockStateSet.BlockHash,
                BlockHeight = blockStateSet.BlockHeight
            },
                                                                   functionMap);

            var newBlockStateSet = await BlockStateSetManger.GetBlockStateSetAsync(chain.BestChainHash);

            newBlockStateSet.BlockHash.ShouldBe(blockStateSet.BlockHash);
            newBlockStateSet.BlockHeight.ShouldBe(blockStateSet.BlockHeight);
            newBlockStateSet.BlockExecutedData.Count.ShouldBe(1);
            newBlockStateSet.BlockExecutedData.ShouldContainKey(blockExecutedDataKey);

            blockStateSet = await AddBlockStateSetAsync(blockStateSet);

            CheckBlockExecutedData(blockStateSet, functionMap);
            await BlockchainStateService.MergeBlockStateAsync(chain.BestChainHeight, chain.BestChainHash);

            CheckBlockExecutedData(blockStateSet, functionMap);

            blockStateSet = await AddBlockStateSetAsync(blockStateSet);

            CheckBlockExecutedData(blockStateSet, functionMap);
        }