Esempio n. 1
0
        public async Task Treasury_SetMinerRewardWeightSetting_Fail_Test()
        {
            //without authority
            {
                var setRet =
                    await TreasuryContractStub.SetMinerRewardWeightSetting.SendAsync(new MinerRewardWeightSetting());

                setRet.TransactionResult.Status.ShouldBe(TransactionResultStatus.Failed);
                setRet.TransactionResult.Error.ShouldContain("no permission");
            }

            //invalid Inpout
            {
                var methodName             = nameof(TreasuryContractStub.SetMinerRewardWeightSetting);
                var newRewardWeightSetting = new MinerRewardWeightSetting
                {
                    BasicMinerRewardWeight = 0
                };
                var setRet = await ExecuteProposalForParliamentTransactionWithException(Tester, TreasuryContractAddress, methodName,
                                                                                        newRewardWeightSetting);

                setRet.Status.ShouldBe(TransactionResultStatus.Failed);
                setRet.Error.ShouldContain("invalid input");
            }
        }
 public override Empty SetMinerRewardWeightSetting(MinerRewardWeightSetting input)
 {
     AssertPerformedByTreasuryController();
     Assert(
         input.BasicMinerRewardWeight > 0 && input.ReElectionRewardWeight > 0 &&
         input.VotesWeightRewardWeight > 0,
         "invalid input");
     ResetSubSchemeToMinerReward(input);
     State.MinerRewardWeightSetting.Value = input;
     return(new Empty());
 }
        private void ResetSubSchemeToMinerReward(MinerRewardWeightSetting newWeightSetting)
        {
            var oldWeightSetting = State.MinerRewardWeightSetting.Value ?? new MinerRewardWeightSetting();
            var parentSchemeId   = State.RewardHash.Value;

            // Register or reset `MinerBasicReward` to `MinerReward`
            SendToProfitContractToResetWeight(parentSchemeId, State.BasicRewardHash.Value,
                                              oldWeightSetting.BasicMinerRewardWeight, newWeightSetting.BasicMinerRewardWeight);
            // Register or reset `MinerVotesWeightReward` to `MinerReward`
            SendToProfitContractToResetWeight(parentSchemeId, State.VotesWeightRewardHash.Value,
                                              oldWeightSetting.VotesWeightRewardWeight, newWeightSetting.VotesWeightRewardWeight);
            // Register or reset `ReElectionMinerReward` to `MinerReward`
            SendToProfitContractToResetWeight(parentSchemeId, State.ReElectionRewardHash.Value,
                                              oldWeightSetting.ReElectionRewardWeight, newWeightSetting.ReElectionRewardWeight);
        }
Esempio n. 4
0
        public async Task Treasury_SetMinerRewardWeightSetting_Success_Test()
        {
            var defaultWeightSetting = await TreasuryContractStub.GetMinerRewardWeightProportion.CallAsync(new Empty());

            defaultWeightSetting.BasicMinerRewardProportionInfo.Proportion.ShouldBe(50);
            defaultWeightSetting.ReElectionRewardProportionInfo.Proportion.ShouldBe(25);
            defaultWeightSetting.VotesWeightRewardProportionInfo.Proportion.ShouldBe(25);
            var newWeightSetting = new MinerRewardWeightSetting
            {
                BasicMinerRewardWeight  = 1,
                ReElectionRewardWeight  = 1,
                VotesWeightRewardWeight = 8
            };

            await ExecuteProposalForParliamentTransaction(Tester, TreasuryContractAddress,
                                                          nameof(TreasuryContractStub.SetMinerRewardWeightSetting), newWeightSetting);

            var updatedWeightSetting = await TreasuryContractStub.GetMinerRewardWeightProportion.CallAsync(new Empty());

            updatedWeightSetting.BasicMinerRewardProportionInfo.Proportion.ShouldBe(10);
            updatedWeightSetting.ReElectionRewardProportionInfo.Proportion.ShouldBe(10);
            updatedWeightSetting.VotesWeightRewardProportionInfo.Proportion.ShouldBe(80);
            var minerRewardProfit =
                await ProfitContractStub.GetScheme.CallAsync(ProfitItemsIds[ProfitType.MinerReward]);

            var subSchemes = minerRewardProfit.SubSchemes;

            subSchemes.Count.ShouldBe(3);
            var basicMinerRewardScheme = subSchemes.Single(x =>
                                                           x.SchemeId == updatedWeightSetting.BasicMinerRewardProportionInfo.SchemeId);

            basicMinerRewardScheme.Shares.ShouldBe(1);
            var reElectionRewardScheme = subSchemes.Single(x =>
                                                           x.SchemeId == updatedWeightSetting.ReElectionRewardProportionInfo.SchemeId);

            reElectionRewardScheme.Shares.ShouldBe(1);
            var votesWeightRewardScheme = subSchemes.Single(x =>
                                                            x.SchemeId == updatedWeightSetting.VotesWeightRewardProportionInfo.SchemeId);

            votesWeightRewardScheme.Shares.ShouldBe(8);
        }