示例#1
0
        private async Task MineAsync(AEDPoSContractImplContainer.AEDPoSContractImplStub contractStub,
                                     Transaction transaction)
        {
            switch (transaction.MethodName)
            {
            case nameof(AEDPoSContractImplContainer.AEDPoSContractImplStub.UpdateTinyBlockInformation):
                await contractStub.UpdateTinyBlockInformation.SendAsync(
                    TinyBlockInput.Parser.ParseFrom(transaction.Params));

                break;

            case nameof(AEDPoSContractImplContainer.AEDPoSContractImplStub.UpdateValue):
                await contractStub.UpdateValue.SendAsync(UpdateValueInput.Parser.ParseFrom(transaction.Params));

                break;

            case nameof(AEDPoSContractImplContainer.AEDPoSContractImplStub.NextRound):
                await contractStub.NextRound.SendAsync(Round.Parser.ParseFrom(transaction.Params));

                break;

            case nameof(AEDPoSContractImplContainer.AEDPoSContractImplStub.NextTerm):
                await contractStub.NextTerm.SendAsync(Round.Parser.ParseFrom(transaction.Params));

                break;
            }
        }
        protected void InitializeContracts()
        {
            BasicContractZeroStub = GetContractZeroTester(DefaultSenderKeyPair);

            //deploy vote contract
            VoteContractAddress = AsyncHelper.RunSync(() =>
                                                      BasicContractZeroStub.DeploySystemSmartContract.SendAsync(
                                                          new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(VoteContract).Assembly.Location)),
                Name     = VoteSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateVoteInitializationCallList()
            })).Output;
            VoteContractStub = GetVoteContractTester(DefaultSenderKeyPair);

            //deploy token contract
            TokenContractAddress = AsyncHelper.RunSync(() =>
                                                       BasicContractZeroStub.DeploySystemSmartContract.SendAsync(
                                                           new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(TokenContract).Assembly.Location)),
                Name     = TokenSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateTokenInitializationCallList()
            })).Output;
            TokenContractStub = GetTokenContractTester(DefaultSenderKeyPair);

            //deploy parliament auth contract
            ParliamentContractAddress = AsyncHelper.RunSync(() =>
                                                            BasicContractZeroStub.DeploySystemSmartContract.SendAsync(
                                                                new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(ParliamentContract).Assembly.Location)),
                Name     = ParliamentSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateParliamentInitializationCallList()
            })).Output;
            ParliamentContractStub = GetParliamentContractTester(DefaultSenderKeyPair);

            ConsensusContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(DefaultSenderKeyPair)
                                                           .DeploySystemSmartContract.SendAsync(
                                                               new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(AEDPoSContract).Assembly.Location)),
                Name     = ConsensusSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateConsensusInitializationCallList()
            })).Output;
            AEDPoSContractStub = GetConsensusContractTester(DefaultSenderKeyPair);
        }
示例#3
0
        private async Task <AElfConsensusTriggerInformation> GetConsensusTriggerInfoAsync(
            AEDPoSContractImplContainer.AEDPoSContractImplStub contractStub, BytesValue pubkey)
        {
            var command = await contractStub.GetConsensusCommand.CallAsync(pubkey);

            var hint = AElfConsensusHint.Parser.ParseFrom(command.Hint);
            var triggerInformation = new AElfConsensusTriggerInformation
            {
                Behaviour = hint.Behaviour,
                // It doesn't matter for testing.
                InValue         = Hash.FromString($"InValueOf{pubkey}"),
                PreviousInValue = Hash.FromString($"InValueOf{pubkey}"),
                Pubkey          = pubkey.Value
            };

            var consensusExtraData = await contractStub.GetConsensusExtraData.CallAsync(new BytesValue
            {
                Value = triggerInformation.ToByteString()
            });

            var consensusHeaderInformation = new AElfConsensusHeaderInformation();

            consensusHeaderInformation.MergeFrom(consensusExtraData.Value);
            Debug.WriteLine($"Current header information: {consensusHeaderInformation}");

            // Validate consensus extra data.
            {
                var validationResult =
                    await _contractStubs.First().ValidateConsensusBeforeExecution.CallAsync(consensusExtraData);

                if (!validationResult.Success)
                {
                    throw new Exception($"Consensus extra data validation failed: {validationResult.Message}");
                }
            }

            return(triggerInformation);
        }
示例#4
0
        protected void InitializeContracts()
        {
            BasicContractZeroStub = GetContractZeroTester(StarterKeyPair);

            ProfitContractAddress = AsyncHelper.RunSync(() =>
                                                        BasicContractZeroStub.DeploySystemSmartContract.SendAsync(
                                                            new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(ProfitContract).Assembly.Location)),
                Name     = ProfitSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateProfitInitializationCallList()
            })).Output;
            ProfitContractStub = GetProfitContractTester(StarterKeyPair);

            //deploy token holder contract
            TokenHolderContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                             .DeploySystemSmartContract.SendAsync(
                                                                 new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(TokenHolderContract).Assembly.Location)),
                Name     = TokenHolderSmartContractAddressNameProvider.Name,
                TransactionMethodCallList =
                    new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList()
            })).Output;
            TokenHolderContractStub = GetTokenHolderContractTester(StarterKeyPair);

            //deploy token contract
            TokenContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                       .DeploySystemSmartContract.SendAsync(
                                                           new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(TokenContract).Assembly.Location)),
                Name     = TokenSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateTokenInitializationCallList()
            })).Output;
            TokenContractStub = GetTokenContractTester(StarterKeyPair);

            //deploy parliament auth contract
            ParliamentContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                            .DeploySystemSmartContract.SendAsync(
                                                                new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(ParliamentContract).Assembly.Location)),
                Name     = ParliamentSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateParliamentInitializationCallList()
            })).Output;
            ParliamentContractStub = GetParliamentContractTester(StarterKeyPair);

            ConsensusContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                           .DeploySystemSmartContract.SendAsync(
                                                               new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(AEDPoSContract).Assembly.Location)),
                Name     = ConsensusSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateConsensusInitializationCallList()
            })).Output;
            AEDPoSContractStub = GetConsensusContractTester(StarterKeyPair);

            //deploy DApp contract
            DAppContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                      .DeploySystemSmartContract.SendAsync(
                                                          new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(DAppContract).Assembly.Location)),
                Name     = DappSmartContractAddressNameProvider.Name,
                TransactionMethodCallList =
                    new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList
                {
                    Value =
                    {
                        new SystemContractDeploymentInput.Types.SystemTransactionMethodCall
                        {
                            MethodName = nameof(DAppContractStub.InitializeForUnitTest),
                            Params     = new AElf.Contracts.TestContract.DApp.InitializeInput
                            {
                                ProfitReceiver = Address.FromPublicKey(UserKeyPairs[1].PublicKey)
                            }.ToByteString()
                        }
                    }
                }
            })).Output;
            DAppContractStub = GetTester <DAppContainer.DAppStub>(DAppContractAddress,
                                                                  UserKeyPairs.First());
        }