Skip to content

Commit

Permalink
Merge pull request #1208 from dadamu/paul/fix-stargate-querier
Browse files Browse the repository at this point in the history
fix: stargate querier does not reset the structure state
  • Loading branch information
alpe authored Mar 2, 2023
2 parents 40b4e6e + 6d8018a commit dc9a920
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions x/wasm/keeper/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ func ConvertProtoToJSONMarshal(cdc codec.Codec, protoResponse codec.ProtoMarshal
return nil, sdkerrors.Wrap(err, "to json")
}

protoResponse.Reset()
return bz, nil
}

Expand Down
25 changes: 25 additions & 0 deletions x/wasm/keeper/query_plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,31 @@ func TestConvertProtoToJSONMarshal(t *testing.T) {
}
}

func TestResetProtoMarshalerAfterJsonMarshal(t *testing.T) {
appCodec := app.MakeEncodingConfig().Marshaler

protoMarshaler := &banktypes.QueryAllBalancesResponse{}
expected := appCodec.MustMarshalJSON(&banktypes.QueryAllBalancesResponse{
Balances: sdk.NewCoins(sdk.NewCoin("bar", sdk.NewInt(30))),
Pagination: &query.PageResponse{
NextKey: []byte("foo"),
},
})

bz, err := hex.DecodeString("0a090a036261721202333012050a03666f6f")
require.NoError(t, err)

// first marshal
response, err := keeper.ConvertProtoToJSONMarshal(appCodec, protoMarshaler, bz)
require.NoError(t, err)
require.Equal(t, expected, response)

// second marshal
response, err = keeper.ConvertProtoToJSONMarshal(appCodec, protoMarshaler, bz)
require.NoError(t, err)
require.Equal(t, expected, response)
}

// TestDeterministicJsonMarshal tests that we get deterministic JSON marshalled response upon
// proto struct update in the state machine.
func TestDeterministicJsonMarshal(t *testing.T) {
Expand Down

0 comments on commit dc9a920

Please sign in to comment.