Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use KVStoreService instead of StoreKey #1028

Merged
merged 13 commits into from
Nov 25, 2024
19 changes: 12 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,12 @@ func New(
)

delayRouter := delaytypes.NewRouter()
app.DelayKeeper = delaykeeper.NewKeeper(appCodec, keys[delaytypes.StoreKey], delayRouter, app.interfaceRegistry)
app.DelayKeeper = delaykeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[delaytypes.StoreKey]),
delayRouter,
app.interfaceRegistry,
)

originalBankKeeper := bankkeeper.NewBaseKeeper(
appCodec,
Expand All @@ -425,7 +430,7 @@ func New(
app.WasmPermissionedKeeper = wasmkeeper.NewGovPermissionKeeper(&app.WasmKeeper)
app.AssetFTKeeper = assetftkeeper.NewKeeper(
appCodec,
keys[assetfttypes.StoreKey],
runtime.NewKVStoreService(keys[assetfttypes.StoreKey]),
// for the assetft we use the clear bank keeper without the assets integration to prevent cycling calls.
originalBankKeeper,
app.DelayKeeper,
Expand Down Expand Up @@ -549,14 +554,14 @@ func New(
)

app.FeeModelKeeper = feemodelkeeper.NewKeeper(
keys[feemodeltypes.StoreKey],
tkeys[feemodeltypes.TransientStoreKey],
runtime.NewKVStoreService(keys[feemodeltypes.StoreKey]),
runtime.NewTransientStoreService(tkeys[feemodeltypes.TransientStoreKey]),
appCodec,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.CustomParamsKeeper = customparamskeeper.NewKeeper(
keys[customparamstypes.StoreKey],
runtime.NewKVStoreService(keys[customparamstypes.StoreKey]),
appCodec,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
Expand All @@ -579,7 +584,7 @@ func New(
)
app.AssetNFTKeeper = assetnftkeeper.NewKeeper(
appCodec,
keys[assetnfttypes.StoreKey],
runtime.NewKVStoreService(keys[assetnfttypes.StoreKey]),
nftKeeper,
// for the assetnft we use the clear bank keeper without the assets integration
// because it interacts only with native token.
Expand Down Expand Up @@ -818,7 +823,7 @@ func New(

app.DEXKeeper = dexkeeper.NewKeeper(
appCodec,
keys[dextypes.StoreKey],
runtime.NewKVStoreService(keys[dextypes.StoreKey]),
app.AccountKeeper,
authkeeper.NewQueryServer(app.AccountKeeper),
app.AssetFTKeeper,
Expand Down
7 changes: 6 additions & 1 deletion app/upgrade/v5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
dexParams := dexKeeper.GetParams(sdkCtx)
//nolint:contextcheck // this is correct context passing.
dexParams, err := dexKeeper.GetParams(sdkCtx)
if err != nil {
return nil, err
}

Check warning on line 66 in app/upgrade/v5/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade/v5/upgrade.go#L62-L66

Added lines #L62 - L66 were not covered by tests
// 10core
dexParams.OrderReserve = sdk.NewInt64Coin(chosenNetwork.Denom(), 10_000_000)
//nolint:contextcheck // this is correct context passing.

Check warning on line 69 in app/upgrade/v5/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade/v5/upgrade.go#L69

Added line #L69 was not covered by tests
if err = dexKeeper.SetParams(sdkCtx, dexParams); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion build/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ replace (
require (
github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240321120602-0a9c50facc68
github.com/CoreumFoundation/coreum/v5 v5.0.0-20241022051641-b49ec5faa621
github.com/CoreumFoundation/crust v0.0.0-20241119103533-4a2dd90bbd7c
github.com/CoreumFoundation/crust v0.0.0-20241121173755-aee1cf8f8254
github.com/iancoleman/strcase v0.3.0
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.39.0
Expand Down
4 changes: 2 additions & 2 deletions build/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240321120602-0a9c50facc68 h1:Tb9avuSQW3smVGrUnDh/Y+ML4eK802UsvJNZHsBgOGg=
github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240321120602-0a9c50facc68/go.mod h1:VD93vCHkxYaT/RhOesXTFgd/GQDW54tr0BqGi5JU1c0=
github.com/CoreumFoundation/crust v0.0.0-20241119103533-4a2dd90bbd7c h1:WOM8Nu9APDJayYpF7vSO8ZUmossqXo0VQB92q8f7BU4=
github.com/CoreumFoundation/crust v0.0.0-20241119103533-4a2dd90bbd7c/go.mod h1:DC2Jq9oOJgDccdSqwxggqoFJ+EMn1wl8hMXAnnK4DSs=
github.com/CoreumFoundation/crust v0.0.0-20241121173755-aee1cf8f8254 h1:W1gJa+DVmhz1qc3Am0NS326Z1lVaspN47Qrz0RiKDYM=
github.com/CoreumFoundation/crust v0.0.0-20241121173755-aee1cf8f8254/go.mod h1:DC2Jq9oOJgDccdSqwxggqoFJ+EMn1wl8hMXAnnK4DSs=
github.com/CosmWasm/wasmd v0.53.0 h1:kdaoAi20bIb4VCsxw9pRaT2g5PpIp82Wqrr9DRVN9ao=
github.com/CosmWasm/wasmd v0.53.0/go.mod h1:FJl/aWjdpGof3usAMFQpDe07Rkx77PUzp0cygFMOvtw=
github.com/CosmWasm/wasmvm/v2 v2.1.2 h1:GkJ5bAsRlLHfIQVg/FY1VHwLyBwlCjAhDea0B8L+e20=
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ github.com/CoreumFoundation/crust v0.0.0-20240829115043-b19e0fee4b1f/go.mod h1:a
github.com/CoreumFoundation/crust v0.0.0-20240910084945-51add516ee39/go.mod h1:jl7aUqRGQj20pctlDXGs64EZJa8g1jtxDiQOCkxx9Gs=
github.com/CoreumFoundation/crust v0.0.0-20240913053503-d54f466836c9/go.mod h1:E9Gyav98jDtWqIr+gAHu9onNQOFf/SGFsYhwbWtO87M=
github.com/CoreumFoundation/crust v0.0.0-20241008134118-a7bc074eff93/go.mod h1:rRKCkQ1UpqmKUCsL6XCFQZCo0OXLRVNWCL9h4gt+pq4=
github.com/CoreumFoundation/crust v0.0.0-20241121173755-aee1cf8f8254/go.mod h1:DC2Jq9oOJgDccdSqwxggqoFJ+EMn1wl8hMXAnnK4DSs=
github.com/CosmWasm/wasmvm/v2 v2.0.0/go.mod h1:su9lg5qLr7adV95eOfzjZWkGiky8WNaNIHDr7Fpu7Ck=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
Expand Down
23 changes: 17 additions & 6 deletions x/asset/ft/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@
URIHash: token.URIHash,
}

k.SetDefinition(ctx, issuer, subunit, definition)
if err := k.SetDefinition(ctx, issuer, subunit, definition); err != nil {
panic(err)

Check warning on line 40 in x/asset/ft/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/genesis.go#L40

Added line #L40 was not covered by tests
}

err = k.SetSymbol(ctx, token.Symbol, issuer)
if err != nil {
if err := k.SetSymbol(ctx, token.Symbol, issuer); err != nil {
panic(err)
}

if token.GloballyFrozen {
k.SetGlobalFreeze(ctx, token.Denom, true)
if err := k.SetGlobalFreeze(ctx, token.Denom, true); err != nil {
panic(err)

Check warning on line 49 in x/asset/ft/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/genesis.go#L49

Added line #L49 was not covered by tests
}
}
}

Expand Down Expand Up @@ -89,7 +93,9 @@
}

for _, settings := range genState.DEXSettings {
k.SetDEXSettings(ctx, settings.Denom, settings.DEXSettings)
if err := k.SetDEXSettings(ctx, settings.Denom, settings.DEXSettings); err != nil {
panic(err)

Check warning on line 97 in x/asset/ft/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/genesis.go#L97

Added line #L97 was not covered by tests
}
}
}

Expand Down Expand Up @@ -137,8 +143,13 @@
panic(err)
}

params, err := k.GetParams(ctx)
if err != nil {
panic(err)

Check warning on line 148 in x/asset/ft/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/genesis.go#L148

Added line #L148 was not covered by tests
}

return &types.GenesisState{
Params: k.GetParams(ctx),
Params: params,
Tokens: tokens,
FrozenBalances: frozenBalances,
WhitelistedBalances: whitelistedBalances,
Expand Down
3 changes: 2 additions & 1 deletion x/asset/ft/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ func TestInitAndExportGenesis(t *testing.T) {

// params

params := ftKeeper.GetParams(ctx)
params, err := ftKeeper.GetParams(ctx)
requireT.NoError(err)
assertT.EqualValues(types.DefaultParams(), params)

// token definitions
Expand Down
3 changes: 2 additions & 1 deletion x/asset/ft/keeper/before_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"

Expand All @@ -34,7 +35,7 @@ func TestApplyRate(t *testing.T) {
issuer := genAccount()
dummyAddress := genAccount()
key := storetypes.NewKVStoreKey(types.StoreKey)
assetFTKeeper := assetftkeeper.NewKeeper(nil, key, nil, nil, nil, nil, nil, "")
assetFTKeeper := assetftkeeper.NewKeeper(nil, runtime.NewKVStoreService(key), nil, nil, nil, nil, nil, "")

testCases := []struct {
name string
Expand Down
33 changes: 23 additions & 10 deletions x/asset/ft/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
//
//nolint:interfacebloat // breaking down this interface is not beneficial.
type QueryKeeper interface {
GetParams(ctx sdk.Context) types.Params
GetParams(ctx sdk.Context) (types.Params, error)
GetIssuerTokens(
ctx sdk.Context,
issuer sdk.AccAddress,
pagination *query.PageRequest,
) ([]types.Token, *query.PageResponse, error)
GetToken(ctx sdk.Context, denom string) (types.Token, error)
GetTokenUpgradeStatuses(ctx sdk.Context, denom string) types.TokenUpgradeStatuses
GetTokenUpgradeStatuses(ctx sdk.Context, denom string) (types.TokenUpgradeStatuses, error)
GetFrozenBalances(
ctx sdk.Context,
addr sdk.AccAddress,
pagination *query.PageRequest,
) (sdk.Coins, *query.PageResponse, error)
GetFrozenBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetFrozenBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) (sdk.Coin, error)
GetWhitelistedBalances(
ctx sdk.Context,
addr sdk.AccAddress,
Expand Down Expand Up @@ -64,9 +64,11 @@

// Params queries the parameters of x/asset/ft module.
func (qs QueryService) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
return &types.QueryParamsResponse{
Params: qs.keeper.GetParams(sdk.UnwrapSDKContext(ctx)),
}, nil
params, err := qs.keeper.GetParams(sdk.UnwrapSDKContext(ctx))
if err != nil {
return nil, err
}

Check warning on line 70 in x/asset/ft/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/keeper/grpc_query.go#L69-L70

Added lines #L69 - L70 were not covered by tests
return &types.QueryParamsResponse{Params: params}, nil
}

// Tokens returns fungible tokens query result.
Expand Down Expand Up @@ -103,8 +105,10 @@
ctx context.Context,
req *types.QueryTokenUpgradeStatusesRequest,
) (*types.QueryTokenUpgradeStatusesResponse, error) {
tokenUpgradeStatuses := qs.keeper.GetTokenUpgradeStatuses(sdk.UnwrapSDKContext(ctx), req.GetDenom())

tokenUpgradeStatuses, err := qs.keeper.GetTokenUpgradeStatuses(sdk.UnwrapSDKContext(ctx), req.GetDenom())
if err != nil {
return nil, err
}

Check warning on line 111 in x/asset/ft/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/keeper/grpc_query.go#L110-L111

Added lines #L110 - L111 were not covered by tests
return &types.QueryTokenUpgradeStatusesResponse{
Statuses: tokenUpgradeStatuses,
}, nil
Expand All @@ -128,10 +132,16 @@
).Amount

sdkCtx := sdk.UnwrapSDKContext(ctx)

frozenBalance, err := qs.keeper.GetFrozenBalance(sdkCtx, account, denom)
if err != nil {
return nil, err
}

Check warning on line 139 in x/asset/ft/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/keeper/grpc_query.go#L138-L139

Added lines #L138 - L139 were not covered by tests

return &types.QueryBalanceResponse{
Balance: qs.bankKeeper.GetBalance(ctx, account, denom).Amount,
Whitelisted: qs.keeper.GetWhitelistedBalance(sdkCtx, account, denom).Amount,
Frozen: qs.keeper.GetFrozenBalance(sdkCtx, account, denom).Amount,
Frozen: frozenBalance.Amount,
Locked: vestingLocked.Add(dexLocked),
LockedInVesting: vestingLocked,
LockedInDEX: dexLocked,
Expand Down Expand Up @@ -170,7 +180,10 @@
if err != nil {
return nil, sdkerrors.Wrap(cosmoserrors.ErrInvalidAddress, "invalid account address")
}
balance := qs.keeper.GetFrozenBalance(ctx, account, req.GetDenom())
balance, err := qs.keeper.GetFrozenBalance(ctx, account, req.GetDenom())
if err != nil {
return nil, err
}

Check warning on line 186 in x/asset/ft/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/asset/ft/keeper/grpc_query.go#L185-L186

Added lines #L185 - L186 were not covered by tests

return &types.QueryFrozenBalanceResponse{
Balance: balance,
Expand Down
2 changes: 1 addition & 1 deletion x/asset/ft/keeper/invariant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestBankMetadataExistInvariant(t *testing.T) {
requireT.NoError(err)

definition.Denom = "invalid"
ftKeeper.SetDefinition(ctx, settings1.Issuer, settings1.Subunit, definition)
requireT.NoError(ftKeeper.SetDefinition(ctx, settings1.Issuer, settings1.Subunit, definition))

// check that state is broken now
_, isBroken = keeper.BankMetadataExistInvariant(ftKeeper)(ctx)
Expand Down
Loading