コード例 #1
0
        public async Task <Hash> Create_Proposal()
        {
            _organizationAddress = await Create_Organization();

            _createInput = new CreateInput()
            {
                Symbol      = "NEW",
                Decimals    = 2,
                TotalSupply = 10_0000,
                TokenName   = "new token",
                Issuer      = _organizationAddress,
                IsBurnable  = true
            };
            _createProposalInput = new CreateProposalInput
            {
                ContractMethodName  = nameof(TokenContract.Create),
                ToAddress           = TokenContractAddress,
                Params              = _createInput.ToByteString(),
                ExpiredTime         = BlockTimeProvider.GetBlockTime().AddDays(2).ToTimestamp(),
                OrganizationAddress = _organizationAddress
            };
            var proposal = await ReferendumAuthContractStub.CreateProposal.SendAsync(_createProposalInput);

            proposal.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
            return(proposal.Output);
        }
コード例 #2
0
        private Hash CreateNewProposal(CreateProposalInput input)
        {
            Hash proposalId = GenerateProposalId(input);
            var  proposal   = new ProposalInfo
            {
                ContractMethodName     = input.ContractMethodName,
                ExpiredTime            = input.ExpiredTime,
                Params                 = input.Params,
                ToAddress              = input.ToAddress,
                OrganizationAddress    = input.OrganizationAddress,
                ProposalId             = proposalId,
                Proposer               = Context.Sender,
                ProposalDescriptionUrl = input.ProposalDescriptionUrl
            };

            Assert(Validate(proposal), "Invalid proposal.");
            Assert(State.Proposals[proposalId] == null, "Proposal already exists.");
            State.Proposals[proposalId] = proposal;
            Context.Fire(new ProposalCreated
            {
                ProposalId          = proposalId,
                OrganizationAddress = input.OrganizationAddress
            });
            return(proposalId);
        }
コード例 #3
0
        private async Task <Hash> CreateProposalAsync(ECKeyPair proposalKeyPair, Address organizationAddress)
        {
            var transferInput = new TransferInput()
            {
                Symbol = "ELF",
                Amount = 100,
                To     = Tester,
                Memo   = "Transfer"
            };
            var createProposalInput = new CreateProposalInput
            {
                ContractMethodName  = nameof(TokenContractStub.Transfer),
                ToAddress           = TokenContractAddress,
                Params              = transferInput.ToByteString(),
                ExpiredTime         = BlockTimeProvider.GetBlockTime().AddDays(2),
                OrganizationAddress = organizationAddress
            };

            ParliamentAuthContractStub = GetParliamentAuthContractTester(proposalKeyPair);
            var proposal = await ParliamentAuthContractStub.CreateProposal.SendAsync(createProposalInput);

            proposal.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
            var proposalCreated = ProposalCreated.Parser.ParseFrom(proposal.TransactionResult.Logs[0].NonIndexed).ProposalId;

            proposal.Output.ShouldBe(proposalCreated);

            return(proposal.Output);
        }
コード例 #4
0
ファイル: ReferendumAuth.cs プロジェクト: xiaoxiongnpu/AElf
        public override Hash CreateProposal(CreateProposalInput proposal)
        {
            Assert(
                !string.IsNullOrWhiteSpace(proposal.ContractMethodName) &&
                proposal.ToAddress != null &&
                proposal.OrganizationAddress != null &&
                proposal.ExpiredTime != null, "Invalid proposal.");
            var organization = State.Organisations[proposal.OrganizationAddress];

            Assert(organization != null, "No registered organization.");
            DateTime timestamp = proposal.ExpiredTime.ToDateTime();

            Assert(Context.CurrentBlockTime < timestamp, "Expired proposal.");
            Hash hash = Hash.FromMessage(proposal);

            Assert(State.Proposals[hash] == null, "Proposal already exists.");
            State.Proposals[hash] = new ProposalInfo
            {
                ContractMethodName  = proposal.ContractMethodName,
                ToAddress           = proposal.ToAddress,
                ExpiredTime         = proposal.ExpiredTime,
                Params              = proposal.Params,
                OrganizationAddress = proposal.OrganizationAddress,
                Proposer            = Context.Sender
            };
            return(hash);
        }
コード例 #5
0
        public async Task MethodFeeController_Test_Fail()
        {
            var updateMethodName = nameof(BasicContractZeroImplContainer.BasicContractZeroImplStub.ChangeMethodFeeController);
            // no authority
            var newAuthority = await CreateNewParliamentAddressAsync();

            //invalid new organization
            var defaultParliamentAddress = await GetDefaultParliamentAddressAsync();

            var invalidAuthority = new AuthorityInfo
            {
                OwnerAddress    = newAuthority.OwnerAddress,
                ContractAddress = AssociationContractAddress
            };
            var createProposalInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = invalidAuthority.ToByteString(),
                OrganizationAddress = defaultParliamentAddress,
                ContractMethodName  = updateMethodName,
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var ret = await MainChainTesterCreatApproveAndReleaseProposalForParliamentAsync(createProposalInput);

            ret.Error.ShouldContain("Invalid authority input");
        }
コード例 #6
0
        public async Task ChangeSymbolsToPayTXSizeFeeController_Fail_Test()
        {
            // no authority
            var newAuthority = await CreateNewParliamentAddressAsync();

            var updateWithOutAuthorityRet =
                await TokenContractStub.ChangeSymbolsToPayTXSizeFeeController.SendWithExceptionAsync(newAuthority);

            updateWithOutAuthorityRet.TransactionResult.Error.ShouldContain("no permission");

            //invalid new organization
            var defaultParliamentAddress = await GetDefaultParliamentAddressAsync();

            var invalidAuthority = new AuthorityInfo
            {
                OwnerAddress    = newAuthority.OwnerAddress,
                ContractAddress = AssociationContractAddress
            };
            var createProposalInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = invalidAuthority.ToByteString(),
                OrganizationAddress = defaultParliamentAddress,
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub
                                             .ChangeSymbolsToPayTXSizeFeeController),
                ExpiredTime = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var ret = await MainChainTesterCreatApproveAndReleaseProposalForParliamentAsync(createProposalInput);

            ret.Error.ShouldContain("new controller does not exist");
        }
コード例 #7
0
        private async Task Profit_SetMethodFee(string method, string symbol, long feeAmount)
        {
            var gensisOwner = await ParliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty());

            var proposal = new CreateProposalInput
            {
                OrganizationAddress = gensisOwner,
                ContractMethodName  = nameof(ProfitContractStub.SetMethodFee),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                Params = new MethodFees
                {
                    MethodName = method,
                    Fees       =
                    {
                        new MethodFee
                        {
                            Symbol   = symbol,
                            BasicFee = feeAmount
                        }
                    }
                }.ToByteString(),
                ToAddress = ProfitContractAddress
            };
            var createResult = await ParliamentContractStub.CreateProposal.SendAsync(proposal);

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

            var proposalId = createResult.Output;

            await ApproveWithAllMinersAsync(proposalId);

            var releaseResult = await ParliamentContractStub.Release.SendAsync(proposalId);

            releaseResult.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
        }
コード例 #8
0
        private async Task <Hash> CreateApproveAndToSideChainRentalDefaultProposalAsync(string methodName,
                                                                                        IMessage message)
        {
            var defaultController =
                await TokenContractStub.GetSideChainRentalControllerCreateInfo.CallAsync(new Empty());

            var defaultParliamentAddress =
                await ParliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty());

            var toAssociationProposal = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                ContractMethodName  = methodName,
                Params              = message.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = defaultController.OwnerAddress
            };
            var associationProposalRet = (await AssociationContractStub.CreateProposal.SendAsync(toAssociationProposal))
                                         .TransactionResult;
            var associationProposalId = new Hash();

            associationProposalId.MergeFrom(associationProposalRet.ReturnValue);
            await ParliamentReachAnAgreementAsync(AssociationContractAddress, defaultParliamentAddress,
                                                  nameof(AssociationContractImplContainer.AssociationContractImplStub.Approve), associationProposalId);

            await AssociationContractStub.Approve.SendAsync(associationProposalId);

            return(associationProposalId);
        }
コード例 #9
0
        private Hash CreateNewProposal(CreateProposalInput input)
        {
            Hash proposalId = Hash.FromTwoHashes(Hash.FromTwoHashes(Hash.FromMessage(input), Context.TransactionId),
                                                 Hash.FromRawBytes(Context.CurrentBlockTime.ToByteArray()));

            Assert(State.Proposals[proposalId] == null, "Proposal already exists.");
            var proposal = new ProposalInfo
            {
                ContractMethodName     = input.ContractMethodName,
                ToAddress              = input.ToAddress,
                ExpiredTime            = input.ExpiredTime,
                Params                 = input.Params,
                OrganizationAddress    = input.OrganizationAddress,
                Proposer               = Context.Sender,
                ProposalDescriptionUrl = input.ProposalDescriptionUrl
            };

            Assert(Validate(proposal), "Invalid proposal.");
            State.Proposals[proposalId] = proposal;
            Context.Fire(new ProposalCreated {
                ProposalId = proposalId
            });

            return(proposalId);
        }
コード例 #10
0
        private async Task <Hash> CreateProposalAsync(ECKeyPair proposalKeyPair, Address organizationAddress)
        {
            var createInput = new CreateInput()
            {
                Symbol      = "NEW",
                Decimals    = 2,
                TotalSupply = 10_0000,
                TokenName   = "new token",
                Issuer      = organizationAddress,
                IsBurnable  = true
            };
            var createProposalInput = new CreateProposalInput
            {
                ContractMethodName  = nameof(TokenContract.Create),
                ToAddress           = TokenContractAddress,
                Params              = createInput.ToByteString(),
                ExpiredTime         = BlockTimeProvider.GetBlockTime().AddDays(2),
                OrganizationAddress = organizationAddress
            };

            ReferendumAuthContractStub = GetReferendumAuthContractTester(proposalKeyPair);
            var proposal = await ReferendumAuthContractStub.CreateProposal.SendAsync(createProposalInput);

            proposal.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
            return(proposal.Output);
        }
コード例 #11
0
        public override Hash CreateProposal(CreateProposalInput input)
        {
            AssertIsAuthorizedProposer(input.OrganizationAddress, Context.Sender);
            var proposalId = CreateNewProposal(input);

            return(proposalId);
        }
コード例 #12
0
        public override Hash CreateProposal(CreateProposalInput input)
        {
            var organization = State.Organisations[input.OrganizationAddress];

            Assert(organization != null, "No registered organization.");

            Hash hash     = Hash.FromTwoHashes(Hash.FromMessage(input), Context.TransactionId);
            var  proposal = new ProposalInfo
            {
                ContractMethodName  = input.ContractMethodName,
                ToAddress           = input.ToAddress,
                ExpiredTime         = input.ExpiredTime,
                Params              = input.Params,
                OrganizationAddress = input.OrganizationAddress,
                Proposer            = Context.Sender
            };

            Assert(Validate(proposal), "Invalid proposal.");
            Assert(State.Proposals[hash] == null, "Proposal already exists.");
            State.Proposals[hash] = proposal;
            Context.Fire(new ProposalCreated {
                ProposalId = hash
            });

            return(hash);
        }
コード例 #13
0
        private async Task VoteToReferendum(Hash input)
        {
            var organizations = await GetControllerForUserFee();

            var referendumProposal = new CreateProposalInput
            {
                ToAddress           = AssociationAddress,
                Params              = input.ToByteString(),
                OrganizationAddress = organizations.ReferendumController,
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.Approve),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var parliamentProposal = new CreateProposalInput
            {
                ToAddress           = ReferendumAddress,
                Params              = referendumProposal.ToByteString(),
                OrganizationAddress = organizations.ParliamentController,
                ContractMethodName  = nameof(ReferendumContractContainer.ReferendumContractStub.CreateProposal),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var parliamentCreateProposal = await MainChainTester.ExecuteContractWithMiningAsync(ParliamentAddress,
                                                                                                nameof(ParliamentContractContainer.ParliamentContractStub.CreateProposal),
                                                                                                parliamentProposal);

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

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

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

            var id = ProposalCreated.Parser
                     .ParseFrom(ret.Logs.First(l => l.Name.Contains(nameof(ProposalCreated)))
                                .NonIndexed).ProposalId;
            await MainChainTester.ExecuteContractWithMiningAsync(ReferendumAddress,
                                                                 nameof(ReferendumContractContainer.ReferendumContractStub.Approve),
                                                                 id);

            parliamentProposal = new CreateProposalInput
            {
                ToAddress           = ReferendumAddress,
                Params              = id.ToByteString(),
                OrganizationAddress = organizations.ParliamentController,
                ContractMethodName  = nameof(ReferendumContractContainer.ReferendumContractStub.Release),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            parliamentCreateProposal = await MainChainTester.ExecuteContractWithMiningAsync(ParliamentAddress,
                                                                                            nameof(ParliamentContractContainer.ParliamentContractStub.CreateProposal),
                                                                                            parliamentProposal);

            parliamentCreateProposal.Status.ShouldBe(TransactionResultStatus.Mined);
            parliamentProposalId = new Hash();
            parliamentProposalId.MergeFrom(parliamentCreateProposal.ReturnValue);
            await ApproveWithMinersAsync(parliamentProposalId, ParliamentAddress, MainChainTester);
            await ReleaseProposalAsync(parliamentProposalId, ParliamentAddress, MainChainTester);
        }
コード例 #14
0
 internal CreateProposalInput CreateParliamentProposalInput(IMessage input, Address organizationAddress)
 {
     var createProposalInput = new CreateProposalInput
     {
         ContractMethodName = nameof(ParliamentContractContainer.ParliamentContractStub.ChangeOrganizationProposerWhiteList),
         ToAddress = ParliamentAddress,
         Params = input.ToByteString(),
         ExpiredTime =  DateTime.UtcNow.AddDays(1).ToTimestamp(),
         OrganizationAddress = organizationAddress
     };
     return createProposalInput;
 }
コード例 #15
0
 internal CreateProposalInput CreateProposalInput(IMessage input, Address organizationAddress)
 {
     var createProposalInput = new CreateProposalInput
     {
         ContractMethodName = nameof(TokenContractContainer.TokenContractStub.Transfer),
         ExpiredTime = DateTime.UtcNow.AddDays(1).ToTimestamp(),
         Params = input.ToByteString(),
         ToAddress = TokenContractAddress,
         OrganizationAddress = organizationAddress
     };
     return createProposalInput;
 }
コード例 #16
0
        public async Task ChangeSymbolsToPayTXSizeFeeController_Success_Test()
        {
            var primaryToken = await TokenContractStub.GetPrimaryTokenSymbol.CallAsync(new Empty());

            var newSymbolList = new SymbolListToPayTxSizeFee();

            newSymbolList.SymbolsToPayTxSizeFee.Add(new SymbolToPayTxSizeFee
            {
                TokenSymbol      = primaryToken.Value,
                AddedTokenWeight = 1,
                BaseTokenWeight  = 1
            });

            // create a new organization to be replace the controller of SetSymbolsToPayTxSizeFee
            var newAuthority = await CreateNewParliamentAddressAsync();

            // get the default parliament that is the controller of SetSymbolsToPayTxSizeFee
            var defaultParliamentAddress = await GetDefaultParliamentAddressAsync();

            // create a proposal to replace the controller
            var createProposalInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = newAuthority.ToByteString(),
                OrganizationAddress = defaultParliamentAddress,
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub
                                             .ChangeSymbolsToPayTXSizeFeeController),
                ExpiredTime = TimestampHelper.GetUtcNow().AddHours(1)
            };

            await MainChainTesterCreatApproveAndReleaseProposalForParliamentAsync(createProposalInput);

            // the new controller try to send SetSymbolsToPayTxSizeFee
            var updateInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = newSymbolList.ToByteString(),
                OrganizationAddress = newAuthority.OwnerAddress,
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub.SetSymbolsToPayTxSizeFee),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };

            await MainChainTesterCreatApproveAndReleaseProposalForParliamentAsync(updateInput);

            var symbolSet = await TokenContractStub.GetSymbolsToPayTxSizeFee.CallAsync(new Empty());

            symbolSet.SymbolsToPayTxSizeFee.Count.ShouldBe(1);
        }
コード例 #17
0
        private Hash Propose(int waitingPeriod, Address targetAddress, string invokingMethod, IMessage input)
        {
            var expiredTime = Context.CurrentBlockTime.AddSeconds(waitingPeriod).ToUniversalTime();
            var proposal    = new CreateProposalInput
            {
                ContractMethodName  = invokingMethod,
                OrganizationAddress = GetOwnerAddress(),
                ExpiredTime         = Timestamp.FromDateTime(expiredTime),
                Params    = input.ToByteString(),
                ToAddress = targetAddress
            };

            ValidateContractState(State.ParliamentAuthContract, State.ParliamentAuthContractSystemName.Value);
            State.ParliamentAuthContract.CreateProposal.Send(proposal);
            return(Hash.FromMessage(proposal));
        }
コード例 #18
0
        /// <summary>
        /// 添加建议
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task CreateProposalAsync(CreateProposalInput input)
        {
            var _default = await _cacheManager.GetCache(BlogCacheNames.CacheBlogProposal)
                           .GetOrDefaultAsync($"{_clientInfoProvider.ClientIpAddress}");

            if (_default != null)
            {
                throw new UserFriendlyException(401, "请等待十分钟后再投递");
            }
            var proposal = ObjectMapper.Map <BlogProposal>(input);

            proposal.Ip = _clientInfoProvider.ClientIpAddress;
            await _blogProposalRepository.InsertAsync(proposal);

            await _cacheManager.GetCache(BlogCacheNames.CacheBlogProposal)
            .SetAsync(_clientInfoProvider.ClientIpAddress, DateTime.Now.ToString());
        }
コード例 #19
0
        public override Hash CreateProposal(CreateProposalInput input)
        {
            var proposalId = Context.GenerateId(Context.Self, input.Token);

            Assert(State.Proposals[proposalId] == null, "Proposal with same token already exists.");
            State.Proposals[proposalId] = new ProposalInfo
            {
                ProposalId             = proposalId,
                Proposer               = Context.Sender,
                ContractMethodName     = input.ContractMethodName,
                Params                 = input.Params,
                ExpiredTime            = input.ExpiredTime,
                ToAddress              = input.ToAddress,
                ProposalDescriptionUrl = input.ProposalDescriptionUrl
            };
            return(proposalId);
        }
        private Hash CreateProposalToSelf(string methodName, ByteString parameter)
        {
            var proposalToken = HashHelper.XorAndCompute(HashHelper.ComputeFrom(parameter.ToByteArray()),
                                                         Context.PreviousBlockHash);
            var createProposalInput = new CreateProposalInput
            {
                ContractMethodName  = methodName,
                Params              = parameter,
                OrganizationAddress = State.OrganizationAddress.Value,
                ExpiredTime         = GetExpiredTime(),
                ToAddress           = Context.Self,
                Token = proposalToken
            };

            State.AssociationContract.CreateProposal.Send(createProposalInput);
            return(Context.GenerateId(State.AssociationContract.Value, proposalToken));
        }
コード例 #21
0
        protected async Task <Hash> CreateProposalAsync(Address contractAddress, Address organizationAddress,
                                                        string methodName, IMessage input)
        {
            var proposal = new CreateProposalInput
            {
                OrganizationAddress = organizationAddress,
                ContractMethodName  = methodName,
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1),
                Params    = input.ToByteString(),
                ToAddress = ConsensusContractAddress
            };

            var createResult = await ParliamentContractStub.CreateProposal.SendAsync(proposal);

            var proposalId = createResult.Output;

            return(proposalId);
        }
コード例 #22
0
        private async Task <Hash> CreateFeeProposalAsync(Address contractAddress, Address organizationAddress,
                                                         string methodName, IMessage input)
        {
            var parliamentContractStub = GetParliamentContractTester(InitialMinersKeyPairs[0]);
            var proposal = new CreateProposalInput
            {
                OrganizationAddress = organizationAddress,
                ContractMethodName  = methodName,
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1),
                Params    = input.ToByteString(),
                ToAddress = contractAddress
            };

            var createResult = await parliamentContractStub.CreateProposal.SendAsync(proposal);

            var proposalId = createResult.Output;

            return(proposalId);
        }
コード例 #23
0
        private async Task ApproveThenReleaseMiddleProposalForDeveloper(Hash input)
        {
            var organizations = await GetControllerForDeveloperFee();

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

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

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

            approveLeafProposalInput = new CreateProposalInput
            {
                ToAddress           = AssociationAddress,
                Params              = input.ToByteString(),
                OrganizationAddress = organizations.ParliamentController,
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.Release),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            parliamentCreateProposal = await MainChainTester.ExecuteContractWithMiningAsync(ParliamentAddress,
                                                                                            nameof(ParliamentContractContainer.ParliamentContractStub.CreateProposal),
                                                                                            approveLeafProposalInput);

            parliamentCreateProposal.Status.ShouldBe(TransactionResultStatus.Mined);
            parliamentProposalId = new Hash();
            parliamentProposalId.MergeFrom(parliamentCreateProposal.ReturnValue);
            await ApproveWithMinersAsync(parliamentProposalId, ParliamentAddress, MainChainTester);
            await ReleaseProposalAsync(parliamentProposalId, ParliamentAddress, MainChainTester);
        }
コード例 #24
0
        public async Task <Hash> Create_Proposal(Address organizationAddress)
        {
            _transferInput = new TransferInput()
            {
                Symbol = "ELF",
                Amount = 100,
                To     = Tester,
                Memo   = "Transfer"
            };
            _createProposalInput = new CreateProposalInput
            {
                ContractMethodName  = nameof(TokenContract.Transfer),
                ToAddress           = TokenContractAddress,
                Params              = _transferInput.ToByteString(),
                ExpiredTime         = BlockTimeProvider.GetBlockTime().AddDays(2).ToTimestamp(),
                OrganizationAddress = organizationAddress
            };
            var proposal = await ParliamentAuthContractStub.CreateProposal.SendAsync(_createProposalInput);

            proposal.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
            return(proposal.Output);
        }
コード例 #25
0
        private async Task <Hash> CreateToRootForUserFeeByTwoLayer(CoefficientFromSender input)
        {
            var organizations = await GetControllerForUserFee();

            var createNestProposalInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = input.ToByteString(),
                OrganizationAddress = organizations.RootController,
                ContractMethodName  = nameof(TokenContractContainer.TokenContractStub.UpdateCoefficientFromSender),
                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);
        }
コード例 #26
0
        private async Task Vote_SetMethodFee(string method, string symbol, long feeAmount)
        {
            var gensisOwner = await ParliamentAuthContractStub.GetGenesisOwnerAddress.CallAsync(new Empty());

            var proposal = new CreateProposalInput
            {
                OrganizationAddress = gensisOwner,
                ContractMethodName  = nameof(VoteContractStub.SetMethodFee),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                Params = new MethodFees
                {
                    MethodName = method,
                    Fees       =
                    {
                        new MethodFee
                        {
                            Symbol   = symbol,
                            BasicFee = feeAmount
                        }
                    }
                }.ToByteString(),
                ToAddress = VoteContractAddress
            };
            var createResult = await ParliamentAuthContractStub.CreateProposal.SendAsync(proposal);

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

            var proposalHash  = createResult.Output;
            var approveResult = await ParliamentAuthContractStub.Approve.SendAsync(new Acs3.ApproveInput
            {
                ProposalId = proposalHash,
            });

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

            var releaseResult = await ParliamentAuthContractStub.Release.SendAsync(proposalHash);

            releaseResult.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
        }
コード例 #27
0
        internal async Task ParliamentReachAnAgreementAsync(CreateProposalInput createProposalInput)
        {
            var createProposalTx = ParliamentStubs.First().CreateProposal.GetTransaction(createProposalInput);
            await BlockMiningService.MineBlockAsync(new List <Transaction>
            {
                createProposalTx
            });

            var proposalId = new Hash();

            proposalId.MergeFrom(TransactionTraceProvider.GetTransactionTrace(createProposalTx.GetHash()).ReturnValue);
            var approvals = new List <Transaction>();

            foreach (var stub in ParliamentStubs)
            {
                approvals.Add(stub.Approve.GetTransaction(proposalId));
            }

            await BlockMiningService.MineBlockAsync(approvals);

            await ParliamentStubs.First().Release.SendAsync(proposalId);
        }
コード例 #28
0
        private async Task <Hash> ApproveToRootForDeveloperFeeByMiddleLayer(Hash input)
        {
            var organizations = await GetControllerForDeveloperFee();

            var approveMidProposalInput = new CreateProposalInput
            {
                ToAddress           = AssociationAddress,
                Params              = input.ToByteString(),
                OrganizationAddress = organizations.DeveloperController,
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.Approve),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var approveLeafProposalInput = new CreateProposalInput
            {
                ToAddress           = AssociationAddress,
                Params              = approveMidProposalInput.ToByteString(),
                OrganizationAddress = organizations.ParliamentController,
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.CreateProposal),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };
            var parliamentCreateProposal = await MainChainTester.ExecuteContractWithMiningAsync(ParliamentAddress,
                                                                                                nameof(ParliamentContractContainer.ParliamentContractStub.CreateProposal),
                                                                                                approveLeafProposalInput);

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

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

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

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

            return(middleProposalId);
        }
コード例 #29
0
        private async Task <Hash> CreateProposalAsync(ECKeyPair proposalKeyPair, Address organizationAddress)
        {
            var transferInput = new TransferInput()
            {
                Symbol = "ELF",
                Amount = 100,
                To     = Reviewer1,
                Memo   = "Transfer"
            };

            AssociationAuthContractStub = GetAssociationAuthContractTester(proposalKeyPair);
            var createProposalInput = new CreateProposalInput
            {
                ContractMethodName  = nameof(TokenContract.Transfer),
                ToAddress           = TokenContractAddress,
                Params              = transferInput.ToByteString(),
                ExpiredTime         = BlockTimeProvider.GetBlockTime().AddDays(2),
                OrganizationAddress = organizationAddress
            };
            var proposal = await AssociationAuthContractStub.CreateProposal.SendAsync(createProposalInput);

            return(proposal.Output);
        }
コード例 #30
0
        public async Task MethodFeeController_Test_Success()
        {
            var defaultController = await TokenContractStub.GetMethodFeeController.CallAsync(new Empty());

            var createOrganizationResult = await ParliamentContractStub.CreateOrganization.SendAsync(
                new CreateOrganizationInput
            {
                ProposalReleaseThreshold = new ProposalReleaseThreshold
                {
                    MinimalApprovalThreshold = 1000,
                    MinimalVoteThreshold     = 1000
                }
            });

            var organizationAddress = createOrganizationResult.Output;

            //change controller
            var newController = new AuthorityInfo
            {
                ContractAddress = defaultController.ContractAddress,
                OwnerAddress    = organizationAddress
            };
            var createProposalInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = newController.ToByteString(),
                OrganizationAddress = defaultController.OwnerAddress,
                ContractMethodName  = nameof(BasicContractZeroImplContainer.BasicContractZeroImplStub.ChangeMethodFeeController),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };

            await MainChainTesterCreatApproveAndReleaseProposalForParliamentAsync(createProposalInput);

            var queryController = await TokenContractStub.GetMethodFeeController.CallAsync(new Empty());

            queryController.ShouldBe(newController);
        }