Skip to content

Commit

Permalink
Revert "Problem: cannot unmarshal gov param into a *big.Int (#857)"
Browse files Browse the repository at this point in the history
This reverts commit 783e224.
  • Loading branch information
mmsqe committed Dec 12, 2024
1 parent 142c0af commit 85871d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
1 change: 0 additions & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,4 @@ 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
)
30 changes: 7 additions & 23 deletions tests/integration/tx/aminojson/aminojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,8 @@ 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
Expand Down Expand Up @@ -228,15 +224,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
protoUnmarshalFails bool
}{
"auth/params": {gogo: &authtypes.Params{TxSigLimit: 10}, pulsar: &authapi.Params{TxSigLimit: 10}},
"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": {
"auth/module_account": {
gogo: &authtypes.ModuleAccount{
BaseAccount: authtypes.NewBaseAccountWithAddress(addr1), Permissions: []string{},
},
Expand Down Expand Up @@ -419,22 +407,16 @@ 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)
Expand All @@ -452,8 +434,10 @@ func TestAminoJSON_LegacyParity(t *testing.T) {

newGogoBytes, err := encCfg.Amino.MarshalJSON(newGogo)
require.NoError(t, err)
newGogoBytes, err = types.SortJSON(newGogoBytes)
require.NoError(t, err)
if tc.roundTripUnequal {
require.NotEqual(t, string(gogoBytes), string(newGogoBytes))
return
}
require.Equal(t, string(gogoBytes), string(newGogoBytes))

// test amino json signer handler equivalence
Expand Down
7 changes: 6 additions & 1 deletion x/tx/signing/aminojson/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ func cosmosDecEncoder(_ *Encoder, v protoreflect.Value, w io.Writer) error {
if val == "" {
return jsonMarshal(w, "0")
}
return jsonMarshal(w, val)
var dec math.LegacyDec
err := dec.Unmarshal([]byte(val))
if err != nil {
return err
}
return jsonMarshal(w, dec.String())
case []byte:
if len(val) == 0 {
return jsonMarshal(w, "0")
Expand Down

0 comments on commit 85871d4

Please sign in to comment.