diff --git a/testutil/keeper/mint.go b/testutil/keeper/mint.go index bbabda64b..df01cb9a5 100644 --- a/testutil/keeper/mint.go +++ b/testutil/keeper/mint.go @@ -22,8 +22,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -func MintKeeper(tb testing.TB) (keeper.Keeper, *mocks.AccountKeeper, sdk.Context) { +func MintKeeper(tb testing.TB) (keeper.Keeper, *mocks.AccountKeeper, *mocks.BankKeeper, sdk.Context) { tb.Helper() + storeKey := storetypes.NewKVStoreKey(types.StoreKey) db := tmdb.NewMemDB() stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), storemetrics.NewNoOpMetrics()) @@ -44,5 +45,5 @@ func MintKeeper(tb testing.TB) (keeper.Keeper, *mocks.AccountKeeper, sdk.Context bankKeeper, ) - return k, accountKeeper, ctx + return k, accountKeeper, bankKeeper, ctx } diff --git a/x/mint/keeper/genesis_test.go b/x/mint/keeper/genesis_test.go index 294146510..21a45024d 100644 --- a/x/mint/keeper/genesis_test.go +++ b/x/mint/keeper/genesis_test.go @@ -10,7 +10,7 @@ import ( func TestGenesis(t *testing.T) { genesisState := types.NewGenesisState("loya") - k, ak, ctx := keepertest.MintKeeper(t) + k, ak, _, ctx := keepertest.MintKeeper(t) k.InitGenesis(ctx, ak, genesisState) got := k.ExportGenesis(ctx) require.NotNil(t, got) diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index 15323551e..562615275 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -1,31 +1,105 @@ package keeper_test -// import ( -// "testing" +import ( + "testing" -// "github.com/stretchr/testify/require" -// keepertest "github.com/tellor-io/layer/testutil/keeper" -// "github.com/tellor-io/layer/x/mint/types" -// ) + "github.com/stretchr/testify/suite" + "github.com/tellor-io/layer/app/config" + keepertest "github.com/tellor-io/layer/testutil/keeper" + "github.com/tellor-io/layer/x/mint/keeper" + "github.com/tellor-io/layer/x/mint/mocks" + "github.com/tellor-io/layer/x/mint/types" -// func TestNewKeeper(t *testing.T) { -// } + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" -// func TestLogger(t *testing.T) { -// } -// func TestGetMinter(t *testing.T) { -// } + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + auth "github.com/cosmos/cosmos-sdk/x/auth" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bank "github.com/cosmos/cosmos-sdk/x/bank" + staking "github.com/cosmos/cosmos-sdk/x/staking" +) -// func TestSetMinter(t *testing.T) { -// //checkAccess -// } +type KeeperTestSuite struct { + suite.Suite -// func TestMintCoins(t *testing.T) { -// //checkAccess -// } + ctx sdk.Context + mintKeeper keeper.Keeper + accountKeeper *mocks.AccountKeeper + bankKeeper *mocks.BankKeeper +} -// func TestSendCoinsToTeam(t *testing.T) { -// } +func (s *KeeperTestSuite) SetupTest() { + config.SetupConfig() -// func TestInflationaryRewards(t *testing.T) { -// } + s.mintKeeper, + s.accountKeeper, + s.bankKeeper, + s.ctx = keepertest.MintKeeper(s.T()) +} + +func (s *KeeperTestSuite) TestNewKeeper(t *testing.T) { + s.SetupTest() + + s.accountKeeper.On("GetModuleAddress", types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)) + s.accountKeeper.On("GetModuleAddress", types.MintToTeam).Return(authtypes.NewModuleAddress(types.MintToTeam)) + s.accountKeeper.On("GetModuleAddress", types.TimeBasedRewards).Return(authtypes.NewModuleAddress(types.TimeBasedRewards)) + + appCodec := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, staking.AppModuleBasic{}).Codec + keys := storetypes.NewKVStoreKeys(types.StoreKey) + + keeper := keeper.NewKeeper(appCodec, keys[types.StoreKey], s.accountKeeper, s.bankKeeper) + s.NotNil(keeper) +} + +func (s *KeeperTestSuite) TestLogger(t *testing.T) { + s.SetupTest() + + logger := s.mintKeeper.Logger(s.ctx) + s.NotNil(logger) +} + +func (s *KeeperTestSuite) TestGetMinter(t *testing.T) { + s.SetupTest() + + minter := s.mintKeeper.GetMinter(s.ctx) + s.ctx.Logger().Info("Minter: %v", minter) + + s.NotNil(minter) + s.Equal("loya", minter.BondDenom) +} + +func (s *KeeperTestSuite) TestSetMinter(t *testing.T) { + s.SetupTest() + + minter := types.NewMinter("loya") + s.mintKeeper.SetMinter(s.ctx, minter) + + returnedMinter := s.mintKeeper.GetMinter(s.ctx) + s.Equal(minter, returnedMinter) +} + +func (s *KeeperTestSuite) TestMintCoins(t *testing.T) { + s.SetupTest() + coins := sdk.NewCoins(sdk.NewCoin("loya", math.NewInt(100*1e6))) + + err := s.mintKeeper.MintCoins(s.ctx, coins) + s.NoError(err) +} + +func (s *KeeperTestSuite) TestSendCoinsToTeam(t *testing.T) { + s.SetupTest() + coins := sdk.NewCoins(sdk.NewCoin("loya", math.NewInt(100*1e6))) + + err := s.mintKeeper.SendCoinsToTeam(s.ctx, coins) + s.NoError(err) +} + +func (s *KeeperTestSuite) TestInflationaryRewards(t *testing.T) { + s.SetupTest() + coins := sdk.NewCoins(sdk.NewCoin("loya", math.NewInt(100*1e6))) + + err := s.mintKeeper.SendInflationaryRewards(s.ctx, coins) + s.NoError(err) +} diff --git a/x/oracle/keeper/aggregate_test.go b/x/oracle/keeper/aggregate_test.go index 296843f1f..7939e94c1 100644 --- a/x/oracle/keeper/aggregate_test.go +++ b/x/oracle/keeper/aggregate_test.go @@ -197,10 +197,18 @@ func (s *KeeperTestSuite) TestGetDataBefore() { jumpForward := reportedAt.Unix() + (60 * 5) queryAt := time.Unix(jumpForward, 0) + goback := reportedAt.Unix() - (60 * 5) + earlyQuery := time.Unix(goback, 0) + s.ctx = s.ctx.WithBlockTime(queryAt) retAggregate, err := s.oracleKeeper.GetDataBefore(s.ctx, qId, queryAt) s.NoError(err) s.Equal(aggregate, retAggregate) + + s.ctx = s.ctx.WithBlockTime(reportedAt) + nilAggregate, err := s.oracleKeeper.GetDataBefore(s.ctx, qId, earlyQuery) + s.Nil(nilAggregate) + s.NotNil(err) } func (s *KeeperTestSuite) TestGetCurrentValueForQueryId() {