-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amino/json): use AminoMarshaler reprType info
When a type is registered, if it implements AminoMarshaler, then use the type returned by `MarshalAmino` method to feed type `ConcreteInfo`. This prevents a panics that happens during the sanity check phase of `encodeReflectJSONInterface` when the type `ConcreteInfo` doesn't match the JSON structure. For instance, that used to happen with `BigintValue` which is a struct (so expected JSON is `{...}`), but is marshaled into a simple string (so expected JSON is only `"..."`).
- Loading branch information
Showing
4 changed files
with
34 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gnolang | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/jaekwon/testify/require" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/amino" | ||
) | ||
|
||
// Tries to reproduce the bug #1036 on all registered types | ||
func TestMarshalAminoRegisteredTypes(t *testing.T) { | ||
for _, typ := range Package.Types { | ||
// Instanciate registered type | ||
x := reflect.New(typ.Type).Interface() | ||
// Call MarshalAmino directly on 'x' | ||
_, err := amino.MarshalJSON(x) | ||
require.NoError(t, err, "marshal type %s", typ.Type.Name()) | ||
// Call MarshalAmino on a struct that embeds 'x' in a field of type any | ||
xx := struct { | ||
X any | ||
}{X: x} | ||
_, err = amino.MarshalJSON(xx) | ||
require.NoError(t, err, "marshal type %s from struct", typ.Type.Name()) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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