From 3dbd5dfe2a123e7b4a6c94a075a2d83b7a9620a8 Mon Sep 17 00:00:00 2001 From: eanzhao Date: Mon, 1 Jul 2024 11:05:39 +0800 Subject: [PATCH] Fix judgements and add tests --- contract/AElf.Contracts.Association/Association_Helper.cs | 2 +- contract/AElf.Contracts.Parliament/Parliament_Helper.cs | 2 +- contract/AElf.Contracts.Referendum/Referendum_Helper.cs | 2 +- .../ParliamentContractTest.cs | 6 +++++- .../ReferendumContractTest.cs | 6 +++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/contract/AElf.Contracts.Association/Association_Helper.cs b/contract/AElf.Contracts.Association/Association_Helper.cs index 5436ccb48c..cc1a7d0643 100644 --- a/contract/AElf.Contracts.Association/Association_Helper.cs +++ b/contract/AElf.Contracts.Association/Association_Helper.cs @@ -177,7 +177,7 @@ 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.Title.Length <= AssociationConstants.MaxLengthForDescription, "Description is too long."); + 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."); diff --git a/contract/AElf.Contracts.Parliament/Parliament_Helper.cs b/contract/AElf.Contracts.Parliament/Parliament_Helper.cs index 18122b53ce..b1317eceb2 100644 --- a/contract/AElf.Contracts.Parliament/Parliament_Helper.cs +++ b/contract/AElf.Contracts.Parliament/Parliament_Helper.cs @@ -257,7 +257,7 @@ 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.Title.Length <= ParliamentConstants.MaxLengthForDescription, "Description is too long."); + 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."); diff --git a/contract/AElf.Contracts.Referendum/Referendum_Helper.cs b/contract/AElf.Contracts.Referendum/Referendum_Helper.cs index e764654621..9b6e4343d9 100644 --- a/contract/AElf.Contracts.Referendum/Referendum_Helper.cs +++ b/contract/AElf.Contracts.Referendum/Referendum_Helper.cs @@ -191,7 +191,7 @@ 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.Title.Length <= ReferendumConstants.MaxLengthForDescription, "Description is too long."); + 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."); diff --git a/test/AElf.Contracts.Parliament.Tests/ParliamentContractTest.cs b/test/AElf.Contracts.Parliament.Tests/ParliamentContractTest.cs index 5a82089232..caeb34f557 100644 --- a/test/AElf.Contracts.Parliament.Tests/ParliamentContractTest.cs +++ b/test/AElf.Contracts.Parliament.Tests/ParliamentContractTest.cs @@ -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); @@ -1541,7 +1543,9 @@ private async Task 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); diff --git a/test/AElf.Contracts.Referendum.Tests/ReferendumContractTest.cs b/test/AElf.Contracts.Referendum.Tests/ReferendumContractTest.cs index d22a250401..81dd45896c 100644 --- a/test/AElf.Contracts.Referendum.Tests/ReferendumContractTest.cs +++ b/test/AElf.Contracts.Referendum.Tests/ReferendumContractTest.cs @@ -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] @@ -1320,7 +1322,9 @@ private async Task 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);