Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jun 13, 2024
1 parent 9cb13e9 commit b193989
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 36 deletions.
3 changes: 2 additions & 1 deletion x/claim/keeper/claim_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"testing"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

Expand All @@ -17,7 +18,7 @@ func createNClaimRecord(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.C
items := make([]types.ClaimRecord, n)
for i := range items {
items[i].Address = sample.AccAddress()
items[i].Claimable = sample.Int(r)
items[i].Claimable = sdkmath.NewInt(r.Int63())

keeper.SetClaimRecord(ctx, items[i])
}
Expand Down
3 changes: 1 addition & 2 deletions x/claim/keeper/grpc_airdrop_supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
func TestAirdropSupplyQuery(t *testing.T) {
var (
ctx, tk, _ = testkeeper.NewTestSetup(t)
wctx = sdk.WrapSDKContext(ctx)
sampleSupply = sdk.NewCoin("foo", sdkmath.NewInt(1000))
)
tk.ClaimKeeper.SetAirdropSupply(ctx, sampleSupply)
Expand All @@ -39,7 +38,7 @@ func TestAirdropSupplyQuery(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
response, err := tk.ClaimKeeper.AirdropSupply(wctx, tc.request)
response, err := tk.ClaimKeeper.AirdropSupply(ctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand Down
13 changes: 5 additions & 8 deletions x/claim/keeper/grpc_claim_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strconv"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
Expand All @@ -18,7 +17,6 @@ import (
func TestClaimRecordQuerySingle(t *testing.T) {
var (
ctx, tk, _ = testkeeper.NewTestSetup(t)
wctx = sdk.WrapSDKContext(ctx)
msgs = createNClaimRecord(tk.ClaimKeeper, ctx, 2)
)

Expand Down Expand Up @@ -55,7 +53,7 @@ func TestClaimRecordQuerySingle(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
response, err := tk.ClaimKeeper.ClaimRecord(wctx, tc.request)
response, err := tk.ClaimKeeper.ClaimRecord(ctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand All @@ -72,7 +70,6 @@ func TestClaimRecordQuerySingle(t *testing.T) {
func TestClaimRecordQueryPaginated(t *testing.T) {
var (
ctx, tk, _ = testkeeper.NewTestSetup(t)
wctx = sdk.WrapSDKContext(ctx)
msgs = createNClaimRecord(tk.ClaimKeeper, ctx, 5)
)

Expand All @@ -89,7 +86,7 @@ func TestClaimRecordQueryPaginated(t *testing.T) {
t.Run("should paginate by offset", func(t *testing.T) {
step := 2
for i := 0; i < len(msgs); i += step {
resp, err := tk.ClaimKeeper.ClaimRecordAll(wctx, request(nil, uint64(i), uint64(step), false))
resp, err := tk.ClaimKeeper.ClaimRecordAll(ctx, request(nil, uint64(i), uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.ClaimRecord), step)
require.Subset(t,
Expand All @@ -102,7 +99,7 @@ func TestClaimRecordQueryPaginated(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(msgs); i += step {
resp, err := tk.ClaimKeeper.ClaimRecordAll(wctx, request(next, 0, uint64(step), false))
resp, err := tk.ClaimKeeper.ClaimRecordAll(ctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.ClaimRecord), step)
require.Subset(t,
Expand All @@ -113,7 +110,7 @@ func TestClaimRecordQueryPaginated(t *testing.T) {
}
})
t.Run("should paginate all", func(t *testing.T) {
resp, err := tk.ClaimKeeper.ClaimRecordAll(wctx, request(nil, 0, 0, true))
resp, err := tk.ClaimKeeper.ClaimRecordAll(ctx, request(nil, 0, 0, true))
require.NoError(t, err)
require.Equal(t, len(msgs), int(resp.Pagination.Total))
require.ElementsMatch(t,
Expand All @@ -122,7 +119,7 @@ func TestClaimRecordQueryPaginated(t *testing.T) {
)
})
t.Run("should return InvalidRequest", func(t *testing.T) {
_, err := tk.ClaimKeeper.ClaimRecordAll(wctx, nil)
_, err := tk.ClaimKeeper.ClaimRecordAll(ctx, nil)
require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
})
}
4 changes: 1 addition & 3 deletions x/claim/keeper/grpc_initial_claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -15,7 +14,6 @@ import (

func TestInitialClaimQuery(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
wctx := sdk.WrapSDKContext(ctx)
item := createTestInitialClaim(tk.ClaimKeeper, ctx)
for _, tc := range []struct {
desc string
Expand All @@ -34,7 +32,7 @@ func TestInitialClaimQuery(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
response, err := tk.ClaimKeeper.InitialClaim(wctx, tc.request)
response, err := tk.ClaimKeeper.InitialClaim(ctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand Down
13 changes: 5 additions & 8 deletions x/claim/keeper/grpc_mission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
Expand All @@ -18,7 +17,6 @@ import (
func TestMissionQuerySingle(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)

wctx := sdk.WrapSDKContext(ctx)
msgs := createNMission(tk.ClaimKeeper, ctx, 2)
for _, tc := range []struct {
name string
Expand Down Expand Up @@ -47,7 +45,7 @@ func TestMissionQuerySingle(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
response, err := tk.ClaimKeeper.Mission(wctx, tc.request)
response, err := tk.ClaimKeeper.Mission(ctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand All @@ -64,7 +62,6 @@ func TestMissionQuerySingle(t *testing.T) {
func TestMissionQueryPaginated(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)

wctx := sdk.WrapSDKContext(ctx)
msgs := createNMission(tk.ClaimKeeper, ctx, 5)

request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllMissionRequest {
Expand All @@ -80,7 +77,7 @@ func TestMissionQueryPaginated(t *testing.T) {
t.Run("should paginate by offset", func(t *testing.T) {
step := 2
for i := 0; i < len(msgs); i += step {
resp, err := tk.ClaimKeeper.MissionAll(wctx, request(nil, uint64(i), uint64(step), false))
resp, err := tk.ClaimKeeper.MissionAll(ctx, request(nil, uint64(i), uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.Mission), step)
require.Subset(t,
Expand All @@ -93,7 +90,7 @@ func TestMissionQueryPaginated(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(msgs); i += step {
resp, err := tk.ClaimKeeper.MissionAll(wctx, request(next, 0, uint64(step), false))
resp, err := tk.ClaimKeeper.MissionAll(ctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.Mission), step)
require.Subset(t,
Expand All @@ -104,7 +101,7 @@ func TestMissionQueryPaginated(t *testing.T) {
}
})
t.Run("should paginate all", func(t *testing.T) {
resp, err := tk.ClaimKeeper.MissionAll(wctx, request(nil, 0, 0, true))
resp, err := tk.ClaimKeeper.MissionAll(ctx, request(nil, 0, 0, true))
require.NoError(t, err)
require.Equal(t, len(msgs), int(resp.Pagination.Total))
require.ElementsMatch(t,
Expand All @@ -113,7 +110,7 @@ func TestMissionQueryPaginated(t *testing.T) {
)
})
t.Run("should return InvalidRequest", func(t *testing.T) {
_, err := tk.ClaimKeeper.MissionAll(wctx, nil)
_, err := tk.ClaimKeeper.MissionAll(ctx, nil)
require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
})
}
4 changes: 1 addition & 3 deletions x/claim/keeper/grpc_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

testkeeper "github.com/ignite/modules/testutil/keeper"
Expand All @@ -14,11 +13,10 @@ func TestParamsQuery(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)

t.Run("should allow params get query", func(t *testing.T) {
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
tk.ClaimKeeper.SetParams(ctx, params)

response, err := tk.ClaimKeeper.Params(wctx, &types.QueryParamsRequest{})
response, err := tk.ClaimKeeper.Params(ctx, &types.QueryParamsRequest{})
require.NoError(t, err)
require.EqualValues(t, params.DecayInformation, response.Params.DecayInformation)
require.Equal(t, params.AirdropStart.Unix(), response.Params.AirdropStart.Unix())
Expand Down
4 changes: 1 addition & 3 deletions x/claim/keeper/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"

testkeeper "github.com/ignite/modules/testutil/keeper"
"github.com/ignite/modules/x/claim/keeper"
"github.com/ignite/modules/x/claim/types"
Expand All @@ -14,5 +12,5 @@ import (
func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
ctx, tk, _ := testkeeper.NewTestSetup(t)

return keeper.NewMsgServerImpl(*tk.ClaimKeeper), sdk.WrapSDKContext(ctx)
return keeper.NewMsgServerImpl(*tk.ClaimKeeper), ctx
}
16 changes: 8 additions & 8 deletions x/claim/types/mission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ func TestMission_Validate(t *testing.T) {
{
name: "should accept weigth 0",
mission: claim.Mission{
MissionID: sample.Uint64(r),
Description: sample.String(r, 30),
MissionID: uint64(r.Intn(10000)),
Description: "dummy description",
Weight: sdkmath.LegacyMustNewDecFromStr("0"),
},
valid: true,
},
{
name: "should accept weight 1",
mission: claim.Mission{
MissionID: sample.Uint64(r),
Description: sample.String(r, 30),
MissionID: uint64(r.Intn(10000)),
Description: "dummy description",
Weight: sdkmath.LegacyMustNewDecFromStr("1"),
},
valid: true,
},
{
name: "should prevent weight greater than 1",
mission: claim.Mission{
MissionID: sample.Uint64(r),
Description: sample.String(r, 30),
MissionID: uint64(r.Intn(10000)),
Description: "dummy description",
Weight: sdkmath.LegacyMustNewDecFromStr("1.0000001"),
},
valid: false,
},
{
name: "should prevent weight less than 0",
mission: claim.Mission{
MissionID: sample.Uint64(r),
Description: sample.String(r, 30),
MissionID: uint64(r.Intn(10000)),
Description: "dummy description",
Weight: sdkmath.LegacyMustNewDecFromStr("-0.0000001"),
},
valid: false,
Expand Down

0 comments on commit b193989

Please sign in to comment.