diff --git a/tests/go.mod b/tests/go.mod index 78f711884c42..d9c660a2b8f4 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -214,4 +214,5 @@ replace ( // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 + cosmossdk.io/x/tx => ../x/tx ) diff --git a/tests/integration/tx/aminojson/aminojson_test.go b/tests/integration/tx/aminojson/aminojson_test.go index eb271308f8d6..6d9859db7ac3 100644 --- a/tests/integration/tx/aminojson/aminojson_test.go +++ b/tests/integration/tx/aminojson/aminojson_test.go @@ -131,8 +131,12 @@ func TestAminoJSON_Equivalence(t *testing.T) { legacyAminoJSON, err := encCfg.Amino.MarshalJSON(gogo) require.NoError(t, err) + legacyAminoJSON, err = types.SortJSON(legacyAminoJSON) + require.NoError(t, err) aminoJSON, err := aj.Marshal(msg) require.NoError(t, err) + aminoJSON, err = types.SortJSON(aminoJSON) + require.NoError(t, err) require.Equal(t, string(legacyAminoJSON), string(aminoJSON)) // test amino json signer handler equivalence @@ -224,7 +228,15 @@ func TestAminoJSON_LegacyParity(t *testing.T) { protoUnmarshalFails bool }{ "auth/params": {gogo: &authtypes.Params{TxSigLimit: 10}, pulsar: &authapi.Params{TxSigLimit: 10}}, - "auth/module_account": { + "auth/module_account_nil_permissions": { + gogo: &authtypes.ModuleAccount{ + BaseAccount: authtypes.NewBaseAccountWithAddress(addr1), + }, + pulsar: &authapi.ModuleAccount{ + BaseAccount: &authapi.BaseAccount{Address: addr1.String()}, + }, + }, + "auth/module_account_empty_permissions": { gogo: &authtypes.ModuleAccount{ BaseAccount: authtypes.NewBaseAccountWithAddress(addr1), Permissions: []string{}, }, @@ -407,16 +419,22 @@ func TestAminoJSON_LegacyParity(t *testing.T) { t.Run(name, func(t *testing.T) { gogoBytes, err := encCfg.Amino.MarshalJSON(tc.gogo) require.NoError(t, err) - + gogoBytes, err = types.SortJSON(gogoBytes) + require.NoError(t, err) pulsarBytes, err := aj.Marshal(tc.pulsar) if tc.pulsarMarshalFails { require.Error(t, err) return } require.NoError(t, err) - + pulsarBytes, err = types.SortJSON(pulsarBytes) + require.NoError(t, err) fmt.Printf("pulsar: %s\n", string(pulsarBytes)) fmt.Printf(" gogo: %s\n", string(gogoBytes)) + if tc.roundTripUnequal { + require.NotEqual(t, string(gogoBytes), string(pulsarBytes)) + return + } require.Equal(t, string(gogoBytes), string(pulsarBytes)) pulsarProtoBytes, err := proto.Marshal(tc.pulsar) @@ -434,10 +452,8 @@ func TestAminoJSON_LegacyParity(t *testing.T) { newGogoBytes, err := encCfg.Amino.MarshalJSON(newGogo) require.NoError(t, err) - if tc.roundTripUnequal { - require.NotEqual(t, string(gogoBytes), string(newGogoBytes)) - return - } + newGogoBytes, err = types.SortJSON(newGogoBytes) + require.NoError(t, err) require.Equal(t, string(gogoBytes), string(newGogoBytes)) // test amino json signer handler equivalence diff --git a/x/tx/signing/aminojson/encoder.go b/x/tx/signing/aminojson/encoder.go index e954c2651e30..c4bf10d04dbe 100644 --- a/x/tx/signing/aminojson/encoder.go +++ b/x/tx/signing/aminojson/encoder.go @@ -51,12 +51,7 @@ func cosmosDecEncoder(_ *Encoder, v protoreflect.Value, w io.Writer) error { if val == "" { return jsonMarshal(w, "0") } - var dec math.LegacyDec - err := dec.Unmarshal([]byte(val)) - if err != nil { - return err - } - return jsonMarshal(w, dec.String()) + return jsonMarshal(w, val) case []byte: if len(val) == 0 { return jsonMarshal(w, "0")