protected void InitializeContracts() { ECKeyPairProvider.SetECKeyPair(BootMinerKeyPair); // Deploy useful contracts. ConsensusContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(BootMinerKeyPair) .DeploySystemSmartContract.SendAsync(new SystemContractDeploymentInput { Category = KernelConstants.CodeCoverageRunnerCategory, Code = ByteString.CopyFrom(File.ReadAllBytes(typeof(ConsensusContract).Assembly.Location)), Name = ConsensusSmartContractAddressNameProvider.Name, TransactionMethodCallList = GenerateConsensusInitializationCallList() })).Output; DividendContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(BootMinerKeyPair) .DeploySystemSmartContract.SendAsync( new SystemContractDeploymentInput { Category = KernelConstants.CodeCoverageRunnerCategory, Code = ByteString.CopyFrom(File.ReadAllBytes(typeof(DividendContract).Assembly.Location)), Name = DividendSmartContractAddressNameProvider.Name, TransactionMethodCallList = GenerateDividendInitializationCallList() })).Output; TokenContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(BootMinerKeyPair) .DeploySystemSmartContract.SendAsync( new SystemContractDeploymentInput { Category = KernelConstants.CodeCoverageRunnerCategory, Code = ByteString.CopyFrom(File.ReadAllBytes(typeof(TokenContract).Assembly.Location)), Name = TokenSmartContractAddressNameProvider.Name, TransactionMethodCallList = GenerateTokenInitializationCallList() })).Output; }
internal async Task <Dictionary <string, DPoSTriggerInformation> > GenerateEncryptedMessagesTest() { var firstRound = await BootMiner.GetCurrentRoundInformation.CallAsync(new Empty()); var randomHashes = Enumerable.Range(0, MinersCount).Select(_ => Hash.Generate()).ToList(); var triggers = Enumerable.Range(0, MinersCount).Select(i => new DPoSTriggerInformation { PublicKey = ByteString.CopyFrom(InitialMinersKeyPairs[i].PublicKey), RandomHash = randomHashes[i] }).ToDictionary(t => t.PublicKey.ToHex(), t => t); foreach (var minerInRound in firstRound.RealTimeMinersInformation.Values.OrderBy(m => m.Order)) { var currentKeyPair = InitialMinersKeyPairs.First(p => p.PublicKey.ToHex() == minerInRound.PublicKey); ECKeyPairProvider.SetECKeyPair(currentKeyPair); BlockTimeProvider.SetBlockTime(minerInRound.ExpectedMiningTime.ToDateTime()); var tester = GetConsensusContractTester(currentKeyPair); var headerInformation = await tester.GetInformationToUpdateConsensus.CallAsync(triggers[minerInRound.PublicKey]); var encryptedInValues = headerInformation.Round.RealTimeMinersInformation[minerInRound.PublicKey] .EncryptedInValues; encryptedInValues.Count.ShouldBe(MinersCount - 1); foreach (var(key, value) in encryptedInValues) { InitialMinersKeyPairs.Select(p => p.PublicKey.ToHex()).ShouldContain(key); value.ShouldNotBeEmpty(); } // Update consensus information. var toUpdate = headerInformation.Round.ExtractInformationToUpdateConsensus(minerInRound.PublicKey); await tester.UpdateValue.SendAsync(toUpdate); } var updatedRound = await BootMiner.GetCurrentRoundInformation.CallAsync(new Empty()); foreach (var minerInRound in updatedRound.RealTimeMinersInformation.Values) { minerInRound.EncryptedInValues.Count.ShouldBe(MinersCount - 1); } return(triggers); }
public async Task DecryptMessageTest() { var previousTriggers = await GenerateEncryptedMessagesTest(); await BootMinerChangeRoundAsync(); var currentRound = await BootMiner.GetCurrentRoundInformation.CallAsync(new Empty()); var randomHashes = Enumerable.Range(0, MinersCount).Select(_ => Hash.Generate()).ToList(); var triggers = Enumerable.Range(0, MinersCount).Select(i => new DPoSTriggerInformation { PublicKey = ByteString.CopyFrom(InitialMinersKeyPairs[i].PublicKey), RandomHash = randomHashes[i], PreviousRandomHash = previousTriggers[InitialMinersKeyPairs[i].PublicKey.ToHex()].RandomHash }).ToDictionary(t => t.PublicKey.ToHex(), t => t); // Just `MinimumCount + 1` miners produce blocks. foreach (var minerInRound in currentRound.RealTimeMinersInformation.Values.OrderBy(m => m.Order) .Take(MinimumCount + 1)) { var currentKeyPair = InitialMinersKeyPairs.First(p => p.PublicKey.ToHex() == minerInRound.PublicKey); ECKeyPairProvider.SetECKeyPair(currentKeyPair); BlockTimeProvider.SetBlockTime(minerInRound.ExpectedMiningTime.ToDateTime()); var tester = GetConsensusContractTester(currentKeyPair); var headerInformation = await tester.GetInformationToUpdateConsensus.CallAsync(triggers[minerInRound.PublicKey]); // Update consensus information. var toUpdate = headerInformation.Round.ExtractInformationToUpdateConsensus(minerInRound.PublicKey); await tester.UpdateValue.SendAsync(toUpdate); } // But in values all filled. var secondRound = await BootMiner.GetCurrentRoundInformation.CallAsync(new Empty()); secondRound.RealTimeMinersInformation.Values.Count(v => v.PreviousInValue != null).ShouldBe(MinersCount); }