Exemple #1
0
        private void InitializeVoteWeightInterest()
        {
            if (State.VoteWeightInterestList.Value != null)
            {
                return;
            }
            var voteWeightSetting = new VoteWeightInterestList();

            voteWeightSetting.VoteWeightInterestInfos.Add(new VoteWeightInterest
            {
                Day      = 365,
                Interest = 1,
                Capital  = 1000
            });
            voteWeightSetting.VoteWeightInterestInfos.Add(new VoteWeightInterest
            {
                Day      = 730,
                Interest = 15,
                Capital  = 10000
            });
            voteWeightSetting.VoteWeightInterestInfos.Add(new VoteWeightInterest
            {
                Day      = 1095,
                Interest = 2,
                Capital  = 1000
            });
            State.VoteWeightInterestList.Value = voteWeightSetting;
        }
Exemple #2
0
        public override Empty SetVoteWeightInterest(VoteWeightInterestList input)
        {
            AssertControllerForManageVoteWeightInterestSetting();
            Assert(input != null && input.VoteWeightInterestInfos.Count > 0, "invalid input");
            foreach (var info in input.VoteWeightInterestInfos)
            {
                Assert(info.Capital > 0, "invalid input");
                Assert(info.Day > 0, "invalid input");
                Assert(info.Interest > 0, "invalid input");
            }

            Assert(input.VoteWeightInterestInfos.GroupBy(x => x.Day).Count() == input.VoteWeightInterestInfos.Count,
                   "repeat day input");
            var orderList = input.VoteWeightInterestInfos.OrderBy(x => x.Day).ToArray();

            input.VoteWeightInterestInfos.Clear();
            input.VoteWeightInterestInfos.AddRange(orderList);
            State.VoteWeightInterestList.Value = input;
            return(new Empty());
        }
Exemple #3
0
        public override Empty SetVoteWeightInterest(VoteWeightInterestList input)
        {
            AssertPerformedByVoteWeightInterestController();
            Assert(input != null && input.VoteWeightInterestInfos.Count > 0, "invalid input");
            // ReSharper disable once PossibleNullReferenceException
            foreach (var info in input.VoteWeightInterestInfos)
            {
                Assert(info.Capital > 0, "invalid input");
                Assert(info.Day > 0, "invalid input");
                Assert(info.Interest > 0, "invalid input");
            }

            Assert(input.VoteWeightInterestInfos.GroupBy(x => x.Day).Count() == input.VoteWeightInterestInfos.Count,
                   "repeat day input");
            var orderList = input.VoteWeightInterestInfos.OrderBy(x => x.Day).ToArray();

            input.VoteWeightInterestInfos.Clear();
            input.VoteWeightInterestInfos.AddRange(orderList);
            State.VoteWeightInterestList.Value = input;
            return(new Empty());
        }
Exemple #4
0
        public async Task ModifyVoteInterest_Test()
        {
            var interestList = await TreasuryContractStub.GetVoteWeightSetting.CallAsync(new Empty());

            interestList.VoteWeightInterestInfos.Count.ShouldBe(3);
            var newInterest = new VoteWeightInterestList();

            newInterest.VoteWeightInterestInfos.Add(new VoteWeightInterest
            {
                Capital  = 1000,
                Interest = 16,
                Day      = 400
            });
            await ExecuteProposalTransaction(Tester, TreasuryContractAddress, nameof(TreasuryContractStub.SetVoteWeightInterest), newInterest);

            interestList = await TreasuryContractStub.GetVoteWeightSetting.CallAsync(new Empty());

            interestList.VoteWeightInterestInfos.Count.ShouldBe(1);
            interestList.VoteWeightInterestInfos[0].Capital.ShouldBe(1000);
            interestList.VoteWeightInterestInfos[0].Interest.ShouldBe(16);
            interestList.VoteWeightInterestInfos[0].Day.ShouldBe(400);
        }
Exemple #5
0
        public async Task TransferAuthorizationForVoteInterest_Test()
        {
            var newInterest = new VoteWeightInterestList();

            newInterest.VoteWeightInterestInfos.Add(new VoteWeightInterest
            {
                Capital  = 1000,
                Interest = 16,
                Day      = 400
            });
            var updateInterestRet = (await TreasuryContractStub.SetVoteWeightInterest.SendAsync(newInterest)).TransactionResult;

            updateInterestRet.Status.ShouldBe(TransactionResultStatus.Failed);
            var newParliament = new Parliament.CreateOrganizationInput
            {
                ProposerAuthorityRequired = false,
                ProposalReleaseThreshold  = new Acs3.ProposalReleaseThreshold
                {
                    MaximalAbstentionThreshold = 1,
                    MaximalRejectionThreshold  = 1,
                    MinimalApprovalThreshold   = 1,
                    MinimalVoteThreshold       = 1
                },
                ParliamentMemberProposingAllowed = false
            };
            var bpParliamentStub    = GetParliamentContractTester(InitialCoreDataCenterKeyPairs[0]);
            var createNewParliament =
                (await bpParliamentStub.CreateOrganization.SendAsync(newParliament)).TransactionResult;

            createNewParliament.Status.ShouldBe(TransactionResultStatus.Mined);
            var calculatedNewParliamentAddress = await ParliamentContractStub.CalculateOrganizationAddress.CallAsync(newParliament);

            var newAuthority = new AuthorityInfo
            {
                OwnerAddress    = calculatedNewParliamentAddress,
                ContractAddress = ParliamentContractAddress
            };

            await ExecuteProposalTransaction(Tester, TreasuryContractAddress, nameof(TreasuryContractStub.ChangeVoteWeightInterestController), newAuthority);

            var proposalToUpdateInterest = new Acs3.CreateProposalInput
            {
                OrganizationAddress = calculatedNewParliamentAddress,
                ContractMethodName  = nameof(TreasuryContractContainer.TreasuryContractStub.SetVoteWeightInterest),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1),
                Params    = newInterest.ToByteString(),
                ToAddress = TreasuryContractAddress
            };
            var createResult = await bpParliamentStub.CreateProposal.SendAsync(proposalToUpdateInterest);

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

            var proposalHash = Hash.Parser.ParseFrom(createResult.TransactionResult.ReturnValue);
            await bpParliamentStub.Approve.SendAsync(proposalHash);

            await ParliamentContractStub.Release.SendAsync(proposalHash);

            var interestList = await TreasuryContractStub.GetVoteWeightSetting.CallAsync(new Empty());

            interestList.VoteWeightInterestInfos.Count.ShouldBe(1);
            interestList.VoteWeightInterestInfos[0].Capital.ShouldBe(1000);
            interestList.VoteWeightInterestInfos[0].Interest.ShouldBe(16);
            interestList.VoteWeightInterestInfos[0].Day.ShouldBe(400);
        }