public async Task GenerateTransactions_Test()
        {
            var transactions = new List <Transaction>();

            _crossChainIndexingTransactionGenerator.GenerateTransactions(SampleAddress.AddressList[0], 0, Hash.Empty, ref transactions);
            transactions.Count.ShouldBe(0);

            var chainId             = _kernelTestHelper.BestBranchBlockList[0].Header.ChainId;
            var previousBlockHash   = _kernelTestHelper.BestBranchBlockList[3].GetHash();
            var previousBlockHeight = _kernelTestHelper.BestBranchBlockList[3].Height;

            _crossChainTestHelper.AddFakeSideChainIdHeight(chainId, previousBlockHeight);

            var blockInfoCache = new List <IBlockCacheEntity>();
            var cachingCount   = CrossChainConstants.MinimalBlockCacheEntityCount + 1;

            for (var i = 1; i <= cachingCount; i++)
            {
                var sideChainBlockData = new SideChainBlockData
                {
                    ChainId = chainId,
                    Height  = previousBlockHeight + i,
                };
                blockInfoCache.Add(sideChainBlockData);
            }

            var fakeCache = new Dictionary <int, List <IBlockCacheEntity> > {
                { chainId, blockInfoCache }
            };

            AddFakeCacheData(fakeCache);

            var smartContractAddress = SampleAddress.AddressList[0];

            _smartContractAddressService.SetAddress(CrossChainSmartContractAddressNameProvider.Name,
                                                    smartContractAddress);

            await _crossChainIndexingDataService.GetCrossChainBlockDataForNextMiningAsync(previousBlockHash, previousBlockHeight);

            _crossChainIndexingTransactionGenerator.GenerateTransactions(SampleAddress.AddressList[0], previousBlockHeight, previousBlockHash, ref transactions);

            transactions.Count.ShouldBe(1);
            transactions[0].From.ShouldBe(SampleAddress.AddressList[0]);
            transactions[0].To.ShouldBe(smartContractAddress);
            transactions[0].RefBlockNumber.ShouldBe(previousBlockHeight);
            transactions[0].RefBlockPrefix.ShouldBe(ByteString.CopyFrom(previousBlockHash.Value.Take(4).ToArray()));
            transactions[0].MethodName.ShouldBe(CrossChainConstants.CrossChainIndexingMethodName);

            var crossChainBlockData = CrossChainBlockData.Parser.ParseFrom(transactions[0].Params);

            crossChainBlockData.PreviousBlockHeight.ShouldBe(previousBlockHeight);
            crossChainBlockData.ParentChainBlockData.Count.ShouldBe(0);
            crossChainBlockData.SideChainBlockData.Count.ShouldBe(
                cachingCount - CrossChainConstants.MinimalBlockCacheEntityCount);
            crossChainBlockData.SideChainBlockData[0].ChainId.ShouldBe(chainId);
            crossChainBlockData.SideChainBlockData[0].Height.ShouldBe(previousBlockHeight + 1);
        }
Пример #2
0
        public void Generate_SystemTransactions()
        {
            var transactions = new List <Transaction>();

            _systemTransactionGenerator.GenerateTransactions(SampleAddress.AddressList[0], 0L, Hash.Empty, ref transactions);
            transactions.Count.ShouldBe(2);
        }
Пример #3
0
        public void GenerateTransactions()
        {
            var address      = Address.Generate();
            var blockHeight  = 100;
            var hash         = Hash.Generate();
            var transactions = new List <Transaction>();

            _systemTransactionGenerator.GenerateTransactions(address, blockHeight, hash, ref transactions);
            transactions.Count.ShouldBe(3);
            transactions.Select(t => t.MethodName).ShouldAllBe(x => x == ConsensusConsts.GenerateConsensusTransactions);
        }