Exemple #1
0
        public async Task AEDPoSContract_GenerateConsensusTransaction_NextTerm_Test()
        {
            var usingKeyPair = BootMinerKeyPair;

            KeyPairProvider.SetKeyPair(usingKeyPair);

            //Next term
            {
                var consensusCommand = await AEDPoSContract_GetConsensusCommand_FirstRound_ExtraBlockMiner_Test();

                var nextTermBehavior = new AElfConsensusHint {
                    Behaviour = AElfConsensusBehaviour.NextTerm
                }
                .ToByteString();
                consensusCommand.Hint = nextTermBehavior;
                BlockTimeProvider.SetBlockTime(BlockchainStartTimestamp + new Duration
                {
                    Seconds = AEDPoSContractTestConstants.MiningInterval
                              .Mul(AEDPoSContractTestConstants.InitialMinersCount)
                              .Div(1000)
                });

                var triggerForCommand = TriggerInformationProvider
                                        .GetTriggerInformationForConsensusTransactions(consensusCommand.ToBytesValue());

                var transactionList =
                    await AEDPoSContractStub.GenerateConsensusTransactions.CallAsync(triggerForCommand);

                transactionList.Transactions.Count.ShouldBe(1);
                transactionList.Transactions[0].MethodName.ShouldBe(nameof(AEDPoSContractStub.NextTerm));
            }
        }
Exemple #2
0
        public async Task AEDPoSContract_ValidateConsensusBeforeExecution_UpdateValue_WithoutMiner_Test()
        {
            var usingKeyPair = ValidationDataCenterKeyPairs[0];

            var consensusCommand = await AEDPoSContract_GetConsensusCommand_FirstRound_ExtraBlockMiner_Test();

            KeyPairProvider.SetKeyPair(usingKeyPair);

            var updateValue = new AElfConsensusHint {
                Behaviour = AElfConsensusBehaviour.UpdateValue
            }
            .ToByteString();

            consensusCommand.Hint = updateValue;

            var triggerForCommand = TriggerInformationProvider
                                    .GetTriggerInformationForBlockHeaderExtraData(consensusCommand.ToBytesValue());
            var extraDataBytes = await AEDPoSContractStub.GetConsensusExtraData.CallAsync(triggerForCommand);

            await NextTerm(BootMinerKeyPair);

            var otherUser            = GetAEDPoSContractStub(usingKeyPair);
            var validateBeforeResult =
                await otherUser.ValidateConsensusBeforeExecution.CallAsync(extraDataBytes);

            validateBeforeResult.Success.ShouldBeFalse();
            validateBeforeResult.Message.ShouldContain("is not a miner");
        }
Exemple #3
0
        public async Task AEDPoSContract_ValidateConsensusBeforeExecution_UpdateValue_Test()
        {
            var usingKeyPair = InitialCoreDataCenterKeyPairs[0];

            KeyPairProvider.SetKeyPair(usingKeyPair);

            var triggerForCommand =
                TriggerInformationProvider.GetTriggerInformationForConsensusCommand(new BytesValue());
            var consensusCommand = await AEDPoSContractStub.GetConsensusCommand.CallAsync(triggerForCommand);

            var updateValue = new AElfConsensusHint {
                Behaviour = AElfConsensusBehaviour.UpdateValue
            }
            .ToByteString();

            consensusCommand.Hint = updateValue;

            triggerForCommand = TriggerInformationProvider
                                .GetTriggerInformationForBlockHeaderExtraData(consensusCommand.ToBytesValue());
            var extraDataBytes = await AEDPoSContractStub.GetConsensusExtraData.CallAsync(triggerForCommand);

            var validateBeforeResult =
                await AEDPoSContractStub.ValidateConsensusBeforeExecution.CallAsync(extraDataBytes);

            validateBeforeResult.Success.ShouldBeTrue();
        }
Exemple #4
0
        public async Task AEDPoSContract_ConsensusTransactionValidation_Test()
        {
            var usingKeyPair = BootMinerKeyPair;

            KeyPairProvider.SetKeyPair(usingKeyPair);

            var consensusCommand = await AEDPoSContract_GetConsensusCommand_FirstRound_ExtraBlockMiner_Test();

            var triggerForCommand = TriggerInformationProvider
                                    .GetTriggerInformationForBlockHeaderExtraData(consensusCommand.ToBytesValue());
            var extraDataBytes = await AEDPoSContractStub.GetConsensusExtraData.CallAsync(triggerForCommand);

            var validateBeforeResult =
                await AEDPoSContractStub.ValidateConsensusBeforeExecution.CallAsync(extraDataBytes);

            validateBeforeResult.Success.ShouldBeTrue();

            var roundInfo = await AEDPoSContractStub.GetCurrentRoundInformation.CallAsync(new Empty());

            roundInfo.RoundNumber++;
            roundInfo.IsMinerListJustChanged = false;
            roundInfo.TermNumber++;
            var transactionResult = await AEDPoSContractStub.NextRound.SendAsync(roundInfo);

            transactionResult.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined);

            var validateAfterResult =
                await AEDPoSContractStub.ValidateConsensusAfterExecution.CallAsync(roundInfo.ToBytesValue());

            validateAfterResult.Success.ShouldBeTrue();
        }
Exemple #5
0
        private async Task <ConsensusCommand> AEDPoSContract_GetConsensusCommand_FirstRound_ExtraBlockMiner_Test()
        {
            await AEDPoSContract_FirstRound_SecondMiner_Test();

            var usingKeyPair = BootMinerKeyPair;

            KeyPairProvider.SetKeyPair(usingKeyPair);

            BlockTimeProvider.SetBlockTime(BlockchainStartTimestamp + new Duration
            {
                Seconds = AEDPoSContractTestConstants.MiningInterval.Mul(2).Div(1000)
            });

            var triggerForCommand =
                TriggerInformationProvider.GetTriggerInformationForConsensusCommand(new BytesValue());

            var currentRound = await AEDPoSContractStub.GetCurrentRoundInformation.CallAsync(new Empty());

            var consensusCommand = await AEDPoSContractStub.GetConsensusCommand.CallAsync(triggerForCommand);

            consensusCommand.LimitMillisecondsOfMiningBlock.ShouldBe(AEDPoSContractTestConstants
                                                                     .SmallBlockMiningInterval);
            var hint = new AElfConsensusHint {
                Behaviour = AElfConsensusBehaviour.NextRound
            }
            .ToByteString();

            consensusCommand.Hint.ShouldBe(hint);

            return(consensusCommand);
        }
        internal async Task <TransactionList> AEDPoSContract_GenerateConsensusTransactions_FirstRound_ExtraBlockMiner_Test()
        {
            var usingKeyPair = BootMinerKeyPair;

            KeyPairProvider.SetKeyPair(usingKeyPair);

            var consensusCommand = await AEDPoSContract_GetConsensusCommand_FirstRound_ExtraBlockMiner_Test();

            BlockTimeProvider.SetBlockTime(BlockchainStartTimestamp + new Duration
            {
                Seconds = AEDPoSContractTestConstants.MiningInterval.Mul(AEDPoSContractTestConstants.InitialMinersCount)
                          .Div(1000)
            });

            var triggerForCommand =
                await TriggerInformationProvider
                .GetTriggerInformationForConsensusTransactionsAsync(consensusCommand.ToBytesValue());

            var transactionList = await AEDPoSContractStub.GenerateConsensusTransactions.CallAsync(triggerForCommand);

            transactionList.Transactions.Count.ShouldBe(1);
            transactionList.Transactions[0].MethodName.ShouldBe(nameof(AEDPoSContractStub.NextRound));

            return(transactionList);
        }
        public async Task AEDPoSContract_GetInformationToUpdateConsensus_FirstRound_ExtraBlockMiner_Test()
        {
            var usingKeyPair = BootMinerKeyPair;

            KeyPairProvider.SetKeyPair(usingKeyPair);

            var consensusCommand = await AEDPoSContract_GetConsensusCommand_FirstRound_ExtraBlockMiner_Test();

            BlockTimeProvider.SetBlockTime(BlockchainStartTimestamp + new Duration
            {
                Seconds = AEDPoSContractTestConstants.MiningInterval.Mul(AEDPoSContractTestConstants.InitialMinersCount)
                          .Div(1000)
            });

            var triggerForCommand =
                await TriggerInformationProvider
                .GetTriggerInformationForBlockHeaderExtraDataAsync(consensusCommand.ToBytesValue());

            var extraDataBytes = await AEDPoSContractStub.GetInformationToUpdateConsensus.CallAsync(triggerForCommand);

            var extraData = extraDataBytes.ToConsensusHeaderInformation();

            extraData.Round.RoundId.ShouldNotBe(0);
            extraData.Round.RoundNumber.ShouldBe(2);
        }
        public async Task AEDPoSContract_GetInformationToUpdateConsensus_FirstRound_SecondMiner_Test()
        {
            var usingKeyPair = InitialCoreDataCenterKeyPairs[1];

            KeyPairProvider.SetKeyPair(usingKeyPair);

            var consensusCommand = await AEDPoSContract_GetConsensusCommand_FirstRound_SecondMiner_Test();

            BlockTimeProvider.SetBlockTime(BlockchainStartTimestamp + new Duration
            {
                Seconds = AEDPoSContractTestConstants.MiningInterval.Mul(2).Div(1000)
            });

            var triggerForCommand =
                await TriggerInformationProvider
                .GetTriggerInformationForBlockHeaderExtraDataAsync(consensusCommand.ToBytesValue());

            var extraDataBytes = await AEDPoSContractStub.GetInformationToUpdateConsensus.CallAsync(triggerForCommand);

            var extraData = extraDataBytes.ToConsensusHeaderInformation();

            extraData.Round.RoundId.ShouldNotBe(0);
            extraData.Round.RoundNumber.ShouldBe(1);
            extraData.Round.RealTimeMinersInformation[usingKeyPair.PublicKey.ToHex()].OutValue
            .ShouldNotBeNull();
        }
        private async Task <ConsensusCommand> AEDPoSContract_GetConsensusCommand_FirstRound_BootMiner_Test()
        {
            KeyPairProvider.SetKeyPair(BootMinerKeyPair);
            var triggerForCommand =
                TriggerInformationProvider.GetTriggerInformationForConsensusCommand(new BytesValue());

            var consensusCommand = await AEDPoSContractStub.GetConsensusCommand.CallAsync(triggerForCommand);

            consensusCommand.LimitMillisecondsOfMiningBlock.ShouldBe(AEDPoSContractTestConstants
                                                                     .SmallBlockMiningInterval);
            var hint = new AElfConsensusHint
            {
                Behaviour = AElfConsensusBehaviour.UpdateValue
            }.ToByteString();

            consensusCommand.Hint.ShouldBe(hint);

            return(consensusCommand);
        }
        private async Task <TransactionList> AEDPoSContract_GenerateConsensusTransactions_FirstRound_BootMiner()
        {
            var consensusCommand = await AEDPoSContract_GetConsensusCommand_FirstRound_BootMiner_Test();

            BlockTimeProvider.SetBlockTime(BlockchainStartTimestamp + new Duration
            {
                Seconds = AEDPoSContractTestConstants.MiningInterval.Div(1000)
            });

            var triggerForCommand =
                TriggerInformationProvider.GetTriggerInformationForConsensusTransactions(
                    consensusCommand.ToBytesValue());

            var transactionList = await AEDPoSContractStub.GenerateConsensusTransactions.CallAsync(triggerForCommand);

            transactionList.Transactions.Count.ShouldBe(1);
            transactionList.Transactions[0].MethodName.ShouldBe(nameof(AEDPoSContractStub.UpdateValue));

            return(transactionList);
        }
        private async Task <ConsensusCommand> AEDPoSContract_GetConsensusCommand_FirstRound_SecondMiner_Test()
        {
            await AEDPoSContract_FirstRound_BootMiner_Test();

            // Now the first time slot of first round already filled by boot miner.

            var usingKeyPair = InitialCoreDataCenterKeyPairs[1];

            KeyPairProvider.SetKeyPair(usingKeyPair);

            var blockchainStartTimestamp = BlockchainStartTimestamp;

            BlockTimeProvider.SetBlockTime(blockchainStartTimestamp + new Duration
            {
                Seconds = AEDPoSContractTestConstants.MiningInterval.Div(1000)
            });

            var triggerForCommand =
                TriggerInformationProvider.GetTriggerInformationForConsensusCommand(new BytesValue());

            var consensusCommand = await AEDPoSContractStub.GetConsensusCommand.CallAsync(triggerForCommand);

            consensusCommand.LimitMillisecondsOfMiningBlock.ShouldBe(AEDPoSContractTestConstants
                                                                     .SmallBlockMiningInterval);
            var hint = new AElfConsensusHint {
                Behaviour = AElfConsensusBehaviour.UpdateValue
            }
            .ToByteString();

            consensusCommand.Hint.ShouldBe(hint);
            consensusCommand.ArrangedMiningTime.ShouldBe(blockchainStartTimestamp + new Duration
            {
                Seconds = AEDPoSContractTestConstants.MiningInterval.Mul(7).Div(1000)
            });

            return(consensusCommand);
        }