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

x/gov client deposits tests are wrong #11936

Closed
4 tasks
facundomedica opened this issue May 11, 2022 · 1 comment · Fixed by #11940
Closed
4 tasks

x/gov client deposits tests are wrong #11936

facundomedica opened this issue May 11, 2022 · 1 comment · Fixed by #11940

Comments

@facundomedica
Copy link
Member

Summary

While debugging #11926 (from #9010) I realized that the entire file (might) contain tests that don't test what they say. I'll explain below and wait for comments to see if this requires fixing.

TL;DR These tests are querying for deposits supposedly after waiting for the voting period to pass. This should not be possible (deposits are not queryable after this period) and these tests require some fixing.

TestQueryDepositsWithoutInitialDeposit is supposedly waiting for the voting period to end but then goes and queries the deposits. This means that both the "wait for voting period to end" and the subsequent query are wrong. This can be proven by adding a bigger delay between the deposit and the query: we get an error saying that the deposit doesn't exist.

func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx
proposalID := s.proposalIDs[0]
// deposit amount
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()
_, err := MsgDeposit(clientCtx, val.Address.String(), proposalID, depositAmount)
s.Require().NoError(err)
// waiting for voting period to end
_, err = s.network.WaitForHeight(2)
s.Require().NoError(err)
// query deposit
deposit := s.queryDeposit(val, proposalID, false, "")
s.Require().NotNil(deposit)
s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount)

TestRejectedProposalDeposits is the test that was flagged as flaky in #9010. The name implies that it queries the deposits from an already rejected proposal; if that's true then we should get exactly 0 deposits. But the test code does the opposite and expects to get the deposits list.

This one (TestQueryProposalNotEnoughDeposits) is actually getting it right:

// waiting for deposit period to end
time.Sleep(20 * time.Second)
// query proposal
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
s.Require().Error(err)
s.Require().Contains(err.Error(), fmt.Sprintf("proposal %s doesn't exist", proposalID))

cc: @AmauryM


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@facundomedica
Copy link
Member Author

After talking with @alexanderbez I'm sure that deposits always get deleted once the proposal ends.

cosmos-sdk/x/gov/abci.go

Lines 52 to 56 in 1715693

if burnDeposits {
keeper.DeleteAndBurnDeposits(ctx, proposal.Id)
} else {
keeper.RefundAndDeleteDeposits(ctx, proposal.Id)
}

So I'll open a new PR removing the bad tests and hopefully adding a new one

@facundomedica facundomedica changed the title x/gov client deposits tests might be wrong x/gov client deposits tests are wrong May 11, 2022
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 a pull request may close this issue.

1 participant