2022-03-11 05:11:10 -08:00
|
|
|
package module_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2022-03-27 21:44:01 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
2022-03-11 05:11:10 -08:00
|
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/group"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/group/module"
|
2022-03-27 21:44:01 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-03-11 05:11:10 -08:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-03-27 21:44:01 -07:00
|
|
|
|
2022-03-11 05:11:10 -08:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
)
|
|
|
|
|
2022-03-27 21:44:01 -07:00
|
|
|
func TestEndBlockerPruning(t *testing.T) {
|
|
|
|
app := simapp.Setup(t, false)
|
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
|
|
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(30000000))
|
|
|
|
addr1 := addrs[0]
|
|
|
|
addr2 := addrs[1]
|
|
|
|
addr3 := addrs[2]
|
|
|
|
|
|
|
|
// Initial group, group policy and balance setup
|
|
|
|
members := []group.Member{
|
|
|
|
{Address: addr1.String(), Weight: "1"}, {Address: addr2.String(), Weight: "2"},
|
|
|
|
}
|
|
|
|
|
|
|
|
groupRes, err := app.GroupKeeper.CreateGroup(ctx, &group.MsgCreateGroup{
|
|
|
|
Admin: addr1.String(),
|
|
|
|
Members: members,
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
groupID := groupRes.GroupId
|
|
|
|
|
|
|
|
policy := group.NewThresholdDecisionPolicy(
|
|
|
|
"2",
|
|
|
|
time.Second,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
|
|
|
|
policyReq := &group.MsgCreateGroupPolicy{
|
|
|
|
Admin: addr1.String(),
|
|
|
|
GroupId: groupID,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = policyReq.SetDecisionPolicy(policy)
|
|
|
|
require.NoError(t, err)
|
|
|
|
policyRes, err := app.GroupKeeper.CreateGroupPolicy(ctx, policyReq)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
groupPolicyAddr, err := sdk.AccAddressFromBech32(policyRes.Address)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, testutil.FundAccount(app.BankKeeper, ctx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10000)}))
|
|
|
|
|
|
|
|
msgSend1 := &banktypes.MsgSend{
|
|
|
|
FromAddress: groupPolicyAddr.String(),
|
|
|
|
ToAddress: addr2.String(),
|
|
|
|
Amount: sdk.Coins{sdk.NewInt64Coin("test", 100)},
|
|
|
|
}
|
|
|
|
proposers := []string{addr2.String()}
|
|
|
|
|
|
|
|
specs := map[string]struct {
|
|
|
|
srcBlockTime time.Time
|
|
|
|
setupProposal func(ctx context.Context) uint64
|
|
|
|
expErr bool
|
|
|
|
expErrMsg string
|
|
|
|
expExecutorResult group.ProposalExecutorResult
|
|
|
|
}{
|
|
|
|
"proposal pruned after executor result success": {
|
|
|
|
setupProposal: func(ctx context.Context) uint64 {
|
|
|
|
msgs := []sdk.Msg{msgSend1}
|
|
|
|
pID, err := submitProposalAndVote(app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
|
|
|
|
require.NoError(t, err)
|
2022-04-06 04:16:23 -07:00
|
|
|
_, err = app.GroupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
|
2022-03-27 21:44:01 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
|
|
|
require.NoError(t, testutil.FundAccount(app.BankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
|
|
|
|
|
|
|
|
return pID
|
|
|
|
},
|
|
|
|
expErrMsg: "load proposal: not found",
|
|
|
|
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_SUCCESS,
|
|
|
|
},
|
|
|
|
"proposal with multiple messages pruned when executed with result success": {
|
|
|
|
setupProposal: func(ctx context.Context) uint64 {
|
|
|
|
msgs := []sdk.Msg{msgSend1, msgSend1}
|
|
|
|
pID, err := submitProposalAndVote(app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
|
|
|
|
require.NoError(t, err)
|
2022-04-06 04:16:23 -07:00
|
|
|
_, err = app.GroupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
|
2022-03-27 21:44:01 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
|
|
|
require.NoError(t, testutil.FundAccount(app.BankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
|
|
|
|
|
|
|
|
return pID
|
|
|
|
},
|
|
|
|
expErrMsg: "load proposal: not found",
|
|
|
|
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_SUCCESS,
|
|
|
|
},
|
|
|
|
"proposal not pruned when not executed and rejected": {
|
|
|
|
setupProposal: func(ctx context.Context) uint64 {
|
|
|
|
msgs := []sdk.Msg{msgSend1}
|
|
|
|
pID, err := submitProposalAndVote(app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_NO)
|
|
|
|
require.NoError(t, err)
|
2022-04-06 04:16:23 -07:00
|
|
|
_, err = app.GroupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
|
2022-03-27 21:44:01 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
|
|
|
require.NoError(t, testutil.FundAccount(app.BankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
|
|
|
|
|
|
|
|
return pID
|
|
|
|
},
|
|
|
|
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_NOT_RUN,
|
|
|
|
},
|
|
|
|
"open proposal is not pruned which must not fail ": {
|
|
|
|
setupProposal: func(ctx context.Context) uint64 {
|
|
|
|
pID, err := submitProposal(app, ctx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
|
|
|
|
require.NoError(t, err)
|
2022-04-06 04:16:23 -07:00
|
|
|
_, err = app.GroupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
|
2022-03-27 21:44:01 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
|
|
|
require.NoError(t, testutil.FundAccount(app.BankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
|
|
|
|
|
|
|
|
return pID
|
|
|
|
},
|
|
|
|
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_NOT_RUN,
|
|
|
|
},
|
|
|
|
"proposal not pruned with group policy modified before tally": {
|
|
|
|
setupProposal: func(ctx context.Context) uint64 {
|
|
|
|
pID, err := submitProposal(app, ctx, []sdk.Msg{msgSend1}, proposers, groupPolicyAddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = app.GroupKeeper.UpdateGroupPolicyMetadata(ctx, &group.MsgUpdateGroupPolicyMetadata{
|
2022-04-06 04:16:23 -07:00
|
|
|
Admin: addr1.String(),
|
|
|
|
GroupPolicyAddress: groupPolicyAddr.String(),
|
2022-03-27 21:44:01 -07:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2022-04-06 04:16:23 -07:00
|
|
|
_, err = app.GroupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
|
2022-03-27 21:44:01 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
|
|
|
require.NoError(t, testutil.FundAccount(app.BankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
|
|
|
|
|
|
|
|
return pID
|
|
|
|
},
|
|
|
|
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_NOT_RUN,
|
|
|
|
},
|
|
|
|
"pruned when proposal is executable when failed before": {
|
|
|
|
setupProposal: func(ctx context.Context) uint64 {
|
|
|
|
msgs := []sdk.Msg{msgSend1}
|
|
|
|
pID, err := submitProposalAndVote(app, ctx, msgs, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
|
|
|
|
require.NoError(t, err)
|
2022-04-06 04:16:23 -07:00
|
|
|
_, err = app.GroupKeeper.Exec(ctx, &group.MsgExec{Executor: addrs[2].String(), ProposalId: pID})
|
2022-03-27 21:44:01 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
return pID
|
|
|
|
},
|
|
|
|
expErrMsg: "load proposal: not found",
|
|
|
|
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_SUCCESS,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for msg, spec := range specs {
|
|
|
|
spec := spec
|
|
|
|
t.Run(msg, func(t *testing.T) {
|
|
|
|
proposalID := spec.setupProposal(ctx)
|
|
|
|
|
|
|
|
module.EndBlocker(ctx, app.GroupKeeper)
|
|
|
|
|
|
|
|
if spec.expExecutorResult == group.PROPOSAL_EXECUTOR_RESULT_SUCCESS {
|
|
|
|
// Make sure proposal is deleted from state
|
|
|
|
_, err = app.GroupKeeper.Proposal(ctx, &group.QueryProposalRequest{ProposalId: proposalID})
|
|
|
|
require.Contains(t, err.Error(), spec.expErrMsg)
|
|
|
|
res, err := app.GroupKeeper.VotesByProposal(ctx, &group.QueryVotesByProposalRequest{ProposalId: proposalID})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, res.GetVotes())
|
|
|
|
} else {
|
|
|
|
// Check that proposal and votes exists
|
|
|
|
res, err := app.GroupKeeper.Proposal(ctx, &group.QueryProposalRequest{ProposalId: proposalID})
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = app.GroupKeeper.VotesByProposal(ctx, &group.QueryVotesByProposalRequest{ProposalId: res.Proposal.Id})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "", spec.expErrMsg)
|
|
|
|
|
|
|
|
exp := group.ProposalExecutorResult_name[int32(spec.expExecutorResult)]
|
|
|
|
got := group.ProposalExecutorResult_name[int32(res.Proposal.ExecutorResult)]
|
|
|
|
assert.Equal(t, exp, got)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-11 05:11:10 -08:00
|
|
|
func TestEndBlocker(t *testing.T) {
|
|
|
|
app := simapp.Setup(t, false)
|
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2022-03-27 21:44:01 -07:00
|
|
|
|
|
|
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 4, sdk.NewInt(30000000))
|
2022-03-11 05:11:10 -08:00
|
|
|
|
|
|
|
// Initial group, group policy and balance setup
|
|
|
|
members := []group.Member{
|
|
|
|
{Address: addrs[1].String(), Weight: "1"}, {Address: addrs[2].String(), Weight: "2"},
|
|
|
|
}
|
|
|
|
|
|
|
|
groupRes, err := app.GroupKeeper.CreateGroup(ctx, &group.MsgCreateGroup{
|
|
|
|
Admin: addrs[0].String(),
|
|
|
|
Members: members,
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
groupID := groupRes.GroupId
|
|
|
|
|
|
|
|
policy := group.NewThresholdDecisionPolicy(
|
|
|
|
"2",
|
|
|
|
time.Second,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
|
|
|
|
policyReq := &group.MsgCreateGroupPolicy{
|
|
|
|
Admin: addrs[0].String(),
|
|
|
|
GroupId: groupID,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = policyReq.SetDecisionPolicy(policy)
|
|
|
|
require.NoError(t, err)
|
|
|
|
policyRes, err := app.GroupKeeper.CreateGroupPolicy(ctx, policyReq)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-27 21:44:01 -07:00
|
|
|
groupPolicyAddr, err := sdk.AccAddressFromBech32(policyRes.Address)
|
2022-03-11 05:11:10 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
votingPeriod := policy.GetVotingPeriod()
|
|
|
|
|
|
|
|
msgSend := &banktypes.MsgSend{
|
|
|
|
FromAddress: groupPolicyAddr.String(),
|
|
|
|
ToAddress: addrs[3].String(),
|
2022-03-27 21:44:01 -07:00
|
|
|
Amount: sdk.Coins{sdk.NewInt64Coin("test", 100)},
|
2022-03-11 05:11:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
proposers := []string{addrs[2].String()}
|
|
|
|
|
|
|
|
specs := map[string]struct {
|
2022-04-06 04:16:23 -07:00
|
|
|
preRun func(sdkCtx sdk.Context) uint64
|
|
|
|
proposalId uint64
|
|
|
|
admin string
|
|
|
|
expErrMsg string
|
|
|
|
newCtx sdk.Context
|
|
|
|
tallyRes group.TallyResult
|
|
|
|
expStatus group.ProposalStatus
|
2022-03-11 05:11:10 -08:00
|
|
|
}{
|
|
|
|
"tally updated after voting power end": {
|
2022-03-27 21:44:01 -07:00
|
|
|
preRun: func(sdkCtx sdk.Context) uint64 {
|
|
|
|
pId, err := submitProposal(app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
|
2022-03-11 05:11:10 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
return pId
|
|
|
|
},
|
2022-04-06 04:16:23 -07:00
|
|
|
admin: proposers[0],
|
|
|
|
newCtx: ctx.WithBlockTime(ctx.BlockTime().Add(votingPeriod).Add(time.Hour)),
|
|
|
|
tallyRes: group.DefaultTallyResult(),
|
|
|
|
expStatus: group.PROPOSAL_STATUS_SUBMITTED,
|
2022-03-11 05:11:10 -08:00
|
|
|
},
|
|
|
|
"tally within voting period": {
|
2022-03-27 21:44:01 -07:00
|
|
|
preRun: func(sdkCtx sdk.Context) uint64 {
|
|
|
|
pId, err := submitProposal(app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
|
2022-03-11 05:11:10 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return pId
|
|
|
|
},
|
2022-04-06 04:16:23 -07:00
|
|
|
admin: proposers[0],
|
|
|
|
newCtx: ctx,
|
|
|
|
tallyRes: group.DefaultTallyResult(),
|
|
|
|
expStatus: group.PROPOSAL_STATUS_SUBMITTED,
|
2022-03-11 05:11:10 -08:00
|
|
|
},
|
|
|
|
"tally within voting period(with votes)": {
|
2022-03-27 21:44:01 -07:00
|
|
|
preRun: func(sdkCtx sdk.Context) uint64 {
|
|
|
|
pId, err := submitProposalAndVote(app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
|
2022-03-11 05:11:10 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return pId
|
|
|
|
},
|
2022-04-06 04:16:23 -07:00
|
|
|
admin: proposers[0],
|
|
|
|
newCtx: ctx,
|
|
|
|
tallyRes: group.DefaultTallyResult(),
|
|
|
|
expStatus: group.PROPOSAL_STATUS_SUBMITTED,
|
2022-03-11 05:11:10 -08:00
|
|
|
},
|
|
|
|
"tally after voting period(with votes)": {
|
2022-03-27 21:44:01 -07:00
|
|
|
preRun: func(sdkCtx sdk.Context) uint64 {
|
|
|
|
pId, err := submitProposalAndVote(app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
|
2022-03-11 05:11:10 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return pId
|
|
|
|
},
|
|
|
|
admin: proposers[0],
|
2022-03-27 21:44:01 -07:00
|
|
|
newCtx: ctx.WithBlockTime(ctx.BlockTime().Add(votingPeriod).Add(time.Hour)),
|
2022-03-11 05:11:10 -08:00
|
|
|
tallyRes: group.TallyResult{
|
|
|
|
YesCount: "2",
|
|
|
|
NoCount: "0",
|
|
|
|
NoWithVetoCount: "0",
|
|
|
|
AbstainCount: "0",
|
|
|
|
},
|
2022-04-06 04:16:23 -07:00
|
|
|
expStatus: group.PROPOSAL_STATUS_ACCEPTED,
|
2022-03-11 05:11:10 -08:00
|
|
|
},
|
|
|
|
"tally of closed proposal": {
|
2022-03-27 21:44:01 -07:00
|
|
|
preRun: func(sdkCtx sdk.Context) uint64 {
|
|
|
|
pId, err := submitProposal(app, sdkCtx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr)
|
2022-03-11 05:11:10 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = app.GroupKeeper.WithdrawProposal(ctx, &group.MsgWithdrawProposal{
|
|
|
|
ProposalId: pId,
|
|
|
|
Address: groupPolicyAddr.String(),
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
return pId
|
|
|
|
},
|
2022-04-06 04:16:23 -07:00
|
|
|
admin: proposers[0],
|
|
|
|
newCtx: ctx,
|
|
|
|
tallyRes: group.DefaultTallyResult(),
|
|
|
|
expStatus: group.PROPOSAL_STATUS_WITHDRAWN,
|
2022-03-11 05:11:10 -08:00
|
|
|
},
|
|
|
|
"tally of closed proposal (with votes)": {
|
2022-03-27 21:44:01 -07:00
|
|
|
preRun: func(sdkCtx sdk.Context) uint64 {
|
|
|
|
pId, err := submitProposalAndVote(app, ctx, []sdk.Msg{msgSend}, proposers, groupPolicyAddr, group.VOTE_OPTION_YES)
|
2022-03-11 05:11:10 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = app.GroupKeeper.WithdrawProposal(ctx, &group.MsgWithdrawProposal{
|
|
|
|
ProposalId: pId,
|
|
|
|
Address: groupPolicyAddr.String(),
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
return pId
|
|
|
|
},
|
2022-04-06 04:16:23 -07:00
|
|
|
admin: proposers[0],
|
|
|
|
newCtx: ctx,
|
|
|
|
tallyRes: group.DefaultTallyResult(),
|
|
|
|
expStatus: group.PROPOSAL_STATUS_WITHDRAWN,
|
2022-03-11 05:11:10 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for msg, spec := range specs {
|
|
|
|
t.Run(msg, func(t *testing.T) {
|
|
|
|
spec := spec
|
|
|
|
pId := spec.preRun(ctx)
|
|
|
|
|
|
|
|
module.EndBlocker(spec.newCtx, app.GroupKeeper)
|
|
|
|
resp, err := app.GroupKeeper.Proposal(spec.newCtx, &group.QueryProposalRequest{
|
|
|
|
ProposalId: pId,
|
|
|
|
})
|
|
|
|
|
|
|
|
if spec.expErrMsg != "" {
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), spec.expErrMsg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, resp.GetProposal().FinalTallyResult, spec.tallyRes)
|
|
|
|
require.Equal(t, resp.GetProposal().Status, spec.expStatus)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func submitProposal(
|
2022-03-27 21:44:01 -07:00
|
|
|
app *simapp.SimApp, ctx context.Context, msgs []sdk.Msg,
|
|
|
|
proposers []string, groupPolicyAddr sdk.AccAddress) (uint64, error) {
|
2022-03-11 05:11:10 -08:00
|
|
|
proposalReq := &group.MsgSubmitProposal{
|
2022-04-06 04:16:23 -07:00
|
|
|
GroupPolicyAddress: groupPolicyAddr.String(),
|
|
|
|
Proposers: proposers,
|
2022-03-11 05:11:10 -08:00
|
|
|
}
|
|
|
|
err := proposalReq.SetMsgs(msgs)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
proposalRes, err := app.GroupKeeper.SubmitProposal(ctx, proposalReq)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return proposalRes.ProposalId, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func submitProposalAndVote(
|
2022-03-27 21:44:01 -07:00
|
|
|
app *simapp.SimApp, ctx context.Context, msgs []sdk.Msg,
|
|
|
|
proposers []string, groupPolicyAddr sdk.AccAddress, voteOption group.VoteOption) (uint64, error) {
|
2022-03-11 05:11:10 -08:00
|
|
|
myProposalID, err := submitProposal(app, ctx, msgs, proposers, groupPolicyAddr)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
_, err = app.GroupKeeper.Vote(ctx, &group.MsgVote{
|
|
|
|
ProposalId: myProposalID,
|
|
|
|
Voter: proposers[0],
|
|
|
|
Option: voteOption,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return myProposalID, nil
|
|
|
|
}
|