Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve acs3 protocol #3566

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion contract/AElf.Contracts.Association/Association.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public override ProposalOutput GetProposal(Hash proposalId)
ToBeReleased = readyToRelease,
ApprovalCount = proposal.Approvals.Count,
RejectionCount = proposal.Rejections.Count,
AbstentionCount = proposal.Abstentions.Count
AbstentionCount = proposal.Abstentions.Count,
Title = proposal.Title,
Description = proposal.Description
};
}

Expand Down
8 changes: 8 additions & 0 deletions contract/AElf.Contracts.Association/AssociationConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AElf.Contracts.Association;

public static class AssociationConstants
{
public const int MaxLengthForTitle = 255;
public const int MaxLengthForDescription = 10200;
public const int MaxLengthForProposalDescriptionUrl = 255;
}
20 changes: 18 additions & 2 deletions contract/AElf.Contracts.Association/Association_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private Hash GenerateProposalId(CreateProposalInput input)

private Hash CreateNewProposal(CreateProposalInput input)
{
CheckCreateProposalInput(input);
var proposalId = GenerateProposalId(input);
var proposal = new ProposalInfo
{
Expand All @@ -154,16 +155,31 @@ private Hash CreateNewProposal(CreateProposalInput input)
OrganizationAddress = input.OrganizationAddress,
ProposalId = proposalId,
Proposer = Context.Sender,
ProposalDescriptionUrl = input.ProposalDescriptionUrl
ProposalDescriptionUrl = input.ProposalDescriptionUrl,
Title = input.Title,
Description = input.Description
};
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
OrganizationAddress = input.OrganizationAddress,
Title = input.Title,
Description = input.Description
});
return proposalId;
}

private void CheckCreateProposalInput(CreateProposalInput input)
{
// Check the length of title
Assert(input.Title.Length <= AssociationConstants.MaxLengthForTitle, "Title is too long.");
// Check the length of description
Assert(input.Description.Length <= AssociationConstants.MaxLengthForDescription, "Description is too long.");
// Check the length of description url
Assert(input.ProposalDescriptionUrl.Length <= AssociationConstants.MaxLengthForProposalDescriptionUrl,
"Description url is too long.");
}
}
4 changes: 3 additions & 1 deletion contract/AElf.Contracts.Parliament/Parliament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@
ToBeReleased = Validate(proposal) && IsReleaseThresholdReached(proposal, organization),
ApprovalCount = proposal.Approvals.Count,
RejectionCount = proposal.Rejections.Count,
AbstentionCount = proposal.Abstentions.Count
AbstentionCount = proposal.Abstentions.Count,
Title = proposal.Title,
Description = proposal.Description

Check warning on line 246 in contract/AElf.Contracts.Parliament/Parliament.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.Parliament/Parliament.cs#L244-L246

Added lines #L244 - L246 were not covered by tests
};
}

Expand Down
8 changes: 8 additions & 0 deletions contract/AElf.Contracts.Parliament/ParliamentConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AElf.Contracts.Parliament;

public static class ParliamentConstants
{
public const int MaxLengthForTitle = 255;
public const int MaxLengthForDescription = 10200;
public const int MaxLengthForProposalDescriptionUrl = 255;
}
23 changes: 21 additions & 2 deletions contract/AElf.Contracts.Parliament/Parliament_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private Hash GenerateProposalId(CreateProposalInput input)

private Hash CreateNewProposal(CreateProposalInput input)
{
CheckCreateProposalInput(input);
var proposalId = GenerateProposalId(input);
var proposal = new ProposalInfo
{
Expand All @@ -234,15 +235,33 @@ private Hash CreateNewProposal(CreateProposalInput input)
OrganizationAddress = input.OrganizationAddress,
ProposalId = proposalId,
Proposer = Context.Sender,
ProposalDescriptionUrl = input.ProposalDescriptionUrl
ProposalDescriptionUrl = input.ProposalDescriptionUrl,
Title = input.Title,
Description = input.Description
};
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 });
{
ProposalId = proposalId,
OrganizationAddress = input.OrganizationAddress,
Title = input.Title,
Description = input.Description
});
return proposalId;
}

private void CheckCreateProposalInput(CreateProposalInput input)
{
// Check the length of title
Assert(input.Title.Length <= ParliamentConstants.MaxLengthForTitle, "Title is too long.");
// Check the length of description
Assert(input.Description.Length <= ParliamentConstants.MaxLengthForDescription, "Description is too long.");
// Check the length of description url
Assert(input.ProposalDescriptionUrl.Length <= ParliamentConstants.MaxLengthForProposalDescriptionUrl,
"Description url is too long.");
}

private Address CreateNewOrganization(CreateOrganizationInput input)
{
Expand Down
4 changes: 3 additions & 1 deletion contract/AElf.Contracts.Referendum/Referendum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ public override ProposalOutput GetProposal(Hash proposalId)
ToBeReleased = readyToRelease,
ApprovalCount = proposal.ApprovalCount,
RejectionCount = proposal.RejectionCount,
AbstentionCount = proposal.AbstentionCount
AbstentionCount = proposal.AbstentionCount,
Title = proposal.Title,
Description = proposal.Description
};
}

Expand Down
8 changes: 8 additions & 0 deletions contract/AElf.Contracts.Referendum/ReferendumConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AElf.Contracts.Referendum;

public static class ReferendumConstants
{
public const int MaxLengthForTitle = 255;
public const int MaxLengthForDescription = 10200;
public const int MaxLengthForProposalDescriptionUrl = 255;
}
24 changes: 22 additions & 2 deletions contract/AElf.Contracts.Referendum/Referendum_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ private Hash GenerateProposalId(CreateProposalInput input)

private Hash CreateNewProposal(CreateProposalInput input)
{
CheckCreateProposalInput(input);
var proposalId = GenerateProposalId(input);
Assert(State.Proposals[proposalId] == null, "Proposal already exists.");
var proposal = new ProposalInfo
Expand All @@ -168,14 +169,33 @@ private Hash CreateNewProposal(CreateProposalInput input)
Params = input.Params,
OrganizationAddress = input.OrganizationAddress,
Proposer = Context.Sender,
ProposalDescriptionUrl = input.ProposalDescriptionUrl
ProposalDescriptionUrl = input.ProposalDescriptionUrl,
Title = input.Title,
Description = input.Description
};
Assert(Validate(proposal), "Invalid proposal.");
State.Proposals[proposalId] = proposal;
Context.Fire(new ProposalCreated { ProposalId = proposalId, OrganizationAddress = input.OrganizationAddress });
Context.Fire(new ProposalCreated
{
ProposalId = proposalId,
OrganizationAddress = input.OrganizationAddress,
Title = input.Title,
Description = input.Description
});

return proposalId;
}

private void CheckCreateProposalInput(CreateProposalInput input)
{
// Check the length of title
Assert(input.Title.Length <= ReferendumConstants.MaxLengthForTitle, "Title is too long.");
// Check the length of description
Assert(input.Description.Length <= ReferendumConstants.MaxLengthForDescription, "Description is too long.");
// Check the length of description url
Assert(input.ProposalDescriptionUrl.Length <= ReferendumConstants.MaxLengthForProposalDescriptionUrl,
"Description url is too long.");
}

private void AssertIsAuthorizedProposer(Address organizationAddress, Address proposer)
{
Expand Down
18 changes: 17 additions & 1 deletion protobuf/acs3.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ message CreateProposalInput {
string proposal_description_url = 6;
// The token is for proposal id generation and with this token, proposal id can be calculated before proposing.
aelf.Hash token = 7;
// Title of this proposal.
string title = 8;
// Description of this proposal.
string description = 9;
}

message ProposalOutput {
Expand All @@ -115,6 +119,10 @@ message ProposalOutput {
int64 rejection_count = 10;
// Abstention count for this proposal.
int64 abstention_count = 11;
// Title of this proposal.
string title = 12;
// Description of this proposal.
string description = 13;
}

message ProposalReleaseThreshold {
Expand Down Expand Up @@ -159,7 +167,11 @@ message ProposalCreated{
// The id of the created proposal.
aelf.Hash proposal_id = 1;
// The organization address of the created proposal.
aelf.Address organization_address=2 [(aelf.is_indexed) = true];
aelf.Address organization_address = 2 [(aelf.is_indexed) = true];
// Title of this proposal.
string title = 3;
// Description of this proposal.
string description = 4;
}

message ProposalReleased{
Expand All @@ -168,6 +180,10 @@ message ProposalReleased{
aelf.Hash proposal_id = 1;
// The organization address of the released proposal.
aelf.Address organization_address=2 [(aelf.is_indexed) = true];
// Title of this proposal.
string title = 3;
// Description of this proposal.
string description = 4;
}

message OrganizationCreated{
Expand Down
4 changes: 4 additions & 0 deletions protobuf/association_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ message ProposalInfo {
repeated aelf.Address abstentions = 10;
// Url is used for proposal describing.
string proposal_description_url = 11;
// Title of this proposal.
string title = 12;
// Description of this proposal.
string description = 13;
}

message OrganizationMemberList {
Expand Down
4 changes: 4 additions & 0 deletions protobuf/parliament_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ message ProposalInfo {
repeated aelf.Address abstentions = 10;
// Url is used for proposal describing.
string proposal_description_url = 11;
// Title of this proposal.
string title = 12;
// Description of this proposal.
string description = 13;
}

message InitializeInput{
Expand Down
4 changes: 4 additions & 0 deletions protobuf/referendum_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ message ProposalInfo {
int64 abstention_count = 10;
// Url is used for proposal describing.
string proposal_description_url = 11;
// Title of this proposal.
string title = 12;
// Description of this proposal.
string description = 13;
}

message CreateOrganizationBySystemContractInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public async Task Get_Proposal_Test()
getProposal.Output.OrganizationAddress.ShouldBe(organizationAddress);
getProposal.Output.ToAddress.ShouldBe(TokenContractAddress);
getProposal.Output.Params.ShouldBe(transferInput.ToByteString());
getProposal.Output.Title.ShouldNotBeNullOrEmpty();
getProposal.Output.Description.ShouldNotBeNullOrEmpty();
}
}

Expand Down Expand Up @@ -1231,7 +1233,9 @@ private async Task<Hash> CreateProposalAsync(ECKeyPair proposalKeyPair, Address
ToAddress = TokenContractAddress,
Params = transferInput.ToByteString(),
ExpiredTime = BlockTimeProvider.GetBlockTime().AddDays(2),
OrganizationAddress = organizationAddress
OrganizationAddress = organizationAddress,
Title = "Token Transfer",
Description = "Transfer 100 ELF to Reviewer1's address",
};
var proposal = await associationContractStub.CreateProposal.SendAsync(createProposalInput);
var proposalCreated = ProposalCreated.Parser.ParseFrom(proposal.TransactionResult.Logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public async Task Get_Proposal_Test()
getProposal.Output.ProposalId.ShouldBe(proposalId);
getProposal.Output.OrganizationAddress.ShouldBe(organizationAddress);
getProposal.Output.ToAddress.ShouldBe(TokenContractAddress);
getProposal.Output.Title.ShouldNotBeNullOrEmpty();
getProposal.Output.Description.ShouldNotBeNullOrEmpty();

var transferParam = TransferInput.Parser.ParseFrom(getProposal.Output.Params);
transferParam.Symbol.ShouldBe(transferInput.Symbol);
Expand Down Expand Up @@ -1541,7 +1543,9 @@ private async Task<Hash> CreateProposalAsync(ECKeyPair proposalKeyPair, Address
ToAddress = TokenContractAddress,
Params = transferInput.ToByteString(),
ExpiredTime = BlockTimeProvider.GetBlockTime().AddDays(2),
OrganizationAddress = organizationAddress
OrganizationAddress = organizationAddress,
Title = "Token Transfer",
Description = "Transfer 100 ELF to Tester's address",
};
var parliamentContractStub = GetParliamentContractTester(proposalKeyPair);
var proposal = await parliamentContractStub.CreateProposal.SendAsync(createProposalInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public async Task Get_Proposal_Test()
getProposal.Output.OrganizationAddress.ShouldBe(organizationAddress);
getProposal.Output.ToAddress.ShouldBe(TokenContractAddress);
getProposal.Output.Params.ShouldBe(createInput.ToByteString());
getProposal.Output.Title.ShouldNotBeNullOrEmpty();
getProposal.Output.Description.ShouldNotBeNullOrEmpty();
}

[Fact]
Expand Down Expand Up @@ -1320,7 +1322,9 @@ private async Task<Hash> CreateProposalAsync(ECKeyPair proposalKeyPair, Address
ToAddress = TokenContractAddress,
Params = createInput.ToByteString(),
ExpiredTime = timestamp ?? BlockTimeProvider.GetBlockTime().AddSeconds(1000),
OrganizationAddress = organizationAddress
OrganizationAddress = organizationAddress,
Title = "Create token: NEW",
Description = "Create a new token named NEW."
};
ReferendumContractStub = GetReferendumContractTester(proposalKeyPair);
var proposal = await ReferendumContractStub.CreateProposal.SendAsync(createProposalInput);
Expand Down
Loading