Some checks failed
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
Build & Push SDK Proto Builder / build (push) Has been cancelled
97 lines
3.1 KiB
Go
97 lines
3.1 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
"github.com/stretchr/testify/suite"
|
|
"go.uber.org/mock/gomock"
|
|
|
|
"cosmossdk.io/log"
|
|
sdkmath "cosmossdk.io/math"
|
|
storetypes "cosmossdk.io/store/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
"github.com/cosmos/cosmos-sdk/codec/address"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
"github.com/cosmos/cosmos-sdk/runtime"
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
|
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
|
authztestutil "github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
|
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
)
|
|
|
|
var (
|
|
granteePub = secp256k1.GenPrivKey().PubKey()
|
|
granterPub = secp256k1.GenPrivKey().PubKey()
|
|
granteeAddr = sdk.AccAddress(granteePub.Address())
|
|
granterAddr = sdk.AccAddress(granterPub.Address())
|
|
)
|
|
|
|
type GenesisTestSuite struct {
|
|
suite.Suite
|
|
|
|
ctx sdk.Context
|
|
keeper keeper.Keeper
|
|
baseApp *baseapp.BaseApp
|
|
accountKeeper *authztestutil.MockAccountKeeper
|
|
encCfg moduletestutil.TestEncodingConfig
|
|
}
|
|
|
|
func (suite *GenesisTestSuite) SetupTest() {
|
|
key := storetypes.NewKVStoreKey(keeper.StoreKey)
|
|
storeService := runtime.NewKVStoreService(key)
|
|
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
|
|
suite.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1})
|
|
suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
|
|
|
// gomock initializations
|
|
ctrl := gomock.NewController(suite.T())
|
|
suite.accountKeeper = authztestutil.NewMockAccountKeeper(ctrl)
|
|
suite.accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()
|
|
|
|
suite.baseApp = baseapp.NewBaseApp(
|
|
"authz",
|
|
log.NewNopLogger(),
|
|
testCtx.DB,
|
|
suite.encCfg.TxConfig.TxDecoder(),
|
|
)
|
|
suite.baseApp.SetCMS(testCtx.CMS)
|
|
|
|
bank.RegisterInterfaces(suite.encCfg.InterfaceRegistry)
|
|
|
|
msr := suite.baseApp.MsgServiceRouter()
|
|
msr.SetInterfaceRegistry(suite.encCfg.InterfaceRegistry)
|
|
|
|
suite.keeper = keeper.NewKeeper(storeService, suite.encCfg.Codec, msr, suite.accountKeeper)
|
|
}
|
|
|
|
func (suite *GenesisTestSuite) TestImportExportGenesis() {
|
|
coins := sdk.NewCoins(sdk.NewCoin("foo", sdkmath.NewInt(1_000)))
|
|
|
|
now := suite.ctx.BlockTime()
|
|
expires := now.Add(time.Hour)
|
|
grant := &bank.SendAuthorization{SpendLimit: coins}
|
|
err := suite.keeper.SaveGrant(suite.ctx, granteeAddr, granterAddr, grant, &expires)
|
|
suite.Require().NoError(err)
|
|
genesis := suite.keeper.ExportGenesis(suite.ctx)
|
|
|
|
// TODO, recheck!
|
|
// Clear keeper
|
|
suite.Require().NoError(suite.keeper.DeleteGrant(suite.ctx, granteeAddr, granterAddr, grant.MsgTypeURL()))
|
|
newGenesis := suite.keeper.ExportGenesis(suite.ctx)
|
|
suite.Require().NotEqual(genesis, newGenesis)
|
|
suite.Require().Empty(newGenesis)
|
|
|
|
suite.keeper.InitGenesis(suite.ctx, genesis)
|
|
newGenesis = suite.keeper.ExportGenesis(suite.ctx)
|
|
suite.Require().Equal(genesis, newGenesis)
|
|
}
|
|
|
|
func TestGenesisTestSuite(t *testing.T) {
|
|
suite.Run(t, new(GenesisTestSuite))
|
|
}
|