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

ci: add gov module to interchaintest folder #3408

Merged
merged 3 commits into from
Dec 9, 2024

Conversation

dasanchez
Copy link
Contributor

@dasanchez dasanchez commented Nov 8, 2024

Description

Adds gov module tests to delegator folder:

  • Proposal submission
  • Proposal deposits
  • Proposal vote
  • Proposal weighted vote
  • Gov module param change
  • Messages from gov module account

Successful workflow run:
https://github.com/cosmos/gaia/actions/runs/11732771239


Author Checklist

I have...

  • Included the correct type prefix in the PR title
  • Targeted the correct branch (see PR Targeting)
  • Provided a link to the relevant issue or specification
  • Reviewed "Files changed" and left comments if necessary
  • Confirmed all CI checks have passed

Reviewers Checklist

I have...

  • Confirmed the correct type prefix in the PR title
  • Confirmed all author checklist items have been addressed
  • Confirmed that this PR does not change production code

@dasanchez dasanchez marked this pull request as ready for review November 8, 2024 15:28
Copy link
Contributor

@fastfadingviolets fastfadingviolets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd like to be able to run the test funcs independently of one another. So the order shouldn't matter that much. I suggest consolidating the ones that all use the same proposal into one function and then removing the number indicator from the other ones. This way there's no global state or anything, and the tests are independent.

Comment on lines 65 to 161
func (s *GovSuite) Test01SubmitProposal() {
delegatorAddress, err := s.Chain.GetAddress(s.GetContext(), delegatorName)
s.Require().NoError(err)
delegatorAddressString := types.MustBech32ifyAddressBytes("cosmos", delegatorAddress)

// Submit proposal
prop, err := s.Chain.BuildProposal(nil, "Test Proposal", "Test Proposal", "ipfs://CID", submissionDeposit+"uatom", delegatorAddressString, false)
s.Require().NoError(err)
result, err := s.Chain.SubmitProposal(s.GetContext(), delegatorName, prop)
s.Require().NoError(err)
proposalId = result.ProposalID

// Get status
proposalIDuint, err := strconv.ParseUint(proposalId, 10, 64)
proposal, err := s.Chain.GovQueryProposalV1(s.GetContext(), proposalIDuint)
s.Require().NoError(err)
currentStatus := proposal.Status.String()

// Test
s.Require().NotEqual("0", proposalId)
s.Require().Equal("PROPOSAL_STATUS_DEPOSIT_PERIOD", currentStatus)
}

func (s *GovSuite) Test02ProposalDeposit() {
node := s.Chain.GetNode()
delegatorAddress, err := s.Chain.GetAddress(s.GetContext(), delegatorName)
s.Require().NoError(err)
delegatorAddressString := types.MustBech32ifyAddressBytes("cosmos", delegatorAddress)
proposalDeposit := strconv.Itoa(proposalDepositInt)

// Submit deposit to proposal
_, err = node.ExecTx(s.GetContext(), delegatorName, "gov", "deposit", proposalId, proposalDeposit+"uatom", "--gas", "auto")
s.Require().NoError(err)
proposalIDuint, err := strconv.ParseUint(proposalId, 10, 64)
proposal, err := s.Chain.GovQueryProposalV1(s.GetContext(), proposalIDuint)
s.Require().NoError(err)
currentStatus := proposal.Status.String()

submissionDepositUint, err := strconv.ParseUint(submissionDeposit, 10, 64)
s.Require().NoError(err)
depositTotal := chainsuite.GovMinDepositAmount + submissionDepositUint
fmt.Println("Deposit total: ", depositTotal)

// Test
deposit, err := s.Chain.QueryJSON(s.GetContext(), "deposit", "gov", "deposit", proposalId, delegatorAddressString)
s.Require().NoError(err)
depositAmount := deposit.Get("amount.#(denom==\"uatom\").amount").String()
depositAmountUint, err := strconv.ParseUint(depositAmount, 10, 64)
s.Require().NoError(err)
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("Query amount: %d", depositAmountUint)
s.Require().Equal("PROPOSAL_STATUS_VOTING_PERIOD", currentStatus)
s.Require().Equal(depositTotal, depositAmountUint)
}

func (s *GovSuite) Test03ProposalVote() {
node := s.Chain.GetNode()
delegatorAddress, err := s.Chain.GetAddress(s.GetContext(), delegatorName)
s.Require().NoError(err)
delegatorAddressString := types.MustBech32ifyAddressBytes("cosmos", delegatorAddress)
// Vote yes on proposal
_, err = node.ExecTx(s.GetContext(), delegatorName, "gov", "vote", proposalId, "yes", "--gas", "auto")
s.Require().NoError(err)

// Test
vote, err := s.Chain.QueryJSON(s.GetContext(), "vote", "gov", "vote", proposalId, delegatorAddressString)
s.Require().NoError(err)
actual_yes_weight := vote.Get("options.#(option==\"VOTE_OPTION_YES\").weight")
chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_yes_weight.String())
s.Require().Equal(float64(1.0), actual_yes_weight.Float())
}

func (s *GovSuite) Test04ProposalWeightedVote() {
node := s.Chain.GetNode()
delegatorAddress, err := s.Chain.GetAddress(s.GetContext(), delegatorName)
s.Require().NoError(err)
delegatorAddressString := types.MustBech32ifyAddressBytes("cosmos", delegatorAddress)
// Submit weighted vote to proposal
_, err = node.ExecTx(s.GetContext(), delegatorName, "gov", "weighted-vote", proposalId, fmt.Sprintf("yes=%0.2f,no=%0.2f,abstain=%0.2f,no_with_veto=%0.2f", yesWeight, noWeight, abstainWeight, vetoWeight), "--gas", "auto")
s.Require().NoError(err)

// Test
vote, err := s.Chain.QueryJSON(s.GetContext(), "vote", "gov", "vote", proposalId, delegatorAddressString)
s.Require().NoError(err)
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", vote)
actual_yes_weight := vote.Get("options.#(option==\"VOTE_OPTION_YES\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_yes_weight.String())
s.Require().Equal(float64(yesWeight), actual_yes_weight.Float())
actual_no_weight := vote.Get("options.#(option==\"VOTE_OPTION_NO\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_no_weight.String())
s.Require().Equal(float64(noWeight), actual_no_weight.Float())
actual_abstain_weight := vote.Get("options.#(option==\"VOTE_OPTION_ABSTAIN\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_abstain_weight.String())
s.Require().Equal(float64(abstainWeight), actual_abstain_weight.Float())
actual_veto_weight := vote.Get("options.#(option==\"VOTE_OPTION_NO_WITH_VETO\").weight")
// chainsuite.GetLogger(s.GetContext()).Sugar().Infof("%s", actual_veto_weight.String())
s.Require().Equal(float64(vetoWeight), actual_veto_weight.Float())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these are the ones that use the proposal you submitted in Test01 right? I'd suggest gathering all of them together into one test func and then using s.Run() to split up the individual stories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fastfadingviolets ! I decoupled all tests.

@dasanchez
Copy link
Contributor Author

Successful workflow run:
https://github.com/cosmos/gaia/actions/runs/11829964071

@fastfadingviolets fastfadingviolets self-requested a review November 14, 2024 15:50
@MSalopek MSalopek merged commit 83f74f2 into main Dec 9, 2024
18 checks passed
@MSalopek MSalopek deleted the interchaintest/delegator-gov branch December 9, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants