public async Task <OsBlockchainNodeContext> InitialChainAsyncWithAuthAsync( Action <List <GenesisSmartContractDto> > configureSmartContract = null) { var osBlockchainNodeContextService = Application.ServiceProvider.GetRequiredService <IOsBlockchainNodeContextService>(); var contractOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ContractOptions> >().Value; var consensusOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ConsensusOptions> >().Value; consensusOptions.StartTimestamp = TimestampHelper.GetUtcNow(); var dto = new OsBlockchainNodeContextStartDto { ChainId = ChainHelper.ConvertBase58ToChainId("AELF"), ZeroSmartContract = typeof(BasicContractZero), SmartContractRunnerCategory = SmartContractTestConstants.TestRunnerCategory, ContractDeploymentAuthorityRequired = contractOptions.ContractDeploymentAuthorityRequired }; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name, GenerateConsensusInitializationCallList(consensusOptions)); configureSmartContract?.Invoke(dto.InitializationSmartContracts); return(await osBlockchainNodeContextService.StartAsync(dto)); }
public async Task RequestCrossChainData_Test() { var chainId = ChainHelper.GetChainId(ChainHelper.ConvertBase58ToChainId("AELF") + 1); var remoteChainId = ChainOptions.ChainId; var height = 2; var port = 5000; await Server.StartAsync(port); var grpcClientInitializationContext = new GrpcClientInitializationContext { RemoteChainId = chainId, LocalChainId = ChainHelper.ConvertBase58ToChainId("AELF"), DialTimeout = 1000, UriStr = string.Concat(Host, ":", port) }; var client = new ClientForSideChain(grpcClientInitializationContext); _grpcCrossChainCommunicationTestHelper.GrpcCrossChainClients.TryAdd(remoteChainId, client); _grpcCrossChainCommunicationTestHelper.FakeSideChainBlockDataEntityCacheOnServerSide(height); await client.RequestCrossChainDataAsync(height, b => _blockCacheEntityProducer.TryAddBlockCacheEntity(b)); var clientBlockDataEntityCache = GrpcCrossChainCommunicationTestHelper.ClientBlockDataEntityCache; var sideChainBlockData = new SideChainBlockData { Height = height }; Assert.Contains(sideChainBlockData, clientBlockDataEntityCache); Dispose(); }
public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); Configure <EconomicOptions>(configuration.GetSection("Economic")); Configure <ChainOptions>(option => { option.ChainId = ChainHelper.ConvertBase58ToChainId(context.Services.GetConfiguration()["ChainId"]); option.ChainType = context.Services.GetConfiguration().GetValue("ChainType", ChainType.MainChain); option.NetType = context.Services.GetConfiguration().GetValue("NetType", NetType.MainNet); }); Configure <HostSmartContractBridgeContextOptions>(options => { options.ContextVariables[ContextVariableDictionary.NativeSymbolName] = context.Services .GetConfiguration().GetValue("Economic:Symbol", "ELF"); options.ContextVariables[ContextVariableDictionary.PayTxFeeSymbolList] = context.Services .GetConfiguration() .GetValue("Economic:SymbolListToPayTxFee", "WRITE,READ,STORAGE,TRAFFIC"); options.ContextVariables[ContextVariableDictionary.PayRentalSymbolList] = context.Services .GetConfiguration().GetValue("Economic:SymbolListToPayRental", "CPU,RAM,DISK,NET"); }); Configure <ContractOptions>(configuration.GetSection("Contract")); Configure <ContractOptions>(options => { options.GenesisContractDir = Path.Combine(context.Services.GetHostingEnvironment().ContentRootPath, "genesis"); options.ContractFeeStrategyAcsList = new List <string> { "acs1", "acs8" }; }); }
public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); Configure <EconomicOptions>(configuration.GetSection("Economic")); Configure <ChainOptions>(option => { option.ChainId = ChainHelper.ConvertBase58ToChainId(context.Services.GetConfiguration()["ChainId"]); option.ChainType = context.Services.GetConfiguration().GetValue("ChainType", ChainType.MainChain); option.NetType = context.Services.GetConfiguration().GetValue("NetType", NetType.MainNet); }); Configure <HostSmartContractBridgeContextOptions>(options => { options.ContextVariables[ContextVariableDictionary.NativeSymbolName] = context.Services .GetConfiguration().GetValue("Economic:Symbol", "ELF"); }); Configure <ContractOptions>(configuration.GetSection("Contract")); Configure <ContractOptions>(options => { options.GenesisContractDir = Path.Combine(context.Services.GetHostingEnvironment().ContentRootPath, "genesis"); }); }
public async Task Create_SideChain() { await InitializeCrossChainContractAsync(); long lockedTokenAmount = 10; await ApproveBalanceAsync(lockedTokenAmount); // Create proposal and approve var proposalId = await CreateSideChainProposalAsync(1, lockedTokenAmount, ByteString.CopyFromUtf8("Test")); await ApproveWithMinersAsync(proposalId); var transactionResult = await ReleaseProposalAsync(proposalId); var chainId = CreationRequested.Parser.ParseFrom(transactionResult.Logs[1].NonIndexed).ChainId; var creator = CreationRequested.Parser.ParseFrom(transactionResult.Logs[1].NonIndexed).Creator; Assert.True(creator == DefaultSender); var chainStatus = await CrossChainContractStub.GetChainStatus.CallAsync(new SInt32Value { Value = chainId }); Assert.True(chainStatus.Value == (int)SideChainStatus.Active); var parentChain = await CrossChainContractStub.GetParentChainId.CallAsync(new Empty()); Assert.True(parentChain.Equals(new SInt32Value { Value = ChainHelper.ConvertBase58ToChainId("AELF") })); }
public SideChainInitializationDataProvider(IOptionsSnapshot <ChainOptions> chainOptions, IOptionsSnapshot <CrossChainConfigOptions> crossChainConfigOptions, IChainInitializationDataPlugin chainInitializationDataPlugin, IBlockchainService blockchainService) { _chainOptions = chainOptions.Value; _chainInitializationDataPlugin = chainInitializationDataPlugin; _blockchainService = blockchainService; ParentChainId = ChainHelper.ConvertBase58ToChainId(crossChainConfigOptions.Value.ParentChainId); }
/// <summary> /// Get id of the chain. /// </summary> /// <returns>ChainId</returns> public async Task <int> GetChainIdAsync() { var url = GetRequestUrl(_baseUrl, "api/blockChain/chainStatus"); var statusDto = await _httpService.GetResponseAsync <ChainStatusDto>(url); var base58ChainId = statusDto.ChainId; var chainId = ChainHelper.ConvertBase58ToChainId(base58ChainId); return(chainId); }
public async Task ValidateBlockBeforeAttach_Test() { var fakeMerkleTreeRoot1 = Hash.FromString("fakeMerkleTreeRoot1"); var fakeSideChainId = ChainHelper.ConvertBase58ToChainId("2112"); var fakeSideChainBlockData = CreateSideChainBlockData(fakeSideChainId, 1, fakeMerkleTreeRoot1); var sideChainTxMerkleTreeRoot = ComputeRootHash(new[] { fakeSideChainBlockData }); var block = CreateFilledBlock(sideChainTxMerkleTreeRoot); var res = await _crossChainBlockValidationProvider.ValidateBeforeAttachAsync(block); Assert.True(res); }
protected async Task InitializeCrossChainContractAsync(long parentChainHeightOfCreation = 0, int parentChainId = 0, bool withException = false) { await BlockMiningService.MineBlockAsync(new List <Transaction> { CrossChainContractStub.Initialize.GetTransaction(new InitializeInput { ParentChainId = parentChainId == 0 ? ChainHelper.ConvertBase58ToChainId("AELF") : parentChainId, CreationHeightOnParentChain = parentChainHeightOfCreation }) }, withException); }
public ParliamentContractPrivilegeTestBase() { var mainChainId = ChainHelper.ConvertBase58ToChainId("AELF"); var chainId = ChainHelper.GetChainId(1); Tester = new ContractTester<ParliamentContractPrivilegeTestAElfModule>(chainId,SampleECKeyPairs.KeyPairs[1]); AsyncHelper.RunSync(() => Tester.InitialChainAsyncWithAuthAsync(Tester.GetSideChainSystemContract( Tester.GetCallOwnerAddress(), mainChainId,"STA",out TotalSupply,Tester.GetCallOwnerAddress()))); ParliamentAddress = Tester.GetContractAddress(ParliamentSmartContractAddressNameProvider.Name); TokenContractAddress = Tester.GetContractAddress(TokenSmartContractAddressNameProvider.Name); }
public MultiTokenContractCrossChainTestBase() { MainChainId = ChainHelper.ConvertBase58ToChainId("AELF"); MainChainTester = new ContractTester <MultiTokenContractCrossChainTestAElfModule>(MainChainId, SampleECKeyPairs.KeyPairs[1]); AsyncHelper.RunSync(() => MainChainTester.InitialChainAsyncWithAuthAsync(MainChainTester.GetDefaultContractTypes(MainChainTester.GetCallOwnerAddress(), out TotalSupply, out _, out BalanceOfStarter))); BasicContractZeroAddress = MainChainTester.GetZeroContractAddress(); CrossChainContractAddress = MainChainTester.GetContractAddress(CrossChainSmartContractAddressNameProvider.Name); TokenContractAddress = MainChainTester.GetContractAddress(TokenSmartContractAddressNameProvider.Name); ParliamentAddress = MainChainTester.GetContractAddress(ParliamentAuthSmartContractAddressNameProvider.Name); }
protected async Task InitializeCrossChainContractAsync(long parentChainHeightOfCreation = 0, int parentChainId = 0) { var crossChainInitializationTransaction = await Tester.GenerateTransactionAsync(CrossChainContractAddress, nameof(CrossChainContractContainer.CrossChainContractStub.Initialize), new InitializeInput { ParentChainId = parentChainId == 0 ? ChainHelper.ConvertBase58ToChainId("AELF") : parentChainId, CreationHeightOnParentChain = parentChainHeightOfCreation }); await Tester.MineAsync(new List <Transaction> { crossChainInitializationTransaction }); }
public override void ConfigureServices(ServiceConfigurationContext context) { Configure <ChainOptions>(o => { o.ChainId = ChainHelper.ConvertBase58ToChainId("AELF"); }); var ecKeyPair = CryptoHelper.GenerateKeyPair(); var nodeAccount = Address.FromPublicKey(ecKeyPair.PublicKey).ToBase58(); var nodeAccountPassword = "******"; Configure <AccountOptions>(o => { o.NodeAccount = nodeAccount; o.NodeAccountPassword = nodeAccountPassword; }); Configure <ConsensusOptions>(o => { var miners = new List <string>(); for (var i = 0; i < 3; i++) { miners.Add(CryptoHelper.GenerateKeyPair().PublicKey.ToHex()); } o.InitialMinerList = miners; o.MiningInterval = 4000; o.PeriodSeconds = 604800; o.MinerIncreaseInterval = 31536000; }); context.Services.AddTransient(o => { var mockService = new Mock <IAccountService>(); mockService.Setup(a => a.SignAsync(It.IsAny <byte[]>())).Returns <byte[]>(data => Task.FromResult(CryptoHelper.SignWithPrivateKey(ecKeyPair.PrivateKey, data))); mockService.Setup(a => a.GetPublicKeyAsync()).ReturnsAsync(ecKeyPair.PublicKey); return(mockService.Object); }); context.Services.AddSingleton(o => Mock.Of <IAElfNetworkServer>()); Configure <NetworkOptions>(o => { o.PeerInvalidTransactionLimit = 5; o.PeerInvalidTransactionTimeout = 1000; o.PeerDiscoveryMaxNodesToKeep = 5; o.MaxPeers = 5; }); }
public async Task Validate_WithTrueOption_Test() { var fakeMerkleTreeRoot1 = Hash.FromString("fakeMerkleTreeRoot1"); var fakeSideChainId = ChainHelper.ConvertBase58ToChainId("2112"); var fakeSideChainBlockData = CreateSideChainBlockData(fakeSideChainId, 1, fakeMerkleTreeRoot1); CreateFakeCacheAndStateData(fakeSideChainId, fakeSideChainBlockData, 2); var sideChainTxMerkleTreeRoot = ComputeRootHash(new[] { fakeSideChainBlockData }); var block = CreateFilledBlock(sideChainTxMerkleTreeRoot); block.Header.Bloom = ByteString.CopyFrom(GetSideChainBlockDataIndexedEventBloom().Data); _configOptions.CrossChainDataValidationIgnored = true; var res = await _crossChainBlockValidationProvider.ValidateBlockAfterExecuteAsync(block); Assert.True(res); }
public async Task GetClientTest() { int remoteChainId1 = ChainHelper.GetChainId(1); int remoteChainId2 = ChainHelper.GetChainId(2); int remoteChainId3 = ChainHelper.GetChainId(3); var localChainId = ChainHelper.ConvertBase58ToChainId("AELF"); { var crossChainClientCreationContext1 = new CrossChainClientCreationContext { LocalChainId = localChainId, RemoteChainId = remoteChainId1, IsClientToParentChain = false, RemoteServerHost = "localhost", RemoteServerPort = 5000 }; _crossChainCommunicationTestHelper.SetClientConnected(remoteChainId1, true); await _crossChainClientService.CreateClientAsync(crossChainClientCreationContext1); var client1 = await _crossChainClientService.GetConnectedCrossChainClientAsync(remoteChainId1); client1.IsConnected.ShouldBeTrue(); client1.RemoteChainId.ShouldBe(remoteChainId1); } { var crossChainClientCreationContext2 = new CrossChainClientCreationContext { LocalChainId = localChainId, RemoteChainId = remoteChainId2, IsClientToParentChain = false, RemoteServerHost = "localhost", RemoteServerPort = 5000 }; _crossChainCommunicationTestHelper.SetClientConnected(remoteChainId2, false); await _crossChainClientService.CreateClientAsync(crossChainClientCreationContext2); var client2 = await _crossChainClientService.GetConnectedCrossChainClientAsync(remoteChainId2); client2.ShouldBeNull(); } { var client3 = await _crossChainClientService.GetConnectedCrossChainClientAsync(remoteChainId3); client3.ShouldBeNull(); } }
/// <summary> /// System contract dto for side chain initialization. /// </summary> /// <returns></returns> public Action <List <GenesisSmartContractDto> > GetSideChainSystemContract(Address issuer, out long totalSupply, Address proposer, out bool isPrivilegePreserved) { totalSupply = TokenTotalSupply; isPrivilegePreserved = IsPrivilegePreserved; var nativeTokenInfo = new TokenInfo { Symbol = "ELF", Decimals = 2, Issuer = issuer, IsBurnable = true, TokenName = "elf token", TotalSupply = TokenTotalSupply, IssueChainId = ChainHelper.ConvertBase58ToChainId("AELF") }; 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 }); var parliamentContractCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList(); var contractOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ContractOptions> >().Value; parliamentContractCallList.Add(nameof(ParliamentAuthContract.Initialize), new ParliamentAuth.InitializeInput { GenesisOwnerReleaseThreshold = contractOptions.GenesisOwnerReleaseThreshold, PrivilegedProposer = proposer, ProposerAuthorityRequired = IsPrivilegePreserved }); return(list => { list.AddGenesisSmartContract(TokenContractCode, TokenSmartContractAddressNameProvider.Name, tokenInitializationCallList); list.AddGenesisSmartContract(CrossChainContractCode, CrossChainSmartContractAddressNameProvider.Name); list.AddGenesisSmartContract(ParliamentAuthContractCode, ParliamentAuthSmartContractAddressNameProvider.Name, parliamentContractCallList); }); }
public async Task StartAsync(int chainId) { _localChainId = chainId; if (string.IsNullOrEmpty(_crossChainConfigOptions.ParentChainId)) { return; } Logger.LogInformation("Starting client to parent chain.."); await _crossChainClientService.CreateClientAsync(new GrpcCrossChainClientCreationContext { RemoteChainId = ChainHelper.ConvertBase58ToChainId(_crossChainConfigOptions.ParentChainId), LocalChainId = chainId, IsClientToParentChain = true }); }
private async Task StartNodeAsync() { var ownAddress = await _accountService.GetAccountAsync(); var callList = new List <ContractInitializationMethodCall>(); callList.Add(nameof(TokenContractContainer.TokenContractStub.Create), new CreateInput { Symbol = _nativeSymbol, TokenName = "ELF_Token", TotalSupply = TokenTotalSupply, Decimals = 8, Issuer = ownAddress, IsBurnable = true }); callList.Add(nameof(TokenContractContainer.TokenContractStub.SetPrimaryTokenSymbol), new SetPrimaryTokenSymbolInput { Symbol = _nativeSymbol }); callList.Add(nameof(TokenContractContainer.TokenContractStub.Issue), new IssueInput { Symbol = _nativeSymbol, Amount = TokenTotalSupply, To = ownAddress, Memo = "Issue" }); var tokenContractCode = Codes.Single(kv => kv.Key.Split(",").First().Trim().EndsWith("MultiToken")).Value; var dto = new OsBlockchainNodeContextStartDto { ZeroSmartContract = typeof(BasicContractZero), ChainId = ChainHelper.ConvertBase58ToChainId("AELF"), SmartContractRunnerCategory = KernelConstants.CodeCoverageRunnerCategory, }; var genesisSmartContractDto = new GenesisSmartContractDto { Code = tokenContractCode, SystemSmartContractName = TokenSmartContractAddressNameProvider.Name, }; genesisSmartContractDto.AddGenesisTransactionMethodCall(callList.ToArray()); dto.InitializationSmartContracts.Add(genesisSmartContractDto); await _osBlockchainNodeContextService.StartAsync(dto); }
public async Task RequestChainInitializationData_ParentClient_Test() { var chainId = ChainHelper.GetChainId(ChainHelper.ConvertBase58ToChainId("AELF") + 1); await Server.StartAsync(5000); var grpcClientInitializationContext = new GrpcClientInitializationContext { LocalChainId = chainId, RemoteChainId = ChainHelper.ConvertBase58ToChainId("AELF"), DialTimeout = 1000, UriStr = string.Concat(Host, ":", "5000") }; var client = new ClientForParentChain(grpcClientInitializationContext); var res = await client.RequestChainInitializationDataAsync(chainId); Assert.Equal(1, res.CreationHeightOnParentChain); Dispose(); }
public void GetChainId_By_SerialNumber_Test() { // Have tested all the conditions (195112UL ~ 11316496UL), To save time, just do some random test //var base58HashSet = new HashSet<string>(); //var intHashSet = new HashSet<int>(); // for (var i = ; i < 11316496UL; i++) for (var i = 0; i < 1000; i++) { var chainId = 2111; var base58String = ChainHelper.ConvertChainIdToBase58(chainId); base58String.Length.ShouldBe(4); var newChainId = ChainHelper.ConvertBase58ToChainId(base58String); newChainId.ShouldBe(chainId); // Uncomment this for go through all conditions // base58HashSet.Add(base58String).ShouldBe(true); // intHashSet.Add(newChainId).ShouldBe(true); } }
/// <summary> /// System contract dto for side chain initialization. /// </summary> /// <returns></returns> public Action <List <GenesisSmartContractDto> > GetSideChainSystemContract(Address issuer, int mainChainId, string symbol, out long totalSupply, Address proposer, long parentChainHeightOfCreation = 1, Address parentChainTokenContractAddress = null) { totalSupply = TokenTotalSupply; var nativeTokenInfo = new TokenInfo { Symbol = "ELF", Decimals = 2, Issuer = issuer, IsBurnable = true, TokenName = "elf token", TotalSupply = TokenTotalSupply, IssueChainId = ChainHelper.ConvertBase58ToChainId("AELF") }; var chainOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ChainOptions> >().Value; var tokenInitializationCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList(); tokenInitializationCallList.Add( nameof(TokenContractContainer.TokenContractStub.Create), new CreateInput { Decimals = nativeTokenInfo.Decimals, IssueChainId = nativeTokenInfo.IssueChainId, Issuer = nativeTokenInfo.Issuer, IsBurnable = nativeTokenInfo.IsBurnable, Symbol = nativeTokenInfo.Symbol, TokenName = nativeTokenInfo.TokenName, TotalSupply = nativeTokenInfo.TotalSupply }); tokenInitializationCallList.Add( nameof(TokenContractContainer.TokenContractStub.Create), new CreateInput { Decimals = 2, IsBurnable = true, Issuer = Address.FromPublicKey(KeyPair.PublicKey), TotalSupply = 1_000_000_000, Symbol = symbol, TokenName = "TEST", IssueChainId = chainOptions.ChainId }
public override void ConfigureServices(ServiceConfigurationContext context) { var s = context.Services; s.AddKeyValueDbContext <BlockchainKeyValueDbContext>(o => o.UseInMemoryDatabase()); s.AddKeyValueDbContext <StateKeyValueDbContext>(o => o.UseInMemoryDatabase()); s.TryAddSingleton <ISmartContractAddressNameProvider, ConsensusSmartContractAddressNameProvider>(); s.TryAddSingleton <ISmartContractAddressNameProvider, ElectionSmartContractAddressNameProvider>(); s.TryAddSingleton <ISmartContractAddressNameProvider, ProfitSmartContractAddressNameProvider>(); s.TryAddSingleton <ISmartContractAddressNameProvider, TokenConverterSmartContractAddressNameProvider>(); s.TryAddSingleton <ISmartContractAddressNameProvider, TokenSmartContractAddressNameProvider>(); s.TryAddSingleton <ISmartContractAddressNameProvider, VoteSmartContractAddressNameProvider>(); var configuration = context.Services.GetConfiguration(); Configure <AElf.OS.EconomicOptions>(configuration.GetSection("Economic")); Configure <ChainOptions>(option => { option.ChainId = ChainHelper.ConvertBase58ToChainId(context.Services.GetConfiguration()["ChainId"]); option.ChainType = context.Services.GetConfiguration().GetValue("ChainType", ChainType.MainChain); option.NetType = context.Services.GetConfiguration().GetValue("NetType", NetType.MainNet); }); Configure <HostSmartContractBridgeContextOptions>(options => { options.ContextVariables[ContextVariableDictionary.NativeSymbolName] = context.Services .GetConfiguration().GetValue("Economic:Symbol", "ELF"); options.ContextVariables[ContextVariableDictionary.PayTxFeeSymbolList] = context.Services .GetConfiguration() .GetValue("Economic:SymbolListToPayTxFee", "WRITE,READ,STORAGE,TRAFFIC"); options.ContextVariables[ContextVariableDictionary.PayRentalSymbolList] = context.Services .GetConfiguration().GetValue("Economic:SymbolListToPayRental", "CPU,RAM,DISK,NET"); }); Configure <ContractOptions>(configuration.GetSection("Contract")); context.Services.AddSingleton <ISystemContractProvider, SystemContractProvider>(); context.Services.AddSingleton(typeof(ContractsDeployer)); context.Services.AddTransient <IGenesisSmartContractDtoProvider, GenesisSmartContractDtoProvider>(); context.Services.RemoveAll <ITransactionValidationProvider>(); }
public async Task Validate_EmptyHeader_WithIndexedData_Test() { var fakeMerkleTreeRoot1 = Hash.FromString("fakeMerkleTreeRoot1"); var fakeSideChainId = ChainHelper.ConvertBase58ToChainId("2112"); var fakeSideChainBlockData = CreateSideChainBlockData(fakeSideChainId, 1, fakeMerkleTreeRoot1); CreateFakeCacheAndStateData(fakeSideChainId, fakeSideChainBlockData, 2); var block = _kernelTestHelper.GenerateBlock(1, Hash.Empty); var bloom = new Bloom(); bloom.Combine(new [] { GetSideChainBlockDataIndexedEventBloom(), GetParentChainBlockDataIndexedEventBloom() }); block.Header.Bloom = ByteString.CopyFrom(bloom.Data); var res = await _crossChainBlockValidationProvider.ValidateBlockAfterExecuteAsync(block); Assert.False(res); }
public override void PreConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); var contentRootPath = hostingEnvironment.ContentRootPath; var hostBuilderContext = context.Services.GetSingletonInstanceOrNull<HostBuilderContext>(); var chainType = configuration.GetValue("ChainType", ChainType.MainChain); var netType = configuration.GetValue("NetType", NetType.MainNet); var newConfig = new ConfigurationBuilder().AddConfiguration(configuration) .AddJsonFile($"appsettings.{chainType}.{netType}.json") .AddJsonFile($"appsettings.{hostingEnvironment.EnvironmentName}.json", true) .SetBasePath(contentRootPath) .Build(); hostBuilderContext.Configuration = newConfig; Configure<EconomicOptions>(newConfig.GetSection("Economic")); Configure<ChainOptions>(option => { option.ChainId = ChainHelper.ConvertBase58ToChainId(newConfig["ChainId"]); option.ChainType = chainType; option.NetType = netType; }); Configure<HostSmartContractBridgeContextOptions>(options => { options.ContextVariables[ContextVariableDictionary.NativeSymbolName] = newConfig.GetValue("Economic:Symbol", "ELF"); options.ContextVariables["SymbolListToPayTxFee"] = newConfig.GetValue("Economic:SymbolListToPayTxFee", "WRITE,READ,STORAGE,TRAFFIC"); options.ContextVariables["SymbolListToPayRental"] = newConfig.GetValue("Economic:SymbolListToPayRental", "CPU,RAM,DISK,NET"); }); Configure<ContractOptions>(newConfig.GetSection("Contract")); Configure<ContractOptions>(options => { options.GenesisContractDir = Path.Combine(contentRootPath, "genesis"); }); Configure<WebAppOptions>(newConfig.GetSection("WebApp")); }
/// <summary> /// System contract dto for side chain initialization. /// </summary> /// <returns></returns> public Action <List <GenesisSmartContractDto> > GetSideChainSystemContract(Address issuer, out long totalSupply, Address proposer, out bool isPrivilegePreserved) { totalSupply = TokenTotalSupply; isPrivilegePreserved = IsPrivilegePreserved; var nativeTokenInfo = new TokenInfo { Symbol = "ELF", Decimals = 2, Issuer = issuer, IsBurnable = true, TokenName = "elf token", TotalSupply = TokenTotalSupply, IssueChainId = ChainHelper.ConvertBase58ToChainId("AELF") }; var chainOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ChainOptions> >().Value; 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 }, ChainPrimaryToken = new TokenInfo { Decimals = 2, IsBurnable = true, Issuer = Address.FromPublicKey(KeyPair.PublicKey), TotalSupply = 1_000_000_000, Symbol = "TE", TokenName = "TEST", IssueChainId = chainOptions.ChainId }, });
public async Task Validate_IncompatibleCacheData_Test() { var fakeMerkleTreeRoot1 = Hash.FromString("fakeMerkleTreeRoot1"); var fakeSideChainId = ChainHelper.ConvertBase58ToChainId("2112"); var fakeSideChainBlockData = CreateSideChainBlockData(fakeSideChainId, 1, fakeMerkleTreeRoot1); var fakeTxnMerkleTreeRoot2 = Hash.FromString("fakeMerkleTreeRoot2"); var fakeSideChainBlockData2 = CreateSideChainBlockData(fakeSideChainId, 1, fakeTxnMerkleTreeRoot2); CreateFakeCacheAndStateData(fakeSideChainId, fakeSideChainBlockData2, 2); var sideChainTxMerkleTreeRoot = ComputeRootHash(new[] { fakeSideChainBlockData }); var block = CreateFilledBlock(sideChainTxMerkleTreeRoot); block.Header.Bloom = ByteString.CopyFrom(GetSideChainBlockDataIndexedEventBloom().Data); var res = await _crossChainBlockValidationProvider.ValidateBlockAfterExecuteAsync(block); Assert.False(res); }
public async Task FinishInitialSync_Test() { int chainId = ChainHelper.ConvertBase58ToChainId("AELF"); long libHeight = 10; _crossChainTestHelper.AddFakeChainIdHeight(chainId, libHeight); _crossChainConfigOptions.CrossChainDataValidationIgnored.ShouldBeTrue(); await _crossChainService.FinishInitialSyncAsync(); _crossChainConfigOptions.CrossChainDataValidationIgnored.ShouldBeFalse(); var height = _crossChainCacheEntityService.GetTargetHeightForChainCacheEntity(chainId); { Should.Throw <InvalidOperationException>(() => _crossChainCacheEntityService.GetTargetHeightForChainCacheEntity(chainId - 1)); } Assert.Equal(libHeight + 1, height); }
protected void StartSideChain() { var chainId = ChainHelper.ConvertBase58ToChainId("Side"); var mainChainId = Tester.GetChainAsync().Result.Id; SideChainTester = new ContractTester <BasicContractZeroTestAElfModule>(chainId, CreatorKeyPair); AsyncHelper.RunSync(() => SideChainTester.InitialCustomizedChainAsync(chainId, configureSmartContract: SideChainTester.GetSideChainSystemContract( SideChainTester.GetCallOwnerAddress(), mainChainId, "STA", out TotalSupply, SideChainTester.GetCallOwnerAddress()))); SideBasicContractZeroAddress = SideChainTester.GetZeroContractAddress(); SideTokenContractAddress = SideChainTester.GetContractAddress(TokenSmartContractAddressNameProvider.Name); SideParliamentAddress = SideChainTester.GetContractAddress(ParliamentSmartContractAddressNameProvider.Name); SideChainMinerTester = SideChainTester.CreateNewContractTester(SideChainTester.InitialMinerList.First()); }
public void TestChainIdGeneration() { { var chainId = ChainHelper.GetChainId(0); var chainIdBased58 = ChainHelper.ConvertChainIdToBase58(chainId); chainIdBased58.ShouldBe("2111"); var convertedChainId = ChainHelper.ConvertBase58ToChainId(chainIdBased58); convertedChainId.ShouldBe(chainId); } { var chainId = ChainHelper.GetChainId(1); var chainIdBased58 = ChainHelper.ConvertChainIdToBase58(chainId); chainIdBased58.ShouldBe("2112"); var convertedChainId = ChainHelper.ConvertBase58ToChainId(chainIdBased58); convertedChainId.ShouldBe(chainId); } { var chainIdMaxValue = ChainHelper.GetChainId(long.MaxValue); var chainIdBased58MaxValue = ChainHelper.ConvertChainIdToBase58(chainIdMaxValue); chainIdBased58MaxValue.ShouldBe("mR59"); var convertedChainIdMaxValue = ChainHelper.ConvertBase58ToChainId(chainIdBased58MaxValue); convertedChainIdMaxValue.ShouldBe(chainIdMaxValue); var chainIdMinValue = ChainHelper.GetChainId(long.MinValue); chainIdMinValue.ShouldBe(chainIdMaxValue); var chainIdBased58MinValue = ChainHelper.ConvertChainIdToBase58(chainIdMaxValue); chainIdBased58MinValue.ShouldBe(chainIdBased58MaxValue); var convertedChainIdMinValue = ChainHelper.ConvertBase58ToChainId(chainIdBased58MinValue); convertedChainIdMinValue.ShouldBe(convertedChainIdMaxValue); } { var chainIdAElf = ChainHelper.ConvertBase58ToChainId("AELF"); var chainId = ChainHelper.GetChainId(chainIdAElf + 1); var chainIdBased58 = ChainHelper.ConvertChainIdToBase58(chainId); chainIdBased58.ShouldBe("tDVV"); } }
public async Task AddClientTest() { int remoteChainId = ChainHelper.GetChainId(1); var localChainId = ChainHelper.ConvertBase58ToChainId("AELF"); var crossChainClientCreationContext = new CrossChainClientCreationContext { LocalChainId = localChainId, RemoteChainId = remoteChainId, IsClientToParentChain = false, RemoteServerHost = "localhost", RemoteServerPort = 5000 }; _crossChainCommunicationTestHelper.SetClientConnected(remoteChainId, true); var client = await _crossChainClientService.CreateClientAsync(crossChainClientCreationContext); client.IsConnected.ShouldBeTrue(); client.RemoteChainId.ShouldBe(remoteChainId); }