public async Task Set_ConfigStrategy() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); var input = new DPoSStrategyInput { IsBlockchainAgeSettable = true, IsTimeSlotSkippable = true, IsVerbose = true }; var transactionResult = await testers.Testers[0].ExecuteConsensusContractMethodWithMiningAsync( nameof(ConsensusContract.ConfigStrategy), input); transactionResult.Status.ShouldBe(TransactionResultStatus.Mined); //set again transactionResult = await testers.Testers[0].ExecuteConsensusContractMethodWithMiningAsync( nameof(ConsensusContract.ConfigStrategy), input); transactionResult.Status.ShouldBe(TransactionResultStatus.Failed); transactionResult.Error.Contains("Already configured").ShouldBeTrue(); }
public async Task NextRound_GetConsensusCommand() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); // Act var futureTime = DateTime.UtcNow.AddMilliseconds(4000 * testers.MinersCount + 1).ToTimestamp(); var command = await testers.Testers[0].GetConsensusCommandAsync(futureTime); // Assert Assert.Equal(DPoSBehaviour.NextRound, DPoSHint.Parser.ParseFrom(command.Hint).Behaviour); Assert.True(command.NextBlockMiningLeftMilliseconds > 0); Assert.Equal(4000, command.LimitMillisecondsOfMiningBlock); }
public async Task NormalBlock_GetNewConsensusInformation() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); var inValue = Hash.Generate(); var stubExtraInformation = GetTriggerInformationForNormalBlock(testers.Testers[1].KeyPair.PublicKey.ToHex(), inValue); // Act var newConsensusInformation = await testers.Testers[1].GetInformationToUpdateConsensusAsync(stubExtraInformation, DateTime.UtcNow); // Assert Assert.NotNull(newConsensusInformation); Assert.Equal(testers.Testers[1].PublicKey, newConsensusInformation.SenderPublicKey.ToHex()); }
public async Task NextRound_GetNewConsensusInformation() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); var triggerInformationForNextRoundOrTerm = GetTriggerInformationForNextRound(testers.Testers[1].KeyPair.PublicKey.ToHex()); // Act var futureTime = DateTime.UtcNow.AddMilliseconds(4000 * testers.MinersCount); var newConsensusInformation = await testers.Testers[1].GetInformationToUpdateConsensusAsync(triggerInformationForNextRoundOrTerm, futureTime); // Assert newConsensusInformation.SenderPublicKey.ToHex().ShouldBe(testers.Testers[1].PublicKey); newConsensusInformation.Round.RoundNumber.ShouldBeGreaterThanOrEqualTo(2); }
public async Task NormalBlock_GenerateConsensusTransactions() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); var inValue = Hash.Generate(); var triggerInformationForNormalBlock = GetTriggerInformationForNormalBlock(testers.Testers[1].KeyPair.PublicKey.ToHex(), inValue); // Act var consensusTransactions = await testers.Testers[1].GenerateConsensusTransactionsAsync(triggerInformationForNormalBlock); // Assert Assert.NotNull(consensusTransactions); Assert.Equal(DPoSBehaviour.UpdateValue.ToString(), consensusTransactions.First().MethodName); }
public async Task NormalBlock_ValidateConsensusAfterExecution_Success() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); var newInformation = new DPoSHeaderInformation { SenderPublicKey = ByteString.CopyFrom(testers.Testers[0].KeyPair.PublicKey), Round = await testers.Testers[0].GetCurrentRoundInformationAsync(), Behaviour = DPoSBehaviour.UpdateValueWithoutPreviousInValue }; // Act var validationResult = await testers.Testers[0].ValidateConsensusAfterExecutionAsync(newInformation); validationResult.Success.ShouldBeTrue(); }
public async Task NormalBlock_ValidateConsensusAfterExecution_Failed() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); var inValue = Hash.Generate(); var triggerInformationForNormalBlock = GetTriggerInformationForNormalBlock(testers.Testers[1].KeyPair.PublicKey.ToHex(), inValue); var newInformation = await testers.Testers[1] .GetInformationToUpdateConsensusAsync(triggerInformationForNormalBlock, DateTime.UtcNow); // Act var validationResult = await testers.Testers[0].ValidateConsensusAfterExecutionAsync(newInformation); validationResult.Success.ShouldBeFalse(); validationResult.Message.ShouldBe("Current round information is different with consensus extra data."); }
public async Task NormalBlock_ValidateConsensusBeforeExecution_Success() { var startTime = DateTime.UtcNow.ToTimestamp(); var testers = new ConsensusTesters(); testers.InitialTesters(startTime); var currentRound = await testers.Testers[0].GetCurrentRoundInformationAsync(); var roundInfo = new Round { BlockchainAge = currentRound.BlockchainAge + 1, RoundNumber = currentRound.RoundNumber + 1, TermNumber = currentRound.TermNumber, RealTimeMinersInformation = { { testers.Testers[0].PublicKey, new MinerInRound { OutValue = Hash.Generate(), FinalOrderOfNextRound = 1, ExpectedMiningTime = currentRound.RealTimeMinersInformation[testers.Testers[0].PublicKey].ExpectedMiningTime, Order = 1 } }, { testers.Testers[1].PublicKey, new MinerInRound { OutValue = Hash.Generate(), FinalOrderOfNextRound = 2, ExpectedMiningTime = currentRound.RealTimeMinersInformation[testers.Testers[1].PublicKey].ExpectedMiningTime, Order = 2 } }, { testers.Testers[2].PublicKey, new MinerInRound { OutValue = Hash.Generate(), FinalOrderOfNextRound = 3, ExpectedMiningTime = currentRound.RealTimeMinersInformation[testers.Testers[2].PublicKey].ExpectedMiningTime, Order = 3 } }, } }; var newInformation = new DPoSHeaderInformation { SenderPublicKey = ByteString.CopyFrom(testers.Testers[0].KeyPair.PublicKey), Round = roundInfo, Behaviour = DPoSBehaviour.NextRound }; // Act var validationResult = await testers.Testers[0].ValidateConsensusBeforeExecutionAsync(newInformation); validationResult.Success.ShouldBeTrue(); //nothing behavior newInformation.Behaviour = DPoSBehaviour.Nothing; validationResult = await testers.Testers[0].ValidateConsensusBeforeExecutionAsync(newInformation); validationResult.Success.ShouldBeFalse(); validationResult.Message.ShouldBe("Invalid behaviour"); //update value newInformation.Behaviour = DPoSBehaviour.UpdateValue; validationResult = await testers.Testers[0].ValidateConsensusBeforeExecutionAsync(newInformation); validationResult.ShouldNotBeNull(); }