Skip to content

Commit

Permalink
moar test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Dec 11, 2024
1 parent 4f2e3ff commit 4858fbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
1 change: 0 additions & 1 deletion tests/integration/rapidgen/rapidgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ var (
NonsignableTypes = []GeneratedType{
GenType(&authtypes.Params{}, &authapi.Params{}, GenOpts),
GenType(&authtypes.BaseAccount{}, &authapi.BaseAccount{}, GenOpts.WithAnyTypes(&ed25519.PubKey{})),
GenType(&authtypes.ModuleAccount{}, &authapi.ModuleAccount{}, GenOpts.WithAnyTypes(&ed25519.PubKey{})),
GenType(&authtypes.ModuleCredential{}, &authapi.ModuleCredential{}, GenOpts),

GenType(&authztypes.GenericAuthorization{}, &authzapi.GenericAuthorization{}, GenOpts),
Expand Down
31 changes: 14 additions & 17 deletions tests/integration/tx/aminojson/aminojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestAminoJSON_Equivalence(t *testing.T) {
gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{}, params.AppModuleBasic{},
slashing.AppModuleBasic{}, staking.AppModuleBasic{}, upgrade.AppModuleBasic{}, vesting.AppModuleBasic{})
legacytx.RegressionTestingAminoCodec = encCfg.Amino
aj := aminojson.NewEncoder(aminojson.EncoderOptions{DoNotSortFields: true})
aj := aminojson.NewEncoder(aminojson.EncoderOptions{})

for _, tt := range rapidgen.DefaultGeneratedTypes {
desc := tt.Pulsar.ProtoReflect().Descriptor()
Expand Down Expand Up @@ -132,6 +132,7 @@ func TestAminoJSON_Equivalence(t *testing.T) {

legacyAminoJSON, err := encCfg.Amino.MarshalJSON(gogo)
require.NoError(t, err)
legacyAminoJSON = sortJSON(t, legacyAminoJSON)
aminoJSON, err := aj.Marshal(msg)
require.NoError(t, err)
require.Equal(t, string(legacyAminoJSON), string(aminoJSON))
Expand Down Expand Up @@ -220,10 +221,6 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
// represent the array as nil, and a subsequent marshal to JSON represent the array as null instead of empty.
roundTripUnequal bool

// pulsar does not support marshaling a math.Dec as anything except a string. Therefore, we cannot unmarshal
// a pulsar encoded Math.dec (the string representation of a Decimal) into a gogo Math.dec (expecting an int64).
protoUnmarshalFails bool

// sort JSON bytes before comparison. for certain types (like ModuleAccount) x/tx is not able to provide an
// unsorted version. note that the legacy amino signer always sorted JSON bytes by round tripping them to/from
// JSON before signing over them.
Expand Down Expand Up @@ -265,9 +262,8 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
pulsar: &distapi.DelegatorStartingInfo{},
},
"distribution/delegator_starting_info/non_zero_dec": {
gogo: &disttypes.DelegatorStartingInfo{Stake: math.LegacyNewDec(10)},
pulsar: &distapi.DelegatorStartingInfo{Stake: string(dec10bz)},
protoUnmarshalFails: true,
gogo: &disttypes.DelegatorStartingInfo{Stake: math.LegacyNewDec(10)},
pulsar: &distapi.DelegatorStartingInfo{Stake: string(dec10bz)},
},
"distribution/delegation_delegator_reward": {
gogo: &disttypes.DelegationDelegatorReward{},
Expand Down Expand Up @@ -427,11 +423,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
gogoBytes, err := encCfg.Amino.MarshalJSON(tc.gogo)
require.NoError(t, err)
if tc.sortJSON {
var c interface{}
err = json.Unmarshal(gogoBytes, &c)
require.NoError(t, err)
gogoBytes, err = json.Marshal(c)
require.NoError(t, err)
gogoBytes = sortJSON(t, gogoBytes)
}

pulsarBytes, err := aj.Marshal(tc.pulsar)
Expand All @@ -452,10 +444,6 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
newGogo := reflect.New(gogoType).Interface().(gogoproto.Message)

err = encCfg.Codec.Unmarshal(pulsarProtoBytes, newGogo)
if tc.protoUnmarshalFails {
require.Error(t, err)
return
}
require.NoError(t, err)

newGogoBytes, err := encCfg.Amino.MarshalJSON(newGogo)
Expand Down Expand Up @@ -599,3 +587,12 @@ func postFixPulsarMessage(msg proto.Message) {
}
}
}

func sortJSON(t require.TestingT, bz []byte) []byte {
var c interface{}
err := json.Unmarshal(bz, &c)
require.NoError(t, err)
bz, err = json.Marshal(c)
require.NoError(t, err)
return bz
}

0 comments on commit 4858fbe

Please sign in to comment.