Skip to content

Commit

Permalink
Merge pull request #294 from comdex-official/locker_unit_tests
Browse files Browse the repository at this point in the history
Added TokenMint unit tests
  • Loading branch information
dheerajkd30 authored Jun 29, 2022
2 parents ffe2c3f + d27a6dd commit a9a5bb3
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 28 deletions.
10 changes: 5 additions & 5 deletions x/auction/keeper/dutch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ func (s *KeeperTestSuite) TestLinearPriceFunction() {
tau := sdk.NewIntFromUint64(60)
dur := sdk.NewInt(0)
for n := 0; n <= 60; n++ {
fmt.Println("top tau dur seconds")
fmt.Println(top, tau, dur)
fmt.Println("price")
price := getPriceFromLinearDecreaseFunction(top, tau, dur)
fmt.Println(price)
//fmt.Println("top tau dur seconds")
//fmt.Println(top, tau, dur)
//fmt.Println("price")
//price := getPriceFromLinearDecreaseFunction(top, tau, dur)
//fmt.Println(price)
dur = dur.Add(sdk.NewInt(1))

}
Expand Down
6 changes: 3 additions & 3 deletions x/collector/keeper/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func (s *KeeperTestSuite) AddAppAsset() {
{Name: "CMDX",
Denom: "ucmdx",
Decimals: 1000000,
IsOnchain: true}, {Name: "CMST",
IsOnChain: true}, {Name: "CMST",
Denom: "ucmst",
Decimals: 1000000,
IsOnchain: true}, {Name: "HARBOR",
IsOnChain: true}, {Name: "HARBOR",
Denom: "uharbor",
Decimals: 1000000,
IsOnchain: true},
IsOnChain: true},
}
err = assetKeeper.AddAssetRecords(*ctx, msg2...)
s.Require().NoError(err)
Expand Down
104 changes: 104 additions & 0 deletions x/tokenmint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package keeper_test

import (
"fmt"
collectorTypes "github.com/comdex-official/comdex/x/collector/types"
"time"

"github.com/stretchr/testify/suite"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

chain "github.com/comdex-official/comdex/app"
assetKeeper "github.com/comdex-official/comdex/x/asset/keeper"
auctionKeeper "github.com/comdex-official/comdex/x/auction/keeper"
collectorKeeper "github.com/comdex-official/comdex/x/collector/keeper"
tokenmintKeeper "github.com/comdex-official/comdex/x/tokenmint/keeper"
tokenmintTypes "github.com/comdex-official/comdex/x/tokenmint/types"
)

type KeeperTestSuite struct {
suite.Suite

app *chain.App
ctx sdk.Context
assetKeeper assetKeeper.Keeper
collectorKeeper collectorKeeper.Keeper
auctionKeeper auctionKeeper.Keeper
tokenmintKeeper tokenmintKeeper.Keeper
querier tokenmintKeeper.QueryServer
msgServer tokenmintTypes.MsgServer
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (s *KeeperTestSuite) SetupTest() {
s.app = chain.Setup(false)
s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{})
s.collectorKeeper = s.app.CollectorKeeper
s.assetKeeper = s.app.AssetKeeper
s.auctionKeeper = s.app.AuctionKeeper
s.tokenmintKeeper = s.app.TokenmintKeeper
s.querier = tokenmintKeeper.QueryServer{Keeper: s.tokenmintKeeper}
s.msgServer = tokenmintKeeper.NewMsgServer(s.tokenmintKeeper)
}

//
//// Below are just shortcuts to frequently-used functions.
//func (s *KeeperTestSuite) getBalances(addr sdk.AccAddress) sdk.Coins {
// return s.app.bankKeeper.GetAllBalances(s.ctx, addr)
//}
//
func (s *KeeperTestSuite) getBalance(addr string, denom string) (coin sdk.Coin, err error) {
addr1, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return coin, err
}
return s.app.BankKeeper.GetBalance(s.ctx, addr1, denom), nil
}

//
//func (s *KeeperTestSuite) sendCoins(fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) {
// s.T().Helper()
// err := s.app.bankKeeper.SendCoins(s.ctx, fromAddr, toAddr, amt)
// s.Require().NoError(err)
//}
//
//func (s *KeeperTestSuite) nextBlock() {
// liquidity.EndBlocker(s.ctx, s.keeper)
// liquidity.BeginBlocker(s.ctx, s.keeper)
//}
//
//// Below are useful helpers to write test code easily.
//func (s *KeeperTestSuite) addr(addrNum int) sdk.AccAddress {
// addr := make(sdk.AccAddress, 20)
// binary.PutVarint(addr, int64(addrNum))
// return addr
//}

func (s *KeeperTestSuite) fundAddr(addr string, amt sdk.Coin) {
s.T().Helper()
err := s.app.BankKeeper.MintCoins(s.ctx, collectorTypes.ModuleName, sdk.NewCoins(amt))
s.Require().NoError(err)
addr1, err := sdk.AccAddressFromBech32(addr)
err = s.app.BankKeeper.SendCoinsFromModuleToAccount(s.ctx, collectorTypes.ModuleName, addr1, sdk.NewCoins(amt))
s.Require().NoError(err)
}

func (s *KeeperTestSuite) advanceseconds(dur int64) {
s.ctx = s.ctx.WithBlockTime(s.ctx.BlockTime().Add(time.Second * time.Duration(dur)))
fmt.Println(s.ctx.BlockTime())
}

// ParseCoins parses and returns sdk.Coins.
func ParseCoin(s string) sdk.Coin {
coins, err := sdk.ParseCoinNormalized(s)
if err != nil {
panic(err)
}
return coins
}
Loading

0 comments on commit a9a5bb3

Please sign in to comment.