Skip to content

Commit

Permalink
fix: prevent false to not be encoded (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux authored and tac0turtle committed Oct 10, 2019
1 parent ccb336d commit 4ce542e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions amino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,28 @@ func TestUnmarshalBinaryBufferedWritesReads(t *testing.T) {
_, err = cdc.UnmarshalBinaryLengthPrefixedReader(buf, &s2, 0)
assert.NotNil(t, err)
}

func TestBoolPointers(t *testing.T) {
var cdc = amino.NewCodec()
type SimpleStruct struct {
BoolPtrTrue *bool
BoolPtrFalse *bool
}

ttrue := true
ffalse := false

s := SimpleStruct{
BoolPtrTrue: &ttrue,
BoolPtrFalse: &ffalse,
}

b, _ := cdc.MarshalBinaryBare(s)

var s2 SimpleStruct
err := cdc.UnmarshalBinaryBare(b, &s2)

assert.Nil(t, err)
assert.NotNil(t, s2.BoolPtrTrue)
assert.NotNil(t, s2.BoolPtrFalse)
}
2 changes: 1 addition & 1 deletion reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func isDefaultValue(rv reflect.Value) (erv reflect.Value, isDefaultValue bool) {
}
switch rv.Kind() {
case reflect.Bool:
return rv, !rv.Bool()
return rv, false
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return rv, rv.Int() == 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
Expand Down

0 comments on commit 4ce542e

Please sign in to comment.