Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Jan 31, 2025
1 parent e86ea8d commit bd37671
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
15 changes: 7 additions & 8 deletions x/move/keeper/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,13 @@ func Test_API_Query(t *testing.T) {
api := keeper.NewApi(input.MoveKeeper, ctx.WithBlockTime(now))

// out of gas
require.Panics(t, func() {
_, _, _ = api.Query(vmtypes.QueryRequest{
Stargate: &vmtypes.StargateQuery{
Path: "/initia.gov.v1.Query/Proposal",
Data: []byte(`{"proposal_id": "1"}`),
},
}, 100)
})
_, _, err = api.Query(vmtypes.QueryRequest{
Stargate: &vmtypes.StargateQuery{
Path: "/initia.gov.v1.Query/Proposal",
Data: []byte(`{"proposal_id": "1"}`),
},
}, 100)
require.ErrorContains(t, err, "out of gas")

// valid query
gasBalance := uint64(2000)
Expand Down
14 changes: 12 additions & 2 deletions x/move/keeper/vm_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (

abci "github.com/cometbft/cometbft/abci/types"

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/initia-labs/initia/x/move/types"
vmtypes "github.com/initia-labs/movevm/types"
Expand All @@ -14,10 +17,17 @@ import (
func (k Keeper) HandleVMQuery(ctx sdk.Context, req *vmtypes.QueryRequest) (res []byte, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic in HandleVMQuery: %v", r)
switch rType := r.(type) {
case storetypes.ErrorOutOfGas:
err = errorsmod.Wrapf(sdkerrors.ErrOutOfGas, "Query gas limit exceeded, out of gas in location: %v", rType.Descriptor)
default:
err = fmt.Errorf("panic in HandleVMQuery: %v", r)

Check warning on line 24 in x/move/keeper/vm_query.go

View check run for this annotation

Codecov / codecov/patch

x/move/keeper/vm_query.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}
}

err = types.ErrVMQueryFailed.Wrap(err.Error())
if err != nil {
err = types.ErrVMQueryFailed.Wrap(err.Error())
}
}()

switch {
Expand Down
4 changes: 2 additions & 2 deletions x/move/keeper/vm_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Test_VMQuery_Stargate(t *testing.T) {
Data: nil,
},
})
require.ErrorIs(t, err, types.ErrNotSupportedStargateQuery)
require.ErrorContains(t, err, types.ErrNotSupportedStargateQuery.Error())

proposal := govtypes.Proposal{
Id: 1,
Expand Down Expand Up @@ -64,7 +64,7 @@ func Test_VMQuery_Custom(t *testing.T) {
Data: nil,
},
})
require.ErrorIs(t, err, types.ErrNotSupportedCustomQuery)
require.ErrorContains(t, err, types.ErrNotSupportedCustomQuery.Error())

reqBz, err := json.Marshal(types.ToSDKAddressRequest{
VMAddr: vmtypes.StdAddress.String(),
Expand Down

0 comments on commit bd37671

Please sign in to comment.