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 b193989 commit 4734708
Show file tree
Hide file tree
Showing 29 changed files with 327 additions and 291 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ require (
cosmossdk.io/client/v2 v2.0.0-beta.1
cosmossdk.io/core v0.11.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
cosmossdk.io/tools/confix v0.1.1
cosmossdk.io/x/feegrant v0.1.0
Expand All @@ -25,6 +27,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.7
github.com/cosmos/gogoproto v1.4.12
github.com/golang/protobuf v1.5.4
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
Expand All @@ -33,17 +36,18 @@ require (
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
golang.org/x/tools v0.20.0
google.golang.org/genproto/googleapis/api v0.0.0-20240325203815-454cdb8f5daa
google.golang.org/grpc v1.63.2
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v2 v2.4.0
)

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240221180331-f05a6f4403ce.1 // indirect
connectrpc.com/connect v1.16.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down Expand Up @@ -114,7 +118,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/cel-go v0.20.1 // indirect
Expand Down Expand Up @@ -215,11 +218,8 @@ require (
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240325203815-454cdb8f5daa // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand Down
19 changes: 19 additions & 0 deletions x/claim/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
ParamSet = paramtypes.ParamSet

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
Get(ctx sdk.Context, key []byte, ptr any)
}
)
7 changes: 3 additions & 4 deletions x/claim/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

testkeeper "github.com/ignite/modules/testutil/keeper"
"github.com/ignite/modules/testutil/nullify"
"github.com/ignite/modules/testutil/sample"
"github.com/ignite/modules/x/claim"
Expand Down Expand Up @@ -42,11 +41,11 @@ func TestGenesis(t *testing.T) {
// this line is used by starport scaffolding # genesis/test/state
}

ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

t.Run("should allow import and export of genesis", func(t *testing.T) {
claim.InitGenesis(ctx, *tk.ClaimKeeper, genesisState)
got := claim.ExportGenesis(ctx, *tk.ClaimKeeper)
claim.InitGenesis(ctx, *tk, genesisState)
got := claim.ExportGenesis(ctx, *tk)
require.NotNil(t, got)

nullify.Fill(&genesisState)
Expand Down
4 changes: 2 additions & 2 deletions x/claim/keeper/airdrop_supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (k Keeper) EndAirdrop(goCtx context.Context) error {
return nil
}

decayInfo := k.DecayInformation(ctx)
if decayInfo.Enabled && ctx.BlockTime().After(decayInfo.DecayEnd) {
params := k.GetParams(ctx)
if params.DecayInformation.Enabled && ctx.BlockTime().After(params.DecayInformation.DecayEnd) {
err := k.distrKeeper.FundCommunityPool(
ctx,
sdk.NewCoins(airdropSupply),
Expand Down
35 changes: 17 additions & 18 deletions x/claim/keeper/airdrop_supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

testkeeper "github.com/ignite/modules/testutil/keeper"
"github.com/ignite/modules/testutil/nullify"
claim "github.com/ignite/modules/x/claim/types"
)

func TestAirdropSupplyGet(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

t.Run("should allow get", func(t *testing.T) {
sampleSupply := sdk.NewCoin("foo", sdkmath.NewInt(1000))
tk.ClaimKeeper.SetAirdropSupply(ctx, sampleSupply)
tk.SetAirdropSupply(ctx, sampleSupply)

rst, found := tk.ClaimKeeper.GetAirdropSupply(ctx)
rst, found := tk.GetAirdropSupply(ctx)
require.True(t, found)
require.Equal(t,
nullify.Fill(&sampleSupply),
Expand All @@ -30,22 +29,22 @@ func TestAirdropSupplyGet(t *testing.T) {
}

func TestAirdropSupplyRemove(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

t.Run("should allow remove", func(t *testing.T) {
tk.ClaimKeeper.SetAirdropSupply(ctx, sdk.NewCoin("foo", sdkmath.NewInt(1000)))
_, found := tk.ClaimKeeper.GetAirdropSupply(ctx)
tk.SetAirdropSupply(ctx, sdk.NewCoin("foo", sdkmath.NewInt(1000)))
_, found := tk.GetAirdropSupply(ctx)
require.True(t, found)
tk.ClaimKeeper.RemoveAirdropSupply(ctx)
_, found = tk.ClaimKeeper.GetAirdropSupply(ctx)
tk.RemoveAirdropSupply(ctx)
_, found = tk.GetAirdropSupply(ctx)
require.False(t, found)
})
}

func TestKeeper_InitializeAirdropSupply(t *testing.T) {
// TODO: use mock for bank module to test critical errors
// https://github.com/ignite/modules/issues/13
ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

tests := []struct {
name string
Expand All @@ -70,10 +69,10 @@ func TestKeeper_InitializeAirdropSupply(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tk.ClaimKeeper.InitializeAirdropSupply(ctx, tt.airdropSupply)
err := tk.InitializeAirdropSupply(ctx, tt.airdropSupply)
require.NoError(t, err)

airdropSupply, found := tk.ClaimKeeper.GetAirdropSupply(ctx)
airdropSupply, found := tk.GetAirdropSupply(ctx)
require.True(t, found)
require.True(t, airdropSupply.IsEqual(tt.airdropSupply))

Expand All @@ -88,7 +87,7 @@ func TestKeeper_InitializeAirdropSupply(t *testing.T) {
}

func TestEndAirdrop(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

tests := []struct {
name string
Expand Down Expand Up @@ -131,14 +130,14 @@ func TestEndAirdrop(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tk.ClaimKeeper.InitializeAirdropSupply(ctx, tt.airdropSupply)
err := tk.InitializeAirdropSupply(ctx, tt.airdropSupply)
require.NoError(t, err)

params := tk.ClaimKeeper.GetParams(ctx)
params := tk.GetParams(ctx)
params.DecayInformation = tt.decayInfo
tk.ClaimKeeper.SetParams(ctx, params)
tk.SetParams(ctx, params)

err = tk.ClaimKeeper.EndAirdrop(ctx)
err = tk.EndAirdrop(ctx)
require.NoError(t, err)
if tt.wantDistribute {
feePool := tk.DistrKeeper.GetFeePool(ctx)
Expand All @@ -148,7 +147,7 @@ func TestEndAirdrop(t *testing.T) {
}
}

airdropSupply, found := tk.ClaimKeeper.GetAirdropSupply(ctx)
airdropSupply, found := tk.GetAirdropSupply(ctx)
require.True(t, found)
require.Equal(t, tt.expectedSupply, airdropSupply)
})
Expand Down
21 changes: 10 additions & 11 deletions x/claim/keeper/claim_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

testkeeper "github.com/ignite/modules/testutil/keeper"
"github.com/ignite/modules/testutil/nullify"
"github.com/ignite/modules/testutil/sample"
"github.com/ignite/modules/x/claim/keeper"
Expand All @@ -26,12 +25,12 @@ func createNClaimRecord(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.C
}

func TestClaimRecordGet(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

t.Run("should allow get", func(t *testing.T) {
items := createNClaimRecord(tk.ClaimKeeper, ctx, 10)
items := createNClaimRecord(tk, ctx, 10)
for _, item := range items {
rst, found := tk.ClaimKeeper.GetClaimRecord(ctx,
rst, found := tk.GetClaimRecord(ctx,
item.Address,
)
require.True(t, found)
Expand All @@ -44,15 +43,15 @@ func TestClaimRecordGet(t *testing.T) {
}

func TestClaimRecordRemove(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

t.Run("should allow remove", func(t *testing.T) {
items := createNClaimRecord(tk.ClaimKeeper, ctx, 10)
items := createNClaimRecord(tk, ctx, 10)
for _, item := range items {
tk.ClaimKeeper.RemoveClaimRecord(ctx,
tk.RemoveClaimRecord(ctx,
item.Address,
)
_, found := tk.ClaimKeeper.GetClaimRecord(ctx,
_, found := tk.GetClaimRecord(ctx,
item.Address,
)
require.False(t, found)
Expand All @@ -61,13 +60,13 @@ func TestClaimRecordRemove(t *testing.T) {
}

func TestClaimRecordGetAll(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
ctx, tk := createClaimKeeper(t)

t.Run("should allow get all", func(t *testing.T) {
items := createNClaimRecord(tk.ClaimKeeper, ctx, 10)
items := createNClaimRecord(tk, ctx, 10)
require.ElementsMatch(t,
nullify.Fill(items),
nullify.Fill(tk.ClaimKeeper.GetAllClaimRecord(ctx)),
nullify.Fill(tk.GetAllClaimRecord(ctx)),
)
})
}
12 changes: 5 additions & 7 deletions x/claim/keeper/grpc_airdrop_supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

testkeeper "github.com/ignite/modules/testutil/keeper"
"github.com/ignite/modules/testutil/nullify"
"github.com/ignite/modules/x/claim/types"
)

func TestAirdropSupplyQuery(t *testing.T) {
var (
ctx, tk, _ = testkeeper.NewTestSetup(t)
sampleSupply = sdk.NewCoin("foo", sdkmath.NewInt(1000))
)
tk.ClaimKeeper.SetAirdropSupply(ctx, sampleSupply)
ctx, tk := createClaimKeeper(t)
sampleSupply := sdk.NewCoin("foo", sdkmath.NewInt(1000))

tk.SetAirdropSupply(ctx, sampleSupply)

for _, tc := range []struct {
name string
Expand All @@ -38,7 +36,7 @@ func TestAirdropSupplyQuery(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
response, err := tk.ClaimKeeper.AirdropSupply(ctx, tc.request)
response, err := tk.AirdropSupply(ctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand Down
23 changes: 9 additions & 14 deletions x/claim/keeper/grpc_claim_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

testkeeper "github.com/ignite/modules/testutil/keeper"
"github.com/ignite/modules/testutil/nullify"
"github.com/ignite/modules/x/claim/types"
)

func TestClaimRecordQuerySingle(t *testing.T) {
var (
ctx, tk, _ = testkeeper.NewTestSetup(t)
msgs = createNClaimRecord(tk.ClaimKeeper, ctx, 2)
)
ctx, tk := createClaimKeeper(t)
msgs := createNClaimRecord(tk, ctx, 2)

for _, tc := range []struct {
name string
Expand Down Expand Up @@ -53,7 +50,7 @@ func TestClaimRecordQuerySingle(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
response, err := tk.ClaimKeeper.ClaimRecord(ctx, tc.request)
response, err := tk.ClaimRecord(ctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand All @@ -68,10 +65,8 @@ func TestClaimRecordQuerySingle(t *testing.T) {
}

func TestClaimRecordQueryPaginated(t *testing.T) {
var (
ctx, tk, _ = testkeeper.NewTestSetup(t)
msgs = createNClaimRecord(tk.ClaimKeeper, ctx, 5)
)
ctx, tk := createClaimKeeper(t)
msgs := createNClaimRecord(tk, ctx, 5)

request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllClaimRecordRequest {
return &types.QueryAllClaimRecordRequest{
Expand All @@ -86,7 +81,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(ctx, request(nil, uint64(i), uint64(step), false))
resp, err := tk.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 @@ -99,7 +94,7 @@ func TestClaimRecordQueryPaginated(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(msgs); i += step {
resp, err := tk.ClaimKeeper.ClaimRecordAll(ctx, request(next, 0, uint64(step), false))
resp, err := tk.ClaimRecordAll(ctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.ClaimRecord), step)
require.Subset(t,
Expand All @@ -110,7 +105,7 @@ func TestClaimRecordQueryPaginated(t *testing.T) {
}
})
t.Run("should paginate all", func(t *testing.T) {
resp, err := tk.ClaimKeeper.ClaimRecordAll(ctx, request(nil, 0, 0, true))
resp, err := tk.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 @@ -119,7 +114,7 @@ func TestClaimRecordQueryPaginated(t *testing.T) {
)
})
t.Run("should return InvalidRequest", func(t *testing.T) {
_, err := tk.ClaimKeeper.ClaimRecordAll(ctx, nil)
_, err := tk.ClaimRecordAll(ctx, nil)
require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
})
}
Loading

0 comments on commit 4734708

Please sign in to comment.