public async Task PrepareExtraDataForNextMiningAsync_NotApproved_Test()
        {
            var sideChainId             = 123;
            var sideChainBlockInfoCache = new List <SideChainBlockData>();
            var cachingCount            = 5;

            for (int i = 0; i < cachingCount + CrossChainConstants.DefaultBlockCacheEntityCount; i++)
            {
                sideChainBlockInfoCache.Add(new SideChainBlockData()
                {
                    ChainId = sideChainId,
                    Height  = (i + 1),
                    TransactionStatusMerkleTreeRoot = Hash.FromString((sideChainId + 1).ToString())
                });
            }

            _crossChainTestHelper.AddFakePendingCrossChainIndexingProposal(
                new GetPendingCrossChainIndexingProposalOutput
            {
                Proposer   = SampleAddress.AddressList[0],
                ProposalId = Hash.FromString("ProposalId"),
                ProposedCrossChainBlockData = new CrossChainBlockData
                {
                    SideChainBlockDataList = { sideChainBlockInfoCache }
                },
                ToBeReleased = false,
                ExpiredTime  = TimestampHelper.GetUtcNow().AddSeconds(10)
            });
            var res = await _crossChainIndexingDataService.PrepareExtraDataForNextMiningAsync(Hash.Empty, 1);

            Assert.Empty(res);
        }
Esempio n. 2
0
        public async Task FillExtraData__NotApproved_Test()
        {
            int sideChainId        = _chainOptions.ChainId;
            var sideChainBlockData = new List <SideChainBlockData>();

            for (int i = 0; i < CrossChainConstants.DefaultBlockCacheEntityCount + 1; i++)
            {
                sideChainBlockData.Add(new SideChainBlockData()
                {
                    Height  = i + 1,
                    ChainId = sideChainId
                }
                                       );
            }

            var header = new BlockHeader
            {
                PreviousBlockHash = Hash.FromString("PreviousHash"),
                Height            = 2
            };

            _crossChainTestHelper.AddFakePendingCrossChainIndexingProposal(
                new GetPendingCrossChainIndexingProposalOutput
            {
                Proposer   = SampleAddress.AddressList[0],
                ProposalId = Hash.FromString("ProposalId"),
                ProposedCrossChainBlockData = new CrossChainBlockData
                {
                    SideChainBlockDataList = { sideChainBlockData }
                },
                ToBeReleased = false,
                ExpiredTime  = TimestampHelper.GetUtcNow().AddSeconds(10)
            });
            var bytes = await _crossChainBlockExtraDataProvider.GetExtraDataForFillingBlockHeaderAsync(header);

            Assert.Empty(bytes);
        }
Esempio n. 3
0
        public async Task GenerateTransaction_PendingProposal_Test()
        {
            var sideChainId             = 123;
            var sideChainBlockInfoCache = new List <IBlockCacheEntity>();
            var previousBlockHash       = Hash.FromString("PreviousBlockHash");
            var previousBlockHeight     = 1;

            var cachingCount = 5;

            for (int i = 1; i < cachingCount + CrossChainConstants.DefaultBlockCacheEntityCount; i++)
            {
                var sideChainBlockData = new SideChainBlockData()
                {
                    ChainId = sideChainId,
                    Height  = (i + 1),
                    TransactionStatusMerkleTreeRoot = Hash.FromString((sideChainId + 1).ToString())
                };
                sideChainBlockInfoCache.Add(sideChainBlockData);
            }

            _crossChainTestHelper.AddFakePendingCrossChainIndexingProposal(
                new GetPendingCrossChainIndexingProposalOutput());
            _crossChainTestHelper.AddFakeSideChainIdHeight(sideChainId, 1);
            AddFakeCacheData(new Dictionary <int, List <IBlockCacheEntity> > {
                { sideChainId, sideChainBlockInfoCache }
            });

            var pendingProposal = new GetPendingCrossChainIndexingProposalOutput
            {
                Proposer   = SampleAddress.AddressList[0],
                ProposalId = Hash.FromString("ProposalId"),
                ProposedCrossChainBlockData = new CrossChainBlockData(),
                ToBeReleased = true,
                ExpiredTime  = TimestampHelper.GetUtcNow().AddSeconds(10)
            };

            _crossChainTestHelper.AddFakePendingCrossChainIndexingProposal(pendingProposal);


            var res = await _crossChainIndexingDataService.PrepareExtraDataForNextMiningAsync(previousBlockHash,
                                                                                              previousBlockHeight);

            Assert.Empty(res);

            var smartContractAddress = SampleAddress.AddressList[0];

            _smartContractAddressService.SetAddress(CrossChainSmartContractAddressNameProvider.Name,
                                                    smartContractAddress);

            var transactions =
                await _crossChainIndexingTransactionGenerator.GenerateTransactionsAsync(SampleAddress.AddressList[0],
                                                                                        previousBlockHeight, previousBlockHash);

            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(nameof(CrossChainContractContainer.CrossChainContractStub.ReleaseCrossChainIndexing));

            var proposalIdInParam = Hash.Parser.ParseFrom(transactions[0].Params);

            Assert.Equal(pendingProposal.ProposalId, proposalIdInParam);
        }