-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: types: ensure .Amount is non-nil in Coin.Validate()
This change fixes a scenario in which Coin.Validate() would panic when given a nil Amount. While here, added a fuzz test along with unit/regression tests. Fixes #15690
- Loading branch information
Showing
4 changed files
with
65 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
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,24 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
) | ||
|
||
func FuzzCoinUnmarshalJSON(f *testing.F) { | ||
if testing.Short() { | ||
f.Skip() | ||
} | ||
|
||
cdc := codec.NewLegacyAmino() | ||
f.Add(`{"denom":"atom","amount":"1000"}`) | ||
f.Add(`{"denom":"atom","amount":"-1000"}`) | ||
f.Add(`{"denom":"uatom","amount":"1000111111111111111111111"}`) | ||
f.Add(`{"denom":"mu","amount":"0"}`) | ||
|
||
f.Fuzz(func(t *testing.T, jsonBlob string) { | ||
var c Coin | ||
_ = cdc.UnmarshalJSON([]byte(jsonBlob), &c) | ||
}) | ||
} |