Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Rename proposal executor results
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Apr 3, 2020
1 parent 04342ea commit f504f89
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 150 deletions.
8 changes: 4 additions & 4 deletions incubator/group/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,16 @@ func (k Keeper) ExecProposal(ctx sdk.Context, id ProposalID) error {
}

// execute proposal payload
if base.Status == ProposalStatusClosed && base.Result == ProposalResultAccepted && base.ExecutorResult != ProposalBase_Success {
if base.Status == ProposalStatusClosed && base.Result == ProposalResultAccepted && base.ExecutorResult != ProposalExecutorResultSuccess {
logger := ctx.Logger().With("module", fmt.Sprintf("x/%s", ModuleName))
ctx, flush := ctx.CacheContext()
_, err := doExecuteMsgs(ctx, k.router, accountMetadata.Base.GroupAccount, proposal.GetMsgs())
if err != nil {
base.ExecutorResult = ProposalBase_Failure
base.ExecutorResult = ProposalExecutorResultFailure
proposalType := reflect.TypeOf(proposal).String()
logger.Info("proposal execution failed", "cause", err, "type", proposalType, "proposalID", id)
} else {
base.ExecutorResult = ProposalBase_Success
base.ExecutorResult = ProposalExecutorResultSuccess
flush()
}
}
Expand Down Expand Up @@ -533,7 +533,7 @@ func (k Keeper) CreateProposal(ctx sdk.Context, accountAddress sdk.AccAddress, c
GroupAccountVersion: account.Base.Version,
Result: ProposalResultUndefined,
Status: ProposalStatusSubmitted,
ExecutorResult: ProposalBase_NotRun,
ExecutorResult: ProposalExecutorResultNotRun,
Timeout: *endTime,
VoteState: Tally{
YesCount: sdk.ZeroDec(),
Expand Down
26 changes: 13 additions & 13 deletions incubator/group/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultAccepted,
expExecutorResult: group.ProposalBase_Success,
expExecutorResult: group.ProposalExecutorResultSuccess,
expPayloadCounter: 1,
},
"proposal with multiple messages executed when accepted": {
Expand All @@ -677,7 +677,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultAccepted,
expExecutorResult: group.ProposalBase_Success,
expExecutorResult: group.ProposalExecutorResultSuccess,
expPayloadCounter: 2,
},
"proposal not executed when rejected": {
Expand All @@ -692,7 +692,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultRejected,
expExecutorResult: group.ProposalBase_NotRun,
expExecutorResult: group.ProposalExecutorResultNotRun,
},
"open proposal must not fail": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -705,7 +705,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusSubmitted,
expProposalResult: group.ProposalResultUndefined,
expExecutorResult: group.ProposalBase_NotRun,
expExecutorResult: group.ProposalExecutorResultNotRun,
},
"existing proposal required": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -726,7 +726,7 @@ func TestExecProposal(t *testing.T) {
srcBlockTime: blockTime.Add(time.Second),
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultRejected,
expExecutorResult: group.ProposalBase_NotRun,
expExecutorResult: group.ProposalExecutorResultNotRun,
},
"Decision policy also applied after timeout": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -741,7 +741,7 @@ func TestExecProposal(t *testing.T) {
srcBlockTime: blockTime.Add(time.Second).Add(time.Millisecond),
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultRejected,
expExecutorResult: group.ProposalBase_NotRun,
expExecutorResult: group.ProposalExecutorResultNotRun,
},
"with group modified before tally": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -759,7 +759,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusAborted,
expProposalResult: group.ProposalResultUndefined,
expExecutorResult: group.ProposalBase_NotRun,
expExecutorResult: group.ProposalExecutorResultNotRun,
},
"with group account modified before tally": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -777,7 +777,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusAborted,
expProposalResult: group.ProposalResultUndefined,
expExecutorResult: group.ProposalBase_NotRun,
expExecutorResult: group.ProposalExecutorResultNotRun,
},
"with group modified after tally": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -796,7 +796,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultAccepted,
expExecutorResult: group.ProposalBase_Failure,
expExecutorResult: group.ProposalExecutorResultFailure,
},
"with group account modified after tally": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -814,7 +814,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusAborted,
expProposalResult: group.ProposalResultUndefined,
expExecutorResult: group.ProposalBase_NotRun,
expExecutorResult: group.ProposalExecutorResultNotRun,
},
"prevent double execution when successful": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -830,7 +830,7 @@ func TestExecProposal(t *testing.T) {
expPayloadCounter: 1,
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultAccepted,
expExecutorResult: group.ProposalBase_Success,
expExecutorResult: group.ProposalExecutorResultSuccess,
},
"rollback all msg updates on failure": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -844,7 +844,7 @@ func TestExecProposal(t *testing.T) {
},
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultAccepted,
expExecutorResult: group.ProposalBase_Failure,
expExecutorResult: group.ProposalExecutorResultFailure,
},
"executable when failed before": {
setupProposal: func(t *testing.T, ctx sdk.Context) group.ProposalID {
Expand All @@ -861,7 +861,7 @@ func TestExecProposal(t *testing.T) {
expPayloadCounter: 2,
expProposalStatus: group.ProposalStatusClosed,
expProposalResult: group.ProposalResultAccepted,
expExecutorResult: group.ProposalBase_Success,
expExecutorResult: group.ProposalExecutorResultSuccess,
},
}
for msg, spec := range specs {
Expand Down
1 change: 1 addition & 0 deletions incubator/group/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func TestMsgProposeBase(t *testing.T) {
})
}
}

func TestMsgVote(t *testing.T) {
specs := map[string]struct {
src MsgVote
Expand Down
7 changes: 4 additions & 3 deletions incubator/group/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func (p ProposalBase) ValidateBasic() error {
if err := AccAddresses(p.Proposers).ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "proposers")
}

if p.SubmittedAt.Seconds == 0 && p.SubmittedAt.Nanos == 0 {
return sdkerrors.Wrap(ErrEmpty, "submitted at")
}
Expand All @@ -276,10 +275,12 @@ func (p ProposalBase) ValidateBasic() error {
if _, ok := ProposalBase_Result_name[int32(p.Result)]; !ok {
return sdkerrors.Wrap(ErrInvalid, "result")
}
if p.ExecutorResult == ProposalBase_PROPOSAL_EXECUTOR_RESULT_INVALID {
if p.ExecutorResult == ProposalExecutorResultInvalid {
return sdkerrors.Wrap(ErrEmpty, "executor result")
}

if _, ok := ProposalBase_ExecutorResult_name[int32(p.ExecutorResult)]; !ok {
return sdkerrors.Wrap(ErrInvalid, "executor result")
}
if err := p.VoteState.ValidateBasic(); err != nil {
return errors.Wrap(err, "vote state")
}
Expand Down
Loading

0 comments on commit f504f89

Please sign in to comment.