Skip to content

Commit

Permalink
Merge pull request #161 from tellor-io/caleb-testing
Browse files Browse the repository at this point in the history
Tested Mint Module
  • Loading branch information
themandalore authored Jun 5, 2024
2 parents 92059af + 98c256c commit 89b0180
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 25 deletions.
5 changes: 3 additions & 2 deletions testutil/keeper/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion x/mint/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
118 changes: 96 additions & 22 deletions x/mint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 8 additions & 0 deletions x/oracle/keeper/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 89b0180

Please sign in to comment.