2021-05-06 11:23:48 -07:00
|
|
|
package keeper_test
|
2021-01-25 08:41:30 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
2021-02-19 22:57:57 -08:00
|
|
|
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
2021-01-25 08:41:30 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
type GenesisTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
ctx sdk.Context
|
|
|
|
keeper keeper.Keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *GenesisTestSuite) SetupTest() {
|
|
|
|
checkTx := false
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(suite.T(), checkTx)
|
2021-01-25 08:41:30 -08:00
|
|
|
|
|
|
|
suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1})
|
|
|
|
suite.keeper = app.AuthzKeeper
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
granteePub = secp256k1.GenPrivKey().PubKey()
|
|
|
|
granterPub = secp256k1.GenPrivKey().PubKey()
|
|
|
|
granteeAddr = sdk.AccAddress(granteePub.Address())
|
|
|
|
granterAddr = sdk.AccAddress(granterPub.Address())
|
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *GenesisTestSuite) TestImportExportGenesis() {
|
|
|
|
coins := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1_000)))
|
|
|
|
|
2022-03-24 11:27:23 -07:00
|
|
|
now := suite.ctx.BlockTime()
|
|
|
|
expires := now.Add(time.Hour)
|
2021-02-19 22:57:57 -08:00
|
|
|
grant := &bank.SendAuthorization{SpendLimit: coins}
|
2022-03-24 11:27:23 -07:00
|
|
|
err := suite.keeper.SaveGrant(suite.ctx, granteeAddr, granterAddr, grant, &expires)
|
2021-01-25 08:41:30 -08:00
|
|
|
suite.Require().NoError(err)
|
2021-05-06 11:23:48 -07:00
|
|
|
genesis := suite.keeper.ExportGenesis(suite.ctx)
|
2021-01-25 08:41:30 -08:00
|
|
|
|
2022-03-24 11:27:23 -07:00
|
|
|
// TODO, recheck!
|
2021-01-25 08:41:30 -08:00
|
|
|
// Clear keeper
|
2021-05-06 11:23:48 -07:00
|
|
|
suite.keeper.DeleteGrant(suite.ctx, granteeAddr, granterAddr, grant.MsgTypeURL())
|
2021-01-25 08:41:30 -08:00
|
|
|
|
2021-05-06 11:23:48 -07:00
|
|
|
suite.keeper.InitGenesis(suite.ctx, genesis)
|
|
|
|
newGenesis := suite.keeper.ExportGenesis(suite.ctx)
|
2021-01-25 08:41:30 -08:00
|
|
|
suite.Require().Equal(genesis, newGenesis)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenesisTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(GenesisTestSuite))
|
|
|
|
}
|