2020-01-12 15:35:34 +00:00
|
|
|
package cdp_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-30 14:23:41 +00:00
|
|
|
|
2020-01-12 15:35:34 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
|
2020-04-30 14:13:31 +00:00
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/x/cdp"
|
|
|
|
|
2020-01-12 15:35:34 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HandlerTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
ctx sdk.Context
|
|
|
|
app app.TestApp
|
|
|
|
handler sdk.Handler
|
|
|
|
keeper cdp.Keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *HandlerTestSuite) SetupTest() {
|
|
|
|
tApp := app.NewTestApp()
|
|
|
|
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
|
|
|
|
tApp.InitializeFromGenesisStates(
|
|
|
|
NewPricefeedGenStateMulti(),
|
|
|
|
NewCDPGenStateMulti(),
|
|
|
|
)
|
|
|
|
keeper := tApp.GetCDPKeeper()
|
|
|
|
suite.handler = cdp.NewHandler(keeper)
|
|
|
|
suite.app = tApp
|
|
|
|
suite.keeper = keeper
|
|
|
|
suite.ctx = ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *HandlerTestSuite) TestMsgCreateCdp() {
|
|
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(1)
|
|
|
|
ak := suite.app.GetAccountKeeper()
|
|
|
|
acc := ak.NewAccountWithAddress(suite.ctx, addrs[0])
|
|
|
|
acc.SetCoins(cs(c("xrp", 200000000), c("btc", 500000000)))
|
|
|
|
ak.SetAccount(suite.ctx, acc)
|
|
|
|
msg := cdp.NewMsgCreateCDP(
|
|
|
|
addrs[0],
|
2020-04-27 14:40:34 +00:00
|
|
|
c("xrp", 200000000),
|
|
|
|
c("usdx", 10000000),
|
2020-08-21 19:42:46 +00:00
|
|
|
"xrp-a",
|
2020-01-12 15:35:34 +00:00
|
|
|
)
|
2020-04-23 16:35:58 +00:00
|
|
|
res, err := suite.handler(suite.ctx, msg)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
suite.Require().Equal(cdp.GetCdpIDBytes(uint64(1)), res.Data)
|
2020-01-12 15:35:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *HandlerTestSuite) TestInvalidMsg() {
|
2020-04-23 16:35:58 +00:00
|
|
|
res, err := suite.handler(suite.ctx, sdk.NewTestMsg())
|
|
|
|
suite.Require().Error(err)
|
|
|
|
suite.Require().Nil(res)
|
2020-01-12 15:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandlerTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(HandlerTestSuite))
|
|
|
|
}
|