-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gov): handle panics when executing x/gov proposals (backport #17780
) (#17790) Co-authored-by: Robert Zaremba <robert@zaremba.ch> Co-authored-by: Julien Robert <julien@rbrt.fr>
- Loading branch information
1 parent
2196eda
commit 87ba5a6
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package gov | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func failingHandler(_ sdk.Context, _ sdk.Msg) (*sdk.Result, error) { | ||
panic("test-fail") | ||
} | ||
|
||
func okHandler(_ sdk.Context, _ sdk.Msg) (*sdk.Result, error) { | ||
return new(sdk.Result), nil | ||
} | ||
|
||
func TestSafeExecuteHandler(t *testing.T) { | ||
t.Parallel() | ||
|
||
require := require.New(t) | ||
var ctx sdk.Context | ||
|
||
r, err := safeExecuteHandler(ctx, nil, failingHandler) | ||
require.ErrorContains(err, "test-fail") | ||
require.Nil(r) | ||
|
||
r, err = safeExecuteHandler(ctx, nil, okHandler) | ||
require.Nil(err) | ||
require.NotNil(r) | ||
} |