-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: sim genesis account validation (#2690)
* fix: app: make SimGenesisAccount.Validate error if .BaseAccount is nil This change ensures that an error is returned, instead of panicking, when SimGenesisAccount.BaseAccount is nil, after invoking .Validate. Found by fuzzing and added the tests in here to catch future regressions. Fixes #2586 * merge fix FuzzGenesisAccountValidate test * fix: lint --------- Co-authored-by: Emmanuel T Odeke <[email protected]> Co-authored-by: Philip Offtermatt <[email protected]>
- Loading branch information
1 parent
93cde23
commit 5e192b5
Showing
4 changed files
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package gaia | ||
|
||
import ( | ||
"runtime/debug" | ||
"testing" | ||
|
||
"github.com/google/gofuzz" | ||
) | ||
|
||
func TestFuzzGenesisAccountValidate(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("running in -short mode") | ||
} | ||
|
||
t.Parallel() | ||
|
||
acct := new(SimGenesisAccount) | ||
i := 0 | ||
defer func() { | ||
r := recover() | ||
if r == nil { | ||
return | ||
} | ||
|
||
// Otherwise report on the configuration and iteration. | ||
t.Fatalf("Failed SimGenesisAccount on iteration #%d: %#v\n\n%s\n\n%s", i, acct, r, debug.Stack()) | ||
}() | ||
|
||
f := fuzz.New() | ||
for i = 0; i < 1e5; i++ { | ||
acct = new(SimGenesisAccount) | ||
f.Fuzz(acct) | ||
acct.Validate() //nolint:errcheck | ||
} | ||
} |
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