GenerateConsensusInitializationCallList(ChainInitializationData chainInitializationData)
        {
            var consensusMethodCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            var miners = chainInitializationData == null
                ? new MinerList
            {
                Pubkeys =
                {
                    _consensusOptions.InitialMinerList.Select(p => p.ToByteString())
                }
            }
                : MinerListWithRoundNumber.Parser
            .ParseFrom(chainInitializationData.ChainInitializationConsensusInfo.InitialMinerListData).MinerList;
            var timestamp = chainInitializationData?.CreationTimestamp ?? _consensusOptions.StartTimestamp;

            consensusMethodCallList.Add(nameof(AEDPoSContractContainer.AEDPoSContractStub.InitialAElfConsensusContract),
                                        new InitialAElfConsensusContractInput
            {
                IsSideChain   = true,
                PeriodSeconds = _consensusOptions.PeriodSeconds
            });
            consensusMethodCallList.Add(nameof(AEDPoSContractContainer.AEDPoSContractStub.FirstRound),
                                        miners.GenerateFirstRoundOfNewTerm(_consensusOptions.MiningInterval, timestamp));
            return(consensusMethodCallList);
        }
Example #2
0
        public override ChainInitializationData GetChainInitializationData(SInt32Value chainId)
        {
            var sideChainInfo = State.SideChainInfo[chainId.Value];

            Assert(sideChainInfo != null, "Side chain not found.");
            var res = new ChainInitializationData
            {
                CreationHeightOnParentChain = sideChainInfo.CreationHeightOnParentChain,
                ChainId           = chainId.Value,
                Creator           = sideChainInfo.Proposer,
                CreationTimestamp = sideChainInfo.CreationTimestamp,
                ChainCreatorPrivilegePreserved = sideChainInfo.SideChainCreationRequest.IsPrivilegePreserved
            };
            ByteString consensusInformation = State.SideChainInitialConsensusInfo[chainId.Value].Value;

            res.ExtraInformation.Add(consensusInformation);

            ByteString nativeTokenInformation = GetNativeTokenInfo().ToByteString();

            res.ExtraInformation.Add(nativeTokenInformation);

            ByteString resourceTokenInformation = GetResourceTokenInfo().ToByteString();

            res.ExtraInformation.Add(resourceTokenInformation);

            ByteString sideChainTokenInformation = GetTokenInfo(sideChainInfo.SideChainCreationRequest.SideChainTokenInfo.Symbol)
                                                   .ToByteString();

            res.ExtraInformation.Add(sideChainTokenInformation);
            return(res);
        }
Example #3
0
        GenerateConfigurationInitializationCallList(ChainInitializationData chainInitializationData)
        {
            var configurationContractMethodCallList =
                new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            return(configurationContractMethodCallList);
        }
        private ICrossChainClient MockCrossChainClient(int remoteChainId, bool isConnected,
                                                       Func <ICrossChainBlockEntity, bool> func)
        {
            var mockCrossChainClient = new Mock <ICrossChainClient>();

            mockCrossChainClient.Setup(c => c.RemoteChainId)
            .Returns(() => remoteChainId);
            mockCrossChainClient.Setup(c => c.IsConnected)
            .Returns(() => isConnected);
            mockCrossChainClient.Setup(m => m.RequestChainInitializationDataAsync(It.IsAny <int>())).Returns(
                () =>
            {
                var chainInitialization = new ChainInitializationData
                {
                    CreationHeightOnParentChain = 1,
                };
                return(Task.FromResult(chainInitialization));
            });
            mockCrossChainClient.Setup(m =>
                                       m.RequestCrossChainDataAsync(It.IsAny <long>(),
                                                                    It.IsAny <Func <ICrossChainBlockEntity, bool> >()))
            .Returns(() =>
            {
                func(new ParentChainBlockData());
                return(Task.CompletedTask);
            });
            mockCrossChainClient.Setup(c => c.ConnectAsync()).Returns(() => Task.CompletedTask);
            return(mockCrossChainClient.Object);
        }
        private SystemContractDeploymentInput.Types.SystemTransactionMethodCallList GenerateTokenInitializationCallList(
            ChainInitializationData chainInitializationData)
        {
            var nativeTokenInfo             = TokenInfo.Parser.ParseFrom(chainInitializationData.ExtraInformation[1]);
            var resourceTokenList           = TokenInfoList.Parser.ParseFrom(chainInitializationData.ExtraInformation[2]);
            var chainPrimaryTokenInfo       = TokenInfo.Parser.ParseFrom(chainInitializationData.ExtraInformation[3]);
            var tokenInitializationCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            tokenInitializationCallList.Add(
                nameof(TokenContractContainer.TokenContractStub.RegisterNativeAndResourceTokenInfo),
                new RegisterNativeAndResourceTokenInfoInput
            {
                NativeTokenInfo =
                    new RegisterNativeTokenInfoInput
                {
                    Decimals     = nativeTokenInfo.Decimals,
                    IssueChainId = nativeTokenInfo.IssueChainId,
                    Issuer       = nativeTokenInfo.Issuer,
                    IsBurnable   = nativeTokenInfo.IsBurnable,
                    Symbol       = nativeTokenInfo.Symbol,
                    TokenName    = nativeTokenInfo.TokenName,
                    TotalSupply  = nativeTokenInfo.TotalSupply,
                    IsProfitable = nativeTokenInfo.IsProfitable
                },
                ResourceTokenList = resourceTokenList,
                ChainPrimaryToken = chainPrimaryTokenInfo
            });

            foreach (var issueStuff in chainInitializationData.SideChainTokenInitialIssueList)
            {
                tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.Issue), new IssueInput
                {
                    Symbol = chainPrimaryTokenInfo.Symbol,
                    Amount = issueStuff.Amount,
                    Memo   = "Initial issue",
                    To     = issueStuff.Address
                });
            }

            tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.Initialize),
                                            new InitializeInput
            {
                ResourceAmount =
                {
                    chainInitializationData.InitialResourceAmount.ToDictionary(kv => kv.Key.ToUpper(),
                                                                               kv => kv.Value)
                }
            });

            tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.SetSideChainCreator),
                                            chainInitializationData.Creator);

            return(tokenInitializationCallList);
        }
Example #6
0
        GenerateCrossChainInitializationCallList(ChainInitializationData chainInitializationData)
        {
            var crossChainMethodCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            crossChainMethodCallList.Add(nameof(CrossChainContractContainer.CrossChainContractStub.Initialize),
                                         new AElf.Contracts.CrossChain.InitializeInput
            {
                ParentChainId = _sideChainInitializationDataProvider.ParentChainId,
                CreationHeightOnParentChain = chainInitializationData.CreationHeightOnParentChain
            });
            return(crossChainMethodCallList);
        }
        GenerateParliamentInitializationCallList(ChainInitializationData chainInitializationData)
        {
            var parliamentInitializationCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            parliamentInitializationCallList.Add(
                nameof(ParliamentContractContainer.ParliamentContractStub.Initialize),
                new Contracts.Parliament.InitializeInput
            {
                PrivilegedProposer        = chainInitializationData.Creator,
                ProposerAuthorityRequired = chainInitializationData.ChainCreatorPrivilegePreserved
            });
            return(parliamentInitializationCallList);
        }
Example #8
0
        GenerateConfigurationInitializationCallList(ChainInitializationData chainInitializationData)
        {
            var configurationContractMethodCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();
            var requiredAcsInContracts = new RequiredAcsInContracts();

            if (!chainInitializationData.ChainCreatorPrivilegePreserved)
            {
                requiredAcsInContracts.AcsList.AddRange(_contractOptions.ContractFeeStrategyAcsList);
            }
            configurationContractMethodCallList.Add(nameof(ConfigurationContainer.ConfigurationStub.SetRequiredAcsInContracts),
                                                    requiredAcsInContracts);
            return(configurationContractMethodCallList);
        }
        public override ChainInitializationData GetChainInitializationData(Int32Value input)
        {
            var sideChainInfo            = State.SideChainInfo[input.Value];
            var sideChainCreationRequest = State.AcceptedSideChainCreationRequest[input.Value];

            Assert(sideChainInfo != null && sideChainCreationRequest != null, "Side chain not found.");

            SetContractStateRequired(State.TokenContract, SmartContractConstants.TokenContractSystemName);
            var res = new ChainInitializationData
            {
                CreationHeightOnParentChain = sideChainInfo.CreationHeightOnParentChain,
                ChainId           = input.Value,
                Creator           = sideChainInfo.Proposer,
                CreationTimestamp = sideChainInfo.CreationTimestamp,
                ChainCreatorPrivilegePreserved  = sideChainInfo.IsPrivilegePreserved,
                ParentChainTokenContractAddress = State.TokenContract.Value
            };
            ByteString consensusInformation = State.SideChainInitialConsensusInfo[input.Value].Value;

            res.ChainInitializationConsensusInfo = new ChainInitializationConsensusInfo
            {
                InitialMinerListData = consensusInformation
            };

            ByteString nativeTokenInformation = GetNativeTokenInfo().ToByteString();

            res.NativeTokenInfoData = nativeTokenInformation;

            ByteString resourceTokenInformation = GetResourceTokenInfo().ToByteString();

            res.ResourceTokenInfo = new ResourceTokenInfo
            {
                ResourceTokenListData = resourceTokenInformation,
                InitialResourceAmount = { sideChainCreationRequest.InitialResourceAmount }
            };

            if (sideChainCreationRequest.IsPrivilegePreserved)
            {
                ByteString sideChainTokenInformation =
                    GetTokenInfo(sideChainCreationRequest.SideChainTokenSymbol).ToByteString();
                res.ChainPrimaryTokenInfo = new ChainPrimaryTokenInfo
                {
                    ChainPrimaryTokenData          = sideChainTokenInformation,
                    SideChainTokenInitialIssueList = { sideChainCreationRequest.SideChainTokenInitialIssueList },
                };
            }

            return(res);
        }
Example #10
0
        private ChainInitializationData GetChainInitializationData(SideChainInfo sideChainInfo,
                                                                   SideChainCreationRequest sideChainCreationRequest)
        {
            SetContractStateRequired(State.TokenContract, SmartContractConstants.TokenContractSystemName);
            var res = new ChainInitializationData
            {
                CreationHeightOnParentChain = sideChainInfo.CreationHeightOnParentChain,
                ChainId           = sideChainInfo.SideChainId,
                Creator           = sideChainInfo.Proposer,
                CreationTimestamp = sideChainInfo.CreationTimestamp,
                ChainCreatorPrivilegePreserved  = sideChainInfo.IsPrivilegePreserved,
                ParentChainTokenContractAddress = State.TokenContract.Value
            };

            var initialConsensusInfo = GetInitialConsensusInformation();

            res.ChainInitializationConsensusInfo = new ChainInitializationConsensusInfo
            {
                InitialConsensusData = initialConsensusInfo
            };

            ByteString nativeTokenInformation = GetNativeTokenInfo().ToByteString();

            res.NativeTokenInfoData = nativeTokenInformation;

            ByteString resourceTokenInformation = GetResourceTokenInfo().ToByteString();

            res.ResourceTokenInfo = new ResourceTokenInfo
            {
                ResourceTokenListData = resourceTokenInformation,
                InitialResourceAmount = { sideChainCreationRequest.InitialResourceAmount }
            };

            if (IsPrimaryTokenNeeded(sideChainCreationRequest))
            {
                ByteString sideChainTokenInformation =
                    GetTokenInfo(sideChainCreationRequest.SideChainTokenCreationRequest.SideChainTokenSymbol).ToByteString();
                res.ChainPrimaryTokenInfo = new ChainPrimaryTokenInfo
                {
                    ChainPrimaryTokenData          = sideChainTokenInformation,
                    SideChainTokenInitialIssueList = { sideChainCreationRequest.SideChainTokenInitialIssueList },
                };
            }

            return(res);
        }
Example #11
0
        public async Task <ChainInitializationData> GetChainInitializationDataAsync()
        {
            if (_chainInitializationData != null)
            {
                return(_chainInitializationData);
            }

            var chain = await _blockchainService.GetChainAsync();

            if (chain != null)
            {
                return(null);
            }

            _chainInitializationData =
                await _chainInitializationDataPlugin.GetChainInitializationDataAsync(_chainOptions.ChainId);

            if (_chainInitializationData == null)
            {
                throw new Exception("Initialization data cannot be null for a new side chain.");
            }

            return(_chainInitializationData);
        }
        private SystemContractDeploymentInput.Types.SystemTransactionMethodCallList GenerateTokenInitializationCallList(ChainInitializationData chainInitializationData)
        {
            var nativeTokenInfo             = TokenInfo.Parser.ParseFrom(chainInitializationData.ExtraInformation[1]);
            var resourceTokenList           = TokenInfoList.Parser.ParseFrom(chainInitializationData.ExtraInformation[2]);
            var chainPrimaryTokenInfo       = TokenInfo.Parser.ParseFrom(chainInitializationData.ExtraInformation[3]);
            var tokenInitializationCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            tokenInitializationCallList.Add(
                nameof(TokenContractContainer.TokenContractStub.RegisterNativeAndResourceTokenInfo),
                new RegisterNativeAndResourceTokenInfoInput
            {
                NativeTokenInfo =
                    new RegisterNativeTokenInfoInput
                {
                    Decimals     = nativeTokenInfo.Decimals,
                    IssueChainId = nativeTokenInfo.IssueChainId,
                    Issuer       = nativeTokenInfo.Issuer,
                    IsBurnable   = nativeTokenInfo.IsBurnable,
                    Symbol       = nativeTokenInfo.Symbol,
                    TokenName    = nativeTokenInfo.TokenName,
                    TotalSupply  = nativeTokenInfo.TotalSupply
                },
                ResourceTokenList = resourceTokenList,
                ChainPrimaryToken = chainPrimaryTokenInfo
            });

            tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.Issue), new IssueInput
            {
                Symbol = chainPrimaryTokenInfo.Symbol,
                Amount = chainPrimaryTokenInfo.TotalSupply / SideChainStartupConstants.SideChainPrimaryTokenInitialIssueRatio,
                Memo   = "Initial issue",
                To     = chainPrimaryTokenInfo.Issuer
            });

            return(tokenInitializationCallList);
        }
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            base.ConfigureServices(context);

            var dictionary = new Dictionary <long, Hash>
            {
                { 1, Hash.FromString("1") },
                { 2, Hash.FromString("2") },
                { 3, Hash.FromString("3") }
            };

            Configure <GrpcCrossChainConfigOption>(option =>
            {
                option.ListeningPort         = 5001;
                option.ParentChainServerIp   = "127.0.0.1";
                option.ParentChainServerPort = 5000;
            });

            Configure <CrossChainConfigOptions>(option =>
            {
                option.ParentChainId = ChainHelper.ConvertChainIdToBase58(ChainHelper.GetChainId(1));
            });

            context.Services.AddTransient(provider =>
            {
                var kernelTestHelper      = context.Services.GetRequiredServiceLazy <KernelTestHelper>();
                var mockBlockChainService = new Mock <IBlockchainService>();
                mockBlockChainService.Setup(m => m.GetChainAsync()).Returns(() =>
                {
                    var chain = new Chain {
                        LastIrreversibleBlockHeight = 10
                    };
                    return(Task.FromResult(chain));
                });
                mockBlockChainService.Setup(m =>
                                            m.GetBlockHashByHeightAsync(It.IsAny <Chain>(), It.IsAny <long>(), It.IsAny <Hash>()))
                .Returns <Chain, long, Hash>((chain, height, hash) =>
                {
                    if (height > 0 && height <= 3)
                    {
                        return(Task.FromResult(dictionary[height]));
                    }
                    return(Task.FromResult <Hash>(null));
                });
                mockBlockChainService.Setup(m => m.GetBlockByHashAsync(It.IsAny <Hash>())).Returns <Hash>(hash =>
                {
                    foreach (var kv in dictionary)
                    {
                        if (kv.Value.Equals(hash))
                        {
                            var block = kernelTestHelper.Value.GenerateBlock(kv.Key - 1, dictionary[kv.Key - 1]);
                            return(Task.FromResult(block));
                        }
                    }

                    return(Task.FromResult <Block>(null));
                });
                return(mockBlockChainService.Object);
            });

            context.Services.AddTransient(provider =>
            {
                var mockBlockExtraDataService = new Mock <IBlockExtraDataService>();
                mockBlockExtraDataService
                .Setup(m => m.GetExtraDataFromBlockHeader(It.IsAny <string>(), It.IsAny <BlockHeader>())).Returns(
                    () =>
                {
                    var crossExtraData = new CrossChainExtraData()
                    {
                        TransactionStatusMerkleTreeRoot = Hash.FromString("SideChainBlockHeadersRoot"),
                    };
                    return(ByteString.CopyFrom(crossExtraData.ToByteArray()));
                });
                return(mockBlockExtraDataService.Object);
            });

            context.Services.AddTransient(provider =>
            {
                var mockCrossChainIndexingDataService = new Mock <ICrossChainIndexingDataService>();
                mockCrossChainIndexingDataService
                .Setup(m => m.GetIndexedCrossChainBlockDataAsync(It.IsAny <Hash>(), It.IsAny <long>()))
                .Returns(() =>
                {
                    var crossChainBlockData = new CrossChainBlockData
                    {
                        SideChainBlockDataList =
                        {
                            new SideChainBlockData
                            {
                                ChainId = 123, Height = 1,
                                TransactionStatusMerkleTreeRoot = Hash.FromString("fakeTransactionMerkleTree")
                            }
                        }
                    };
                    return(Task.FromResult(crossChainBlockData));
                });
                mockCrossChainIndexingDataService
                .Setup(m => m.GetIndexedSideChainBlockDataAsync(It.IsAny <Hash>(), It.IsAny <long>())).Returns(
                    () =>
                {
                    var indexedSideChainBlockData = new IndexedSideChainBlockData
                    {
                        SideChainBlockDataList =
                        {
                            new SideChainBlockData
                            {
                                ChainId = 123, Height = 1,
                                TransactionStatusMerkleTreeRoot = Hash.FromString("fakeTransactionMerkleTree")
                            }
                        }
                    };
                    return(Task.FromResult(indexedSideChainBlockData));
                });
                return(mockCrossChainIndexingDataService.Object);
            });

            context.Services.AddTransient(provider =>
            {
                var mockCrossChainClientProvider = new Mock <ICrossChainClientProvider>();
                mockCrossChainClientProvider.Setup(m => m.CreateCrossChainClient(It.IsAny <CrossChainClientDto>()))
                .Returns(() =>
                {
                    var mockCrossChainClient = new Mock <ICrossChainClient>();
                    mockCrossChainClient.Setup(m => m.RequestChainInitializationDataAsync(It.IsAny <int>())).Returns(
                        () =>
                    {
                        var chainInitialization = new ChainInitializationData
                        {
                            CreationHeightOnParentChain = 1
                        };
                        return(Task.FromResult(chainInitialization));
                    });
                    mockCrossChainClient.Setup(m =>
                                               m.RequestCrossChainDataAsync(It.IsAny <long>(),
                                                                            It.IsAny <Func <IBlockCacheEntity, bool> >()))
                    .Returns(() =>
                    {
                        var chainInitialization = new ChainInitializationData
                        {
                            CreationHeightOnParentChain = 1
                        };
                        return(Task.FromResult(chainInitialization));
                    });
                    return(mockCrossChainClient.Object);
                });
                return(mockCrossChainClientProvider.Object);
            });

            context.Services.AddSingleton <CrossChainPlugin>();

            context.Services.AddSingleton <IConsensusExtraDataNameProvider, MockConsensusExtraDataProvider>();
        }
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var services = context.Services;

            services.AddSingleton <IGrpcCrossChainServer, GrpcCrossChainServer>();
            services.AddSingleton <GrpcCrossChainCommunicationTestHelper>();
            Configure <ChainOptions>(option => { option.ChainId = ChainHelper.ConvertBase58ToChainId("AELF"); });

            services.AddTransient(o =>
            {
                var mockService = new Mock <IBlockchainService>();
                mockService.Setup(m => m.GetChainAsync())
                .Returns(Task.FromResult(new Chain
                {
                    LastIrreversibleBlockHeight = 1
                }));
                return(mockService.Object);
            });
            services.AddTransient(o =>
            {
                var mockCrossChainService = new Mock <ICrossChainService>();
                mockCrossChainService
                .Setup(c => c.GetChainInitializationDataAsync(It.IsAny <int>())).Returns(async() =>
                                                                                         await Task.FromResult(new ChainInitializationData
                {
                    CreationHeightOnParentChain = 1,
                }));
                return(mockCrossChainService.Object);
            });

            services.AddTransient(o =>
            {
                var mockService = new Mock <ICrossChainCacheEntityService>();
                return(mockService.Object);
            });

            services.AddTransient(o =>
            {
                var mockBlockCacheEntityProvider = new Mock <IBlockCacheEntityProducer>();
                mockBlockCacheEntityProvider.Setup(m => m.TryAddBlockCacheEntity(It.IsAny <IBlockCacheEntity>()))
                .Returns <IBlockCacheEntity>(
                    blockCacheEntity =>
                {
                    if (!GrpcCrossChainCommunicationTestHelper.ClientBlockDataEntityCache.Contains(
                            blockCacheEntity))
                    {
                        GrpcCrossChainCommunicationTestHelper.ClientBlockDataEntityCache.Add(blockCacheEntity);
                        return(true);
                    }

                    return(false);
                });
                return(mockBlockCacheEntityProvider.Object);
            });

            services.AddTransient(o =>
            {
                var mockCrossChainResponseService = new Mock <ICrossChainResponseService>();
                int i = 0;
                mockCrossChainResponseService.Setup(b => b.ResponseSideChainBlockDataAsync(It.IsAny <long>()))
                .Returns(
                    async() =>
                {
                    if (i >= GrpcCrossChainCommunicationTestHelper.ServerBlockDataEntityCache.Count)
                    {
                        return(null);
                    }
                    return(await Task.FromResult(GrpcCrossChainCommunicationTestHelper.ServerBlockDataEntityCache[i++]));
                });

                mockCrossChainResponseService
                .Setup(m => m.ResponseChainInitializationDataFromParentChainAsync(It.IsAny <int>())).Returns(async() =>
                {
                    var chainInitializationData = new ChainInitializationData
                    {
                        CreationHeightOnParentChain = 1
                    };
                    return(await Task.FromResult(chainInitializationData));
                });
                return(mockCrossChainResponseService.Object);
            });
        }
        private SystemContractDeploymentInput.Types.SystemTransactionMethodCallList GenerateTokenInitializationCallList(
            ChainInitializationData chainInitializationData)
        {
            var nativeTokenInfo   = TokenInfo.Parser.ParseFrom(chainInitializationData.NativeTokenInfoData);
            var resourceTokenList =
                TokenInfoList.Parser.ParseFrom(chainInitializationData.ResourceTokenInfo.ResourceTokenListData);
            var tokenInitializationCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            // native token
            tokenInitializationCallList.Add(
                nameof(TokenContractContainer.TokenContractStub.Create),
                GenerateTokenCreateInput(nativeTokenInfo));

            // resource token
            foreach (var resourceTokenInfo in resourceTokenList.Value)
            {
                tokenInitializationCallList.Add(
                    nameof(TokenContractContainer.TokenContractStub.Create),
                    GenerateTokenCreateInput(resourceTokenInfo));
            }

            tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.InitializeFromParentChain),
                                            new InitializeFromParentChainInput
            {
                ResourceAmount =
                {
                    chainInitializationData.ResourceTokenInfo.InitialResourceAmount.ToDictionary(
                        kv => kv.Key.ToUpper(),
                        kv => kv.Value)
                },
                RegisteredOtherTokenContractAddresses =
                {
                    [_sideChainInitializationDataProvider.ParentChainId] =
                        chainInitializationData.ParentChainTokenContractAddress
                },
                Creator = chainInitializationData.Creator
            });

            tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.InitialCoefficients),
                                            new Empty());

            if (chainInitializationData.ChainPrimaryTokenInfo != null)
            {
                // primary token
                var chainPrimaryTokenInfo =
                    TokenInfo.Parser.ParseFrom(chainInitializationData.ChainPrimaryTokenInfo.ChainPrimaryTokenData);

                tokenInitializationCallList.Add(
                    nameof(TokenContractContainer.TokenContractStub.Create),
                    GenerateTokenCreateInput(chainPrimaryTokenInfo));

                foreach (var issueStuff in chainInitializationData.ChainPrimaryTokenInfo.SideChainTokenInitialIssueList)
                {
                    tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.Issue),
                                                    new IssueInput
                    {
                        Symbol = chainPrimaryTokenInfo.Symbol,
                        Amount = issueStuff.Amount,
                        Memo   = "Initial issue",
                        To     = issueStuff.Address
                    });
                }

                tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.SetPrimaryTokenSymbol),
                                                new SetPrimaryTokenSymbolInput
                {
                    Symbol = chainPrimaryTokenInfo.Symbol
                });
            }
            else
            {
                // set primary token with native token
                tokenInitializationCallList.Add(nameof(TokenContractContainer.TokenContractStub.SetPrimaryTokenSymbol),
                                                new SetPrimaryTokenSymbolInput
                {
                    Symbol = nativeTokenInfo.Symbol
                });
            }

            return(tokenInitializationCallList);
        }
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            base.ConfigureServices(context);

            var services = context.Services;

            services.AddTransient(o =>
            {
                var kernelTestHelper = context.Services.GetRequiredServiceLazy <KernelTestHelper>();
                var mockService      = new Mock <IBlockchainService>();
                mockService.Setup(m => m.GetChainAsync())
                .Returns(Task.FromResult(new Chain
                {
                    LastIrreversibleBlockHeight = 10
                }));
                mockService.Setup(m =>
                                  m.GetBlockHashByHeightAsync(It.IsAny <Chain>(), It.IsAny <long>(), It.IsAny <Hash>()))
                .Returns(Task.FromResult(Hash.FromString("hash")));
                mockService.Setup(m => m.GetBlockByHashAsync(It.IsAny <Hash>()))
                .Returns(() =>
                {
                    var previousBlockHash = Hash.FromString("previousBlockHash");
                    return(Task.FromResult(kernelTestHelper.Value.GenerateBlock(9, previousBlockHash)));
                });
                return(mockService.Object);
            });

            services.AddTransient(o =>
            {
                var mockCrossChainDataProvider = new Mock <ICrossChainService>();
                mockCrossChainDataProvider
                .Setup(c => c.GetChainInitializationDataAsync(It.IsAny <int>())).Returns(async() =>
                                                                                         await Task.FromResult(new ChainInitializationData
                {
                    CreationHeightOnParentChain = 1,
                }));
                return(mockCrossChainDataProvider.Object);
            });

            services.AddTransient(o =>
            {
                var mockCrossChainResponseService = new Mock <ICrossChainResponseService>();
                mockCrossChainResponseService
                .Setup(c => c.ResponseParentChainBlockDataAsync(It.IsAny <long>(), It.IsAny <int>())).Returns <long, int>(
                    (height, chainId) =>
                {
                    if (height > 100)
                    {
                        return(Task.FromResult <ParentChainBlockData>(null));
                    }

                    var parentChanBlockData = new ParentChainBlockData
                    {
                        ChainId = chainId,
                        Height  = height,
                        TransactionStatusMerkleRoot = Hash.FromString("TransactionStatusMerkleRoot")
                    };
                    return(Task.FromResult(parentChanBlockData));
                });
                mockCrossChainResponseService
                .Setup(c => c.ResponseSideChainBlockDataAsync(It.IsAny <long>())).Returns(
                    () =>
                {
                    var sideChanBlockData = new SideChainBlockData()
                    {
                        ChainId = ChainHelper.GetChainId(1),
                        Height  = 10,
                    };
                    return(Task.FromResult(sideChanBlockData));
                });
                mockCrossChainResponseService
                .Setup(c => c.ResponseChainInitializationDataFromParentChainAsync(It.IsAny <int>())).Returns(
                    () =>
                {
                    var chainInitializationData = new ChainInitializationData()
                    {
                        CreationHeightOnParentChain = 1
                    };
                    return(Task.FromResult(chainInitializationData));
                });
                return(mockCrossChainResponseService.Object);
            });

            services.AddTransient(o =>
            {
                var mockService = new Mock <ICrossChainCacheEntityService>();
                return(mockService.Object);
            });
        }
        private SystemContractDeploymentInput.Types.SystemTransactionMethodCallList GenerateTokenInitializationCallList(ChainInitializationData chainInitializationData)
        {
            var nativeTokenInfo             = TokenInfo.Parser.ParseFrom(chainInitializationData.ExtraInformation[1]);
            var tokenInitializationCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            tokenInitializationCallList.Add(
                nameof(TokenContractContainer.TokenContractStub.RegisterNativeTokenInfo),
                new RegisterNativeTokenInfoInput
            {
                Decimals     = nativeTokenInfo.Decimals,
                IssueChainId = nativeTokenInfo.IssueChainId,
                Issuer       = nativeTokenInfo.Issuer,
                IsBurnable   = nativeTokenInfo.IsBurnable,
                Symbol       = nativeTokenInfo.Symbol,
                TokenName    = nativeTokenInfo.TokenName,
                TotalSupply  = nativeTokenInfo.TotalSupply
            });

            return(tokenInitializationCallList);
        }