feat(group): add test for keeper and cli (#11679)

## Description

Closes: #XXXX



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Jeancarlo Barrios 2022-05-09 08:43:03 -06:00 committed by GitHub
parent ead6e6f948
commit 324da02ba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 520 additions and 229 deletions

View File

@ -47,7 +47,6 @@ func MarshalJSONIndent(cdc *LegacyAmino, obj interface{}) ([]byte, error) {
if err = json.Indent(&out, bz, "", " "); err != nil { if err = json.Indent(&out, bz, "", " "); err != nil {
return nil, err return nil, err
} }
return out.Bytes(), nil return out.Bytes(), nil
} }

View File

@ -793,7 +793,7 @@ func (s *IntegrationTestSuite) TestTallyResult() {
var txResp sdk.TxResponse var txResp sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().Equal(uint32(0), txResp.Code, out.String()) s.Require().Equal(uint32(0), txResp.Code, out.String())
proposalId := s.getProposalIdFromTxResponse(txResp) proposalID := s.getProposalIDFromTxResponse(txResp)
testCases := []struct { testCases := []struct {
name string name string
@ -828,7 +828,7 @@ func (s *IntegrationTestSuite) TestTallyResult() {
{ {
"valid proposal id with no votes", "valid proposal id with no votes",
[]string{ []string{
proposalId, proposalID,
fmt.Sprintf("--%s=json", tmcli.OutputFlag), fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}, },
false, false,

File diff suppressed because it is too large Load Diff

View File

@ -2831,6 +2831,53 @@ func (s *TestSuite) TestLeaveGroup() {
} }
} }
func (s *TestSuite) TestPruneProposals() {
addrs := s.addrs
expirationTime := time.Hour * 24 * 15 // 15 days
groupID := s.groupID
accountAddr := s.groupPolicyAddr
msgSend := &banktypes.MsgSend{
FromAddress: s.groupPolicyAddr.String(),
ToAddress: addrs[0].String(),
Amount: sdk.Coins{sdk.NewInt64Coin("test", 100)},
}
policyReq := &group.MsgCreateGroupPolicy{
Admin: addrs[0].String(),
GroupId: groupID,
}
policy := group.NewThresholdDecisionPolicy("100", time.Microsecond, time.Microsecond)
err := policyReq.SetDecisionPolicy(policy)
s.Require().NoError(err)
_, err = s.keeper.CreateGroupPolicy(s.ctx, policyReq)
s.Require().NoError(err)
req := &group.MsgSubmitProposal{
GroupPolicyAddress: accountAddr.String(),
Proposers: []string{addrs[1].String()},
}
err = req.SetMsgs([]sdk.Msg{msgSend})
s.Require().NoError(err)
submittedProposal, err := s.keeper.SubmitProposal(s.ctx, req)
s.Require().NoError(err)
queryProposal := group.QueryProposalRequest{ProposalId: submittedProposal.ProposalId}
prePrune, err := s.keeper.Proposal(s.ctx, &queryProposal)
s.Require().NoError(err)
s.Require().Equal(prePrune.Proposal.Id, submittedProposal.ProposalId)
// Move Forward in time for 15 days, after voting period end + max_execution_period
s.sdkCtx = s.sdkCtx.WithBlockTime(s.sdkCtx.BlockTime().Add(expirationTime))
// Prune Expired Proposals
err = s.keeper.PruneProposals(s.sdkCtx)
s.Require().NoError(err)
postPrune, err := s.keeper.Proposal(s.ctx, &queryProposal)
s.Require().Nil(postPrune)
s.Require().Error(err)
s.Require().Contains(err.Error(), "load proposal: not found")
}
func submitProposal( func submitProposal(
ctx context.Context, s *TestSuite, msgs []sdk.Msg, ctx context.Context, s *TestSuite, msgs []sdk.Msg,
proposers []string) uint64 { proposers []string) uint64 {