public override Empty UpdateCoefficientFromContract(CoefficientFromContract coefficientInput)
        {
            if (coefficientInput == null)
            {
                return(new Empty());
            }
            Assert(Context.Sender == State.ControllerForDeveloperFee.Value.RootController, "no permission");
            var coefficientInfoInState = State.CalculateCoefficientOfContract[coefficientInput.FeeType];

            if (coefficientInfoInState == null)
            {
                return(new Empty());
            }
            var coefficient     = coefficientInput.Coefficient;
            var funcCoefficient =
                coefficientInfoInState.Coefficients.SingleOrDefault(x => x.PieceKey == coefficient.PieceKey);

            Assert(funcCoefficient != null, $"piece key:{coefficient.PieceKey} does not exist");
            if (!IsModifiedDbData(coefficientInput.Coefficient, funcCoefficient))
            {
                return(new Empty());
            }
            State.CalculateCoefficientOfContract[coefficientInput.FeeType] = coefficientInfoInState;
            Context.Fire(new NoticeUpdateCalculateFeeAlgorithm
            {
                AllCoefficient = coefficientInfoInState
            });
            return(new Empty());
        }
Example #2
0
        public async Task Update_Coefficient_For_Contract_Should_Success()
        {
            const int         pieceKey = 1000000;
            const FeeTypeEnum feeType  = FeeTypeEnum.Traffic;
            var updateInput            = new CoefficientFromContract
            {
                FeeType     = feeType,
                Coefficient = new CoefficientFromSender
                {
                    LinerCoefficient = new LinerCoefficient
                    {
                        ConstantValue = 1,
                        Denominator   = 2,
                        Numerator     = 3
                    },
                    PieceKey = pieceKey,
                    IsLiner  = true
                }
            };

            var proposalId = await CreateToRootForDeveloperFeeByTwoLayer(updateInput);

            await ApproveToRootForDeveloperFeeByTwoLayer(proposalId);

            var middleApproveProposalId = await ApproveToRootForDeveloperFeeByMiddleLayer(proposalId);

            await ApproveThenReleaseMiddleProposalForDeveloper(middleApproveProposalId);

            await ReleaseToRootForDeveloperFeeByTwoLayer(proposalId);

            var developerCoefficientRet = await MainChainTester.ExecuteContractWithMiningAsync(TokenContractAddress,
                                                                                               nameof(TokenContractContainer.TokenContractStub.GetCalculateFeeCoefficientOfContract), new SInt32Value
            {
                Value = (int)feeType
            });

            developerCoefficientRet.Status.ShouldBe(TransactionResultStatus.Mined);
            var userCoefficient = new CalculateFeeCoefficientsOfType();

            userCoefficient.MergeFrom(developerCoefficientRet.ReturnValue);
            var hasModified = userCoefficient.Coefficients.Single(x => x.PieceKey == pieceKey);

            hasModified.CoefficientDic["ConstantValue".ToLower()].ShouldBe(1);
            hasModified.CoefficientDic["Denominator".ToLower()].ShouldBe(2);
            hasModified.CoefficientDic["Numerator".ToLower()].ShouldBe(3);
        }
Example #3
0
        private async Task <Hash> CreateToRootForDeveloperFeeByTwoLayer(CoefficientFromContract input)
        {
            var organizations = await GetControllerForDeveloperFee();

            var createNestProposalInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = input.ToByteString(),
                OrganizationAddress = organizations.RootController,
                ContractMethodName  = nameof(TokenContractContainer.TokenContractStub.UpdateCoefficientFromContract),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var createProposalInput = new CreateProposalInput
            {
                ToAddress           = AssociationAddress,
                Params              = createNestProposalInput.ToByteString(),
                OrganizationAddress = organizations.ParliamentController,
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.CreateProposal),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var parliamentCreateProposal = await MainChainTester.ExecuteContractWithMiningAsync(ParliamentAddress,
                                                                                                nameof(ParliamentContractContainer.ParliamentContractStub.CreateProposal),
                                                                                                createProposalInput);

            parliamentCreateProposal.Status.ShouldBe(TransactionResultStatus.Mined);
            var parliamentProposalId = new Hash();

            parliamentProposalId.MergeFrom(parliamentCreateProposal.ReturnValue);
            await ApproveWithMinersAsync(parliamentProposalId, ParliamentAddress, MainChainTester);

            var releaseRet = await ReleaseProposalAsync(parliamentProposalId, ParliamentAddress, MainChainTester);

            var id = ProposalCreated.Parser
                     .ParseFrom(releaseRet.Logs.First(l => l.Name.Contains(nameof(ProposalCreated)))
                                .NonIndexed).ProposalId;

            return(id);
        }