mukan-sdk/x/authz/module/abci_test.go
Mukan Erkin Törük abb1ff956e
Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
refactor: complete sovereign stack cleanup — all github.com upstream refs purged
2026-05-11 03:46:06 +03:00

105 lines
3.9 KiB
Go

package authz_test
import (
"testing"
"time"
"git.cw.tr/mukan-network/mukan-consensus/proto/tendermint/types"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"git.cw.tr/mukan-network/mukan-sdk/baseapp"
"git.cw.tr/mukan-network/mukan-sdk/codec/address"
"git.cw.tr/mukan-network/mukan-sdk/runtime"
"git.cw.tr/mukan-network/mukan-sdk/testutil"
simtestutil "git.cw.tr/mukan-network/mukan-sdk/testutil/sims"
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
moduletestutil "git.cw.tr/mukan-network/mukan-sdk/types/module/testutil"
authtypes "git.cw.tr/mukan-network/mukan-sdk/x/auth/types"
"git.cw.tr/mukan-network/mukan-sdk/x/authz"
"git.cw.tr/mukan-network/mukan-sdk/x/authz/keeper"
authzmodule "git.cw.tr/mukan-network/mukan-sdk/x/authz/module"
authztestutil "git.cw.tr/mukan-network/mukan-sdk/x/authz/testutil"
banktypes "git.cw.tr/mukan-network/mukan-sdk/x/bank/types"
)
func TestExpiredGrantsQueue(t *testing.T) {
key := storetypes.NewKVStoreKey(keeper.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
ctx := testCtx.Ctx.WithBlockHeader(types.Header{})
baseApp := baseapp.NewBaseApp(
"authz",
log.NewNopLogger(),
testCtx.DB,
encCfg.TxConfig.TxDecoder(),
)
baseApp.SetCMS(testCtx.CMS)
baseApp.SetInterfaceRegistry(encCfg.InterfaceRegistry)
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
addrs := simtestutil.CreateIncrementalAccounts(5)
granter := addrs[0]
grantee1 := addrs[1]
grantee2 := addrs[2]
grantee3 := addrs[3]
grantee4 := addrs[4]
expiration := ctx.BlockTime().AddDate(0, 1, 0)
expiration2 := expiration.AddDate(1, 0, 0)
smallCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 10))
sendAuthz := banktypes.NewSendAuthorization(smallCoins, nil)
ctrl := gomock.NewController(t)
accountKeeper := authztestutil.NewMockAccountKeeper(ctrl)
accountKeeper.EXPECT().GetAccount(gomock.Any(), granter).Return(authtypes.NewBaseAccountWithAddress(granter)).AnyTimes()
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee1).Return(authtypes.NewBaseAccountWithAddress(grantee1)).AnyTimes()
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee2).Return(authtypes.NewBaseAccountWithAddress(grantee2)).AnyTimes()
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee3).Return(authtypes.NewBaseAccountWithAddress(grantee3)).AnyTimes()
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee4).Return(authtypes.NewBaseAccountWithAddress(grantee4)).AnyTimes()
accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()
authzKeeper := keeper.NewKeeper(storeService, encCfg.Codec, baseApp.MsgServiceRouter(), accountKeeper)
save := func(grantee sdk.AccAddress, exp *time.Time) {
err := authzKeeper.SaveGrant(ctx, grantee, granter, sendAuthz, exp)
require.NoError(t, err, "Grant from %s", grantee.String())
}
save(grantee1, &expiration)
save(grantee2, &expiration)
save(grantee3, &expiration2)
save(grantee4, nil)
queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry)
authz.RegisterQueryServer(queryHelper, authzKeeper)
queryClient := authz.NewQueryClient(queryHelper)
checkGrants := func(ctx sdk.Context, expectedNum int) {
require.NoError(t, authzmodule.BeginBlocker(ctx, authzKeeper))
res, err := queryClient.GranterGrants(ctx.Context(), &authz.QueryGranterGrantsRequest{
Granter: granter.String(),
})
require.NoError(t, err)
require.NotNil(t, res)
require.Equal(t, expectedNum, len(res.Grants))
}
checkGrants(ctx, 4)
// expiration is exclusive!
ctx = ctx.WithBlockTime(expiration)
checkGrants(ctx, 4)
ctx = ctx.WithBlockTime(expiration.AddDate(0, 0, 1))
checkGrants(ctx, 2)
ctx = ctx.WithBlockTime(expiration2.AddDate(0, 0, 1))
checkGrants(ctx, 1)
}