planetmint-go/x/asset/keeper/query_address_test.go
Lorenz Herzberger 468fbb5305
402 bug asset query does not repsect lookupperiodinmin value (#405)
* chore: remove unused asset.proto and asset.pb.go files
* feat: add AssetByAddress store functionality
* fix: asset query now returns numElements passed in req
* chore: add migration for new store mechanics
* chore: set upgradehandler for assetmodule migration
* chore: removed obsolete GetCIDsByAddress function
* chore: adjust cmd usage
---------

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
2024-06-06 14:39:05 +02:00

48 lines
1.3 KiB
Go

package keeper_test
import (
"testing"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/asset/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
func TestGetNotarizedAssetByAddress(t *testing.T) {
keeper, ctx := keepertest.AssetKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
_ = createNAsset(keeper, ctx, 10)
assets, _ := keeper.GetAssetsByAddress(ctx, "plmnt_address", nil, util.SerializeUint64(3))
for _, tc := range []struct {
desc string
request *types.QueryGetCIDsByAddressRequest
response *types.QueryGetCIDsByAddressResponse
err error
}{
{
desc: "cid found",
request: &types.QueryGetCIDsByAddressRequest{Address: "plmnt_address", NumElements: 3},
response: &types.QueryGetCIDsByAddressResponse{Cids: assets},
},
{
desc: "cid not found",
request: &types.QueryGetCIDsByAddressRequest{Address: "invalid key"},
err: status.Error(codes.NotFound, "no CIDs found"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
response, err := keeper.GetCIDsByAddress(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.Equal(t, tc.response, response)
}
})
}
}