diff --git a/go.mod b/go.mod index 9e846a2cb3..0f30e00006 100644 --- a/go.mod +++ b/go.mod @@ -185,3 +185,5 @@ replace github.com/regen-network/regen-ledger/errors => ./errors replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 + +replace github.com/regen-network/regen-ledger/errors => ./errors diff --git a/x/ecocredit/base/keeper/query_all_balances.go b/x/ecocredit/base/keeper/query_all_balances.go index d8d351f66c..cce3adcbe2 100644 --- a/x/ecocredit/base/keeper/query_all_balances.go +++ b/x/ecocredit/base/keeper/query_all_balances.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" + regenerrors "github.com/regen-network/regen-ledger/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/types/ormutil" @@ -16,7 +17,7 @@ import ( func (k Keeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequest) (*types.QueryAllBalancesResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf(err.Error()) } it, err := k.stateStore.BatchBalanceTable().List(ctx, api.BatchBalancePrimaryKey{}, ormlist.Paginate(pg)) if err != nil { @@ -33,7 +34,7 @@ func (k Keeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequ batch, err := k.stateStore.BatchTable().Get(ctx, balance.BatchKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("batch with key: %d", balance.BatchKey) } res.Balances = append(res.Balances, &types.BatchBalanceInfo{ @@ -46,7 +47,7 @@ func (k Keeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequ } res.Pagination, err = ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &res, nil } diff --git a/x/ecocredit/base/keeper/query_allowed_class_creators.go b/x/ecocredit/base/keeper/query_allowed_class_creators.go index 47d2192548..1c7ab04357 100644 --- a/x/ecocredit/base/keeper/query_allowed_class_creators.go +++ b/x/ecocredit/base/keeper/query_allowed_class_creators.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" baseapi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,7 +16,7 @@ import ( func (k Keeper) AllowedClassCreators(ctx context.Context, req *types.QueryAllowedClassCreatorsRequest) (*types.QueryAllowedClassCreatorsResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } itr, err := k.stateStore.AllowedClassCreatorTable().List(ctx, baseapi.AllowedClassCreatorAddressIndexKey{}, ormlist.Paginate(pg)) @@ -36,7 +37,7 @@ func (k Keeper) AllowedClassCreators(ctx context.Context, req *types.QueryAllowe pr, err := ormutil.PulsarPageResToGogoPageRes(itr.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryAllowedClassCreatorsResponse{ diff --git a/x/ecocredit/base/keeper/query_balance.go b/x/ecocredit/base/keeper/query_balance.go index b14154a34e..f6b1507e0e 100644 --- a/x/ecocredit/base/keeper/query_balance.go +++ b/x/ecocredit/base/keeper/query_balance.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" "github.com/regen-network/regen-ledger/x/ecocredit/server/utils" ) @@ -15,17 +15,17 @@ import ( func (k Keeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) { batch, err := k.stateStore.BatchTable().GetByDenom(ctx, req.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) } addr, err := sdk.AccAddressFromBech32(req.Address) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } balance, err := utils.GetBalance(ctx, k.stateStore.BatchBalanceTable(), addr, batch.Key) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get balance with batch key: %d", batch.Key) } info := types.BatchBalanceInfo{ diff --git a/x/ecocredit/base/keeper/query_balance_by_batch.go b/x/ecocredit/base/keeper/query_balance_by_batch.go index 431d882205..bec8cb6b06 100644 --- a/x/ecocredit/base/keeper/query_balance_by_batch.go +++ b/x/ecocredit/base/keeper/query_balance_by_batch.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,11 +15,11 @@ import ( func (k Keeper) BalancesByBatch(ctx context.Context, req *types.QueryBalancesByBatchRequest) (*types.QueryBalancesByBatchResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } batch, err := k.stateStore.BatchTable().GetByDenom(ctx, req.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) } it, err := k.stateStore.BatchBalanceTable().List(ctx, api.BatchBalanceBatchKeyAddressIndexKey{}.WithBatchKey(batch.Key), ormlist.Paginate(pg)) if err != nil { @@ -43,7 +43,7 @@ func (k Keeper) BalancesByBatch(ctx context.Context, req *types.QueryBalancesByB } pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBalancesByBatchResponse{ Balances: balances, diff --git a/x/ecocredit/base/keeper/query_balances.go b/x/ecocredit/base/keeper/query_balances.go index 9684faf106..47fc250e03 100644 --- a/x/ecocredit/base/keeper/query_balances.go +++ b/x/ecocredit/base/keeper/query_balances.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -14,12 +15,12 @@ import ( func (k Keeper) Balances(ctx context.Context, req *types.QueryBalancesRequest) (*types.QueryBalancesResponse, error) { addr, err := sdk.AccAddressFromBech32(req.Address) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.BatchBalanceTable().List(ctx, api.BatchBalanceAddressBatchKeyIndexKey{}.WithAddress(addr), ormlist.Paginate(pg)) @@ -37,7 +38,7 @@ func (k Keeper) Balances(ctx context.Context, req *types.QueryBalancesRequest) ( batch, err := k.stateStore.BatchTable().Get(ctx, balance.BatchKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("balance with key: %d", balance.BatchKey) } info := types.BatchBalanceInfo{ @@ -53,7 +54,7 @@ func (k Keeper) Balances(ctx context.Context, req *types.QueryBalancesRequest) ( pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBalancesResponse{Balances: balances, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_batch_info.go b/x/ecocredit/base/keeper/query_batch_info.go index d2c81b6ad1..6ca603abba 100644 --- a/x/ecocredit/base/keeper/query_batch_info.go +++ b/x/ecocredit/base/keeper/query_batch_info.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/ecocredit/base" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -14,19 +14,19 @@ import ( // Batch queries for information on a credit batch. func (k Keeper) Batch(ctx context.Context, request *types.QueryBatchRequest) (*types.QueryBatchResponse, error) { if err := base.ValidateBatchDenom(request.BatchDenom); err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("batch denom: %s", err) + return nil, regenerrors.ErrInvalidArgument.Wrapf("batch denom: %s", err) } batch, err := k.stateStore.BatchTable().GetByDenom(ctx, request.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) } issuer := sdk.AccAddress(batch.Issuer) project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("could not get project with key %d", batch.ProjectKey) } info := types.BatchInfo{ diff --git a/x/ecocredit/base/keeper/query_batches.go b/x/ecocredit/base/keeper/query_batches.go index eb531211c9..95c6aebf96 100644 --- a/x/ecocredit/base/keeper/query_batches.go +++ b/x/ecocredit/base/keeper/query_batches.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -16,7 +17,7 @@ import ( func (k Keeper) Batches(ctx context.Context, request *types.QueryBatchesRequest) (*types.QueryBatchesResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.BatchTable().List(ctx, api.BatchPrimaryKey{}, ormlist.Paginate(pg)) @@ -36,7 +37,7 @@ func (k Keeper) Batches(ctx context.Context, request *types.QueryBatchesRequest) project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("failed to get project by key: %d: %s", batch.ProjectKey, err.Error()) } info := types.BatchInfo{ @@ -55,7 +56,7 @@ func (k Keeper) Batches(ctx context.Context, request *types.QueryBatchesRequest) pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesResponse{ diff --git a/x/ecocredit/base/keeper/query_batches_by_class.go b/x/ecocredit/base/keeper/query_batches_by_class.go index 8453c0fdb9..a47a4ae03c 100644 --- a/x/ecocredit/base/keeper/query_batches_by_class.go +++ b/x/ecocredit/base/keeper/query_batches_by_class.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -17,12 +17,12 @@ import ( func (k Keeper) BatchesByClass(ctx context.Context, request *types.QueryBatchesByClassRequest) (*types.QueryBatchesByClassResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } class, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } // we put a "-" after the class name to avoid including class names outside of the query (i.e. a query for C01 could technically include C011 otherwise). @@ -43,7 +43,7 @@ func (k Keeper) BatchesByClass(ctx context.Context, request *types.QueryBatchesB project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get project with key: %d", batch.ProjectKey) } info := types.BatchInfo{ @@ -62,7 +62,7 @@ func (k Keeper) BatchesByClass(ctx context.Context, request *types.QueryBatchesB pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesByClassResponse{ diff --git a/x/ecocredit/base/keeper/query_batches_by_issuer.go b/x/ecocredit/base/keeper/query_batches_by_issuer.go index acce1772c0..d519125411 100644 --- a/x/ecocredit/base/keeper/query_batches_by_issuer.go +++ b/x/ecocredit/base/keeper/query_batches_by_issuer.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -17,12 +17,12 @@ import ( func (k Keeper) BatchesByIssuer(ctx context.Context, req *types.QueryBatchesByIssuerRequest) (*types.QueryBatchesByIssuerResponse, error) { issuer, err := sdk.AccAddressFromBech32(req.Issuer) if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("issuer: %s", err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.BatchTable().List(ctx, api.BatchIssuerIndexKey{}.WithIssuer(issuer), ormlist.Paginate(pg)) @@ -41,7 +41,7 @@ func (k Keeper) BatchesByIssuer(ctx context.Context, req *types.QueryBatchesByIs project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get project by key: %d", batch.ProjectKey) } info := types.BatchInfo{ @@ -60,7 +60,7 @@ func (k Keeper) BatchesByIssuer(ctx context.Context, req *types.QueryBatchesByIs pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesByIssuerResponse{Batches: batches, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_batches_by_issuer_test.go b/x/ecocredit/base/keeper/query_batches_by_issuer_test.go index cc645857ea..e9b65553f8 100644 --- a/x/ecocredit/base/keeper/query_batches_by_issuer_test.go +++ b/x/ecocredit/base/keeper/query_batches_by_issuer_test.go @@ -7,7 +7,6 @@ import ( "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" @@ -70,5 +69,5 @@ func TestQueryBatchesByIssuer(t *testing.T) { // query batches by an invalid address _, err = s.k.BatchesByIssuer(s.ctx, &types.QueryBatchesByIssuerRequest{Issuer: "foobar"}) - assert.ErrorContains(t, err, sdkerrors.ErrInvalidAddress.Error()) + assert.ErrorContains(t, err, "decoding bech32 failed: invalid bech32 string length 6: invalid argument") } diff --git a/x/ecocredit/base/keeper/query_batches_by_project.go b/x/ecocredit/base/keeper/query_batches_by_project.go index 77ef08686a..2f3ec051e5 100644 --- a/x/ecocredit/base/keeper/query_batches_by_project.go +++ b/x/ecocredit/base/keeper/query_batches_by_project.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -17,12 +17,12 @@ import ( func (k Keeper) BatchesByProject(ctx context.Context, request *types.QueryBatchesByProjectRequest) (*types.QueryBatchesByProjectResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } project, err := k.stateStore.ProjectTable().GetById(ctx, request.ProjectId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) } it, err := k.stateStore.BatchTable().List(ctx, api.BatchProjectKeyIndexKey{}.WithProjectKey(project.Key), ormlist.Paginate(pg)) @@ -56,7 +56,7 @@ func (k Keeper) BatchesByProject(ctx context.Context, request *types.QueryBatche pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesByProjectResponse{ diff --git a/x/ecocredit/base/keeper/query_class_creator_allowlist.go b/x/ecocredit/base/keeper/query_class_creator_allowlist.go index c8e24bf1bc..7e3955b802 100644 --- a/x/ecocredit/base/keeper/query_class_creator_allowlist.go +++ b/x/ecocredit/base/keeper/query_class_creator_allowlist.go @@ -3,6 +3,7 @@ package keeper import ( "context" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -10,7 +11,7 @@ import ( func (k Keeper) ClassCreatorAllowlist(ctx context.Context, request *types.QueryClassCreatorAllowlistRequest) (*types.QueryClassCreatorAllowlistResponse, error) { result, err := k.stateStore.ClassCreatorAllowlistTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("failed to get class creator allowlist: %s", err.Error()) } return &types.QueryClassCreatorAllowlistResponse{ diff --git a/x/ecocredit/base/keeper/query_class_fee.go b/x/ecocredit/base/keeper/query_class_fee.go index 4d85d6ac00..5fa4c1b63b 100644 --- a/x/ecocredit/base/keeper/query_class_fee.go +++ b/x/ecocredit/base/keeper/query_class_fee.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -14,7 +14,7 @@ import ( func (k Keeper) ClassFee(ctx context.Context, request *types.QueryClassFeeRequest) (*types.QueryClassFeeResponse, error) { classFee, err := k.stateStore.ClassFeeTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("failed to get class fee: %s", err.Error()) } var fee sdk.Coin @@ -22,7 +22,7 @@ func (k Keeper) ClassFee(ctx context.Context, request *types.QueryClassFeeReques var ok bool fee, ok = regentypes.ProtoCoinToCoin(classFee.Fee) if !ok { - return nil, sdkerrors.ErrInvalidType.Wrapf("failed to parse class fee") + return nil, regenerrors.ErrInternal.Wrapf("failed to parse class fee") } } diff --git a/x/ecocredit/base/keeper/query_class_info.go b/x/ecocredit/base/keeper/query_class_info.go index 3188f10c3c..9bc525b25d 100644 --- a/x/ecocredit/base/keeper/query_class_info.go +++ b/x/ecocredit/base/keeper/query_class_info.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -13,7 +13,7 @@ import ( func (k Keeper) Class(ctx context.Context, request *types.QueryClassRequest) (*types.QueryClassResponse, error) { class, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } admin := sdk.AccAddress(class.Admin) diff --git a/x/ecocredit/base/keeper/query_class_issuers.go b/x/ecocredit/base/keeper/query_class_issuers.go index 43f35c1fed..9471e738e3 100644 --- a/x/ecocredit/base/keeper/query_class_issuers.go +++ b/x/ecocredit/base/keeper/query_class_issuers.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -16,12 +16,12 @@ import ( func (k Keeper) ClassIssuers(ctx context.Context, request *types.QueryClassIssuersRequest) (*types.QueryClassIssuersResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } classInfo, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } it, err := k.stateStore.ClassIssuerTable().List(ctx, api.ClassIssuerClassKeyIssuerIndexKey{}.WithClassKey(classInfo.Key), ormlist.Paginate(pg)) @@ -40,7 +40,7 @@ func (k Keeper) ClassIssuers(ctx context.Context, request *types.QueryClassIssue } pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryClassIssuersResponse{ Issuers: issuers, diff --git a/x/ecocredit/base/keeper/query_classes.go b/x/ecocredit/base/keeper/query_classes.go index 549b2ebefb..c3ff863b31 100644 --- a/x/ecocredit/base/keeper/query_classes.go +++ b/x/ecocredit/base/keeper/query_classes.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,7 +16,7 @@ import ( func (k Keeper) Classes(ctx context.Context, request *types.QueryClassesRequest) (*types.QueryClassesResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ClassTable().List(ctx, &api.ClassPrimaryKey{}, ormlist.Paginate(pg)) @@ -45,7 +46,7 @@ func (k Keeper) Classes(ctx context.Context, request *types.QueryClassesRequest) pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryClassesResponse{ diff --git a/x/ecocredit/base/keeper/query_classes_by_admin.go b/x/ecocredit/base/keeper/query_classes_by_admin.go index 3af1911175..af8f006af2 100644 --- a/x/ecocredit/base/keeper/query_classes_by_admin.go +++ b/x/ecocredit/base/keeper/query_classes_by_admin.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -16,12 +16,12 @@ import ( func (k Keeper) ClassesByAdmin(ctx context.Context, req *types.QueryClassesByAdminRequest) (*types.QueryClassesByAdminResponse, error) { admin, err := sdk.AccAddressFromBech32(req.Admin) if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("invalid admin: %s", err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ClassTable().List(ctx, api.ClassAdminIndexKey{}.WithAdmin(admin), ormlist.Paginate(pg)) @@ -50,7 +50,7 @@ func (k Keeper) ClassesByAdmin(ctx context.Context, req *types.QueryClassesByAdm pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryClassesByAdminResponse{Classes: classes, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_classes_by_admin_test.go b/x/ecocredit/base/keeper/query_classes_by_admin_test.go index 1715a857cb..6b574692b5 100644 --- a/x/ecocredit/base/keeper/query_classes_by_admin_test.go +++ b/x/ecocredit/base/keeper/query_classes_by_admin_test.go @@ -6,10 +6,10 @@ import ( "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -55,5 +55,5 @@ func TestQueryClassesByAdmin(t *testing.T) { // query classes by an invalid admin address _, err = s.k.ClassesByAdmin(s.ctx, &types.QueryClassesByAdminRequest{Admin: "foobar"}) - assert.ErrorContains(t, err, sdkerrors.ErrInvalidAddress.Error()) + assert.ErrorContains(t, err, regenerrors.ErrInvalidArgument.Error()) } diff --git a/x/ecocredit/base/keeper/query_credit_type.go b/x/ecocredit/base/keeper/query_credit_type.go index 0ae22d5567..c62948f160 100644 --- a/x/ecocredit/base/keeper/query_credit_type.go +++ b/x/ecocredit/base/keeper/query_credit_type.go @@ -3,6 +3,7 @@ package keeper import ( "context" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -10,7 +11,7 @@ import ( func (k Keeper) CreditType(ctx context.Context, request *types.QueryCreditTypeRequest) (*types.QueryCreditTypeResponse, error) { creditType, err := k.stateStore.CreditTypeTable().Get(ctx, request.Abbreviation) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get credit type with abbreviation: %s", request.Abbreviation) } return &types.QueryCreditTypeResponse{ diff --git a/x/ecocredit/base/keeper/query_credit_type_test.go b/x/ecocredit/base/keeper/query_credit_type_test.go index 0db7a4b07d..a9091fe6b2 100644 --- a/x/ecocredit/base/keeper/query_credit_type_test.go +++ b/x/ecocredit/base/keeper/query_credit_type_test.go @@ -5,8 +5,6 @@ import ( "gotest.tools/v3/assert" - "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" - api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -33,5 +31,5 @@ func TestQuery_CreditType(t *testing.T) { _, err = s.k.CreditType(s.ctx, &types.QueryCreditTypeRequest{ Abbreviation: "D", }) - assert.ErrorIs(t, err, ormerrors.NotFound) + assert.Equal(t, err.Error(), "unable to get credit type with abbreviation: D: not found") } diff --git a/x/ecocredit/base/keeper/query_credit_types.go b/x/ecocredit/base/keeper/query_credit_types.go index 4206e68678..6f5fbec376 100644 --- a/x/ecocredit/base/keeper/query_credit_types.go +++ b/x/ecocredit/base/keeper/query_credit_types.go @@ -4,6 +4,7 @@ import ( "context" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -24,7 +25,7 @@ func (k Keeper) CreditTypes(ctx context.Context, _ *types.QueryCreditTypesReques } var creditType types.CreditType if err := ormutil.PulsarToGogoSlow(ct, &creditType); err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } creditTypes = append(creditTypes, &creditType) } diff --git a/x/ecocredit/base/keeper/query_params.go b/x/ecocredit/base/keeper/query_params.go index b6e74041ff..b189492dbf 100644 --- a/x/ecocredit/base/keeper/query_params.go +++ b/x/ecocredit/base/keeper/query_params.go @@ -4,10 +4,10 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" marketplacev1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -19,7 +19,7 @@ func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types allowlistEnabled, err := k.stateStore.ClassCreatorAllowlistTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("unable to get allowlist param: %s", err.Error()) } itr, err := k.stateStore.AllowedClassCreatorTable().List(ctx, api.AllowedClassCreatorPrimaryKey{}) @@ -40,22 +40,22 @@ func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types classFee, err := k.stateStore.ClassFeeTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("unable to get class fee param: %s", err.Error()) } classFeeCoin, ok := regentypes.ProtoCoinToCoin(classFee.Fee) if !ok { - return nil, sdkerrors.ErrInvalidCoins.Wrap("class fees") + return nil, regenerrors.ErrInternal.Wrap("failed to convert class fee") } basketFee, err := k.basketStore.BasketFeeTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("unable to get basket fee: %s", err.Error()) } basketFeeCoin, ok := regentypes.ProtoCoinToCoin(basketFee.Fee) if !ok { - return nil, sdkerrors.ErrInvalidCoins.Wrap("basket fees") + return nil, regenerrors.ErrInternal.Wrap("failed to convert basket fee") } allowedDenomsItr, err := k.marketStore.AllowedDenomTable().List(ctx, marketplacev1.AllowedDenomPrimaryKey{}) diff --git a/x/ecocredit/base/keeper/query_project_info.go b/x/ecocredit/base/keeper/query_project_info.go index b5db04add6..c3483a8327 100644 --- a/x/ecocredit/base/keeper/query_project_info.go +++ b/x/ecocredit/base/keeper/query_project_info.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -13,14 +13,14 @@ import ( func (k Keeper) Project(ctx context.Context, request *types.QueryProjectRequest) (*types.QueryProjectResponse, error) { project, err := k.stateStore.ProjectTable().GetById(ctx, request.ProjectId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) } admin := sdk.AccAddress(project.Admin) class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with key %d: %s", project.ClassKey, err.Error()) } info := types.ProjectInfo{ diff --git a/x/ecocredit/base/keeper/query_projects.go b/x/ecocredit/base/keeper/query_projects.go index 5f5e15b722..61c220601b 100644 --- a/x/ecocredit/base/keeper/query_projects.go +++ b/x/ecocredit/base/keeper/query_projects.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,7 +16,7 @@ import ( func (k Keeper) Projects(ctx context.Context, request *types.QueryProjectsRequest) (*types.QueryProjectsResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectIdIndexKey{}, ormlist.Paginate(pg)) @@ -35,7 +36,7 @@ func (k Keeper) Projects(ctx context.Context, request *types.QueryProjectsReques class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("class with key: %d", project.ClassKey) } info := types.ProjectInfo{ @@ -52,7 +53,7 @@ func (k Keeper) Projects(ctx context.Context, request *types.QueryProjectsReques pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsResponse{ diff --git a/x/ecocredit/base/keeper/query_projects_by_admin.go b/x/ecocredit/base/keeper/query_projects_by_admin.go index c96ed4f99f..c431084c9b 100644 --- a/x/ecocredit/base/keeper/query_projects_by_admin.go +++ b/x/ecocredit/base/keeper/query_projects_by_admin.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,12 +15,12 @@ import ( func (k Keeper) ProjectsByAdmin(ctx context.Context, req *types.QueryProjectsByAdminRequest) (*types.QueryProjectsByAdminResponse, error) { admin, err := sdk.AccAddressFromBech32(req.Admin) if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectAdminIndexKey{}.WithAdmin(admin), ormlist.Paginate(pg)) @@ -38,7 +38,7 @@ func (k Keeper) ProjectsByAdmin(ctx context.Context, req *types.QueryProjectsByA class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get class with key: %d: %s", project.ClassKey, err.Error()) } projects = append(projects, &types.ProjectInfo{ @@ -53,7 +53,7 @@ func (k Keeper) ProjectsByAdmin(ctx context.Context, req *types.QueryProjectsByA pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsByAdminResponse{Projects: projects, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_projects_by_admin_test.go b/x/ecocredit/base/keeper/query_projects_by_admin_test.go index 40388a4dab..54827b53d9 100644 --- a/x/ecocredit/base/keeper/query_projects_by_admin_test.go +++ b/x/ecocredit/base/keeper/query_projects_by_admin_test.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/stretchr/testify/require" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -82,4 +83,9 @@ func TestQuery_Projects_By_Admin(t *testing.T) { res, err = s.k.ProjectsByAdmin(s.ctx, &types.QueryProjectsByAdminRequest{Admin: admin2.String()}) assert.NilError(t, err) assert.Equal(t, len(res.Projects), 1) + + // query project by invalid bech32 address + _, err = s.k.ProjectsByAdmin(s.ctx, &types.QueryProjectsByAdminRequest{Admin: "address"}) + require.Error(t, err) + require.Equal(t, "decoding bech32 failed: invalid bech32 string length 7: invalid argument", err.Error()) } diff --git a/x/ecocredit/base/keeper/query_projects_by_class.go b/x/ecocredit/base/keeper/query_projects_by_class.go index d9d7904040..cf283b43f1 100644 --- a/x/ecocredit/base/keeper/query_projects_by_class.go +++ b/x/ecocredit/base/keeper/query_projects_by_class.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -16,12 +16,12 @@ import ( func (k Keeper) ProjectsByClass(ctx context.Context, request *types.QueryProjectsByClassRequest) (*types.QueryProjectsByClassResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } cInfo, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectClassKeyIdIndexKey{}.WithClassKey(cInfo.Key), ormlist.Paginate(pg)) @@ -41,7 +41,7 @@ func (k Keeper) ProjectsByClass(ctx context.Context, request *types.QueryProject class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with key: %d", project.ClassKey) } info := types.ProjectInfo{ @@ -58,7 +58,7 @@ func (k Keeper) ProjectsByClass(ctx context.Context, request *types.QueryProject pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsByClassResponse{ diff --git a/x/ecocredit/base/keeper/query_projects_by_reference_id.go b/x/ecocredit/base/keeper/query_projects_by_reference_id.go index 859efaaeda..b7c07b53eb 100644 --- a/x/ecocredit/base/keeper/query_projects_by_reference_id.go +++ b/x/ecocredit/base/keeper/query_projects_by_reference_id.go @@ -3,13 +3,11 @@ package keeper import ( "context" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -17,12 +15,12 @@ import ( // ProjectsByReferenceId queries projects by reference id. func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *types.QueryProjectsByReferenceIdRequest) (*types.QueryProjectsByReferenceIdResponse, error) { //nolint:revive,stylecheck if req.ReferenceId == "" { - return nil, status.Errorf(codes.InvalidArgument, "reference-id is empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("reference-id is empty") } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectReferenceIdIndexKey{}.WithReferenceId(req.ReferenceId), ormlist.Paginate(pg)) @@ -40,7 +38,7 @@ func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *types.QueryProje class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("class with key: %d", project.ClassKey) } info := &types.ProjectInfo{ @@ -57,7 +55,7 @@ func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *types.QueryProje pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsByReferenceIdResponse{ diff --git a/x/ecocredit/base/keeper/query_supply.go b/x/ecocredit/base/keeper/query_supply.go index 3ef5355b8d..f43f8c380b 100644 --- a/x/ecocredit/base/keeper/query_supply.go +++ b/x/ecocredit/base/keeper/query_supply.go @@ -3,8 +3,7 @@ package keeper import ( "context" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -12,12 +11,12 @@ import ( func (k Keeper) Supply(ctx context.Context, request *types.QuerySupplyRequest) (*types.QuerySupplyResponse, error) { batch, err := k.stateStore.BatchTable().GetByDenom(ctx, request.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) } supply, err := k.stateStore.BatchSupplyTable().Get(ctx, batch.Key) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf("unable to get batch supply for batch: %s", batch.Denom) } return &types.QuerySupplyResponse{ diff --git a/x/ecocredit/base/keeper/query_supply_test.go b/x/ecocredit/base/keeper/query_supply_test.go index 6adc8f81d8..c3c7413bda 100644 --- a/x/ecocredit/base/keeper/query_supply_test.go +++ b/x/ecocredit/base/keeper/query_supply_test.go @@ -6,6 +6,7 @@ import ( "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" + "github.com/stretchr/testify/require" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -27,6 +28,12 @@ func TestQuery_Supply(t *testing.T) { StartDate: nil, EndDate: nil, })) + + // supply not found + _, err := s.k.Supply(s.ctx, &types.QuerySupplyRequest{BatchDenom: batchDenom}) + require.Error(t, err) + assert.Equal(t, "unable to get batch supply for batch: C01-001-20200101-20220101-001: invalid argument", err.Error()) + assert.NilError(t, s.stateStore.BatchSupplyTable().Insert(s.ctx, &api.BatchSupply{ BatchKey: 1, TradableAmount: tradable, diff --git a/x/ecocredit/base/simulation/msg_add_credit_type.go b/x/ecocredit/base/simulation/msg_add_credit_type.go index 846b7b2ccd..c07029f851 100644 --- a/x/ecocredit/base/simulation/msg_add_credit_type.go +++ b/x/ecocredit/base/simulation/msg_add_credit_type.go @@ -6,13 +6,13 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/simulation" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/x/ecocredit" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" "github.com/regen-network/regen-ledger/x/ecocredit/simulation/utils" @@ -55,7 +55,7 @@ func SimulateMsgAddCreditType(ak ecocredit.AccountKeeper, bk ecocredit.BankKeepe Abbreviation: abbrev, }) if err != nil { - if !ormerrors.NotFound.Is(err) { + if !regenerrors.ErrNotFound.Is(err) { return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgAddCreditType, err.Error()), nil, err } } diff --git a/x/ecocredit/base/simulation/operations.go b/x/ecocredit/base/simulation/operations.go index 0acb65a3ef..39ad183922 100644 --- a/x/ecocredit/base/simulation/operations.go +++ b/x/ecocredit/base/simulation/operations.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "math/rand" - "strings" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" @@ -12,6 +11,7 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/x/ecocredit" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" baskettypes "github.com/regen-network/regen-ledger/x/ecocredit/basket/types/v1" @@ -298,7 +298,7 @@ func getRandomBatchFromProject(ctx context.Context, r *rand.Rand, qryClient type ProjectId: projectID, }) if err != nil { - if strings.Contains(err.Error(), ormerrors.NotFound.Error()) { + if regenerrors.ErrNotFound.Is(err) { return nil, simtypes.NoOpMsg(ecocredit.ModuleName, msgType, fmt.Sprintf("no credit batches for %s project", projectID)), nil } return nil, simtypes.NoOpMsg(ecocredit.ModuleName, msgType, err.Error()), err diff --git a/x/ecocredit/go.mod b/x/ecocredit/go.mod index 13957d18b4..8a6a8527c0 100644 --- a/x/ecocredit/go.mod +++ b/x/ecocredit/go.mod @@ -16,6 +16,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/regen-network/gocuke v0.6.2 github.com/regen-network/regen-ledger/api v0.8.0 + github.com/regen-network/regen-ledger/errors v0.0.0-00010101000000-000000000000 github.com/regen-network/regen-ledger/types v1.0.0 github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.1 @@ -174,3 +175,5 @@ replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alp replace github.com/regen-network/regen-ledger/types => ../../types replace github.com/regen-network/regen-ledger/api => ../../api + +replace github.com/regen-network/regen-ledger/errors => ../../errors