Skip to content

Commit

Permalink
tests(math): fix zero value test (#21821)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski authored Sep 20, 2024
1 parent fa9ce49 commit 5a05f12
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions math/dec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,11 +1032,13 @@ func Test_DocumentLegacyAsymmetry(t *testing.T) {

zeroDecBz, err := zeroDec.Marshal()
require.NoError(t, err)
zeroDecJSON := zeroDec.String()
zeroDecJSON, err := zeroDec.MarshalJSON()
require.NoError(t, err)

emptyDecBz, err := emptyDec.Marshal()
require.NoError(t, err)
emptyDecJSON := emptyDec.String()
emptyDecJSON, err := emptyDec.MarshalJSON()
require.NoError(t, err)

// makes sense, zero and empty are semantically different and render differently
require.NotEqual(t, zeroDecJSON, emptyDecJSON)
Expand All @@ -1047,14 +1049,19 @@ func Test_DocumentLegacyAsymmetry(t *testing.T) {
zeroDecRoundTrip := math.LegacyDec{}
err = zeroDecRoundTrip.Unmarshal(zeroDecBz)
require.NoError(t, err)
require.Equal(t, zeroDec.String(), zeroDecRoundTrip.String())
zeroDecRoundTripJSON, err := zeroDecRoundTrip.MarshalJSON()
require.NoError(t, err)
require.Equal(t, zeroDecJSON, zeroDecRoundTripJSON)
require.Equal(t, zeroDec, zeroDecRoundTrip)

// empty values are not
emptyDecRoundTrip := math.LegacyDec{}
err = emptyDecRoundTrip.Unmarshal(emptyDecBz)
require.NoError(t, err)
emptyDecRoundTripJSON, err := emptyDecRoundTrip.MarshalJSON()
require.NoError(t, err)

// !!! this is the key point, they are not equal, it looks like a bug
require.NotEqual(t, emptyDec.String(), emptyDecRoundTrip.String())
require.NotEqual(t, emptyDecJSON, emptyDecRoundTripJSON)
require.NotEqual(t, emptyDec, emptyDecRoundTrip)
}

0 comments on commit 5a05f12

Please sign in to comment.