0g-chain/x/cdp/app_test.go

56 lines
1.9 KiB
Go
Raw Normal View History

2019-12-03 14:35:40 +00:00
package cdp_test
2019-11-25 19:46:02 +00:00
import (
"testing"
2019-12-03 14:35:40 +00:00
"github.com/cosmos/cosmos-sdk/simapp"
2019-11-25 19:46:02 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
2019-12-03 14:35:40 +00:00
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/cdp"
2019-11-25 19:46:02 +00:00
)
func TestApp_CreateModifyDeleteCDP(t *testing.T) {
// Setup
2019-12-03 14:35:40 +00:00
tApp := app.NewTestApp()
privKeys, addrs := app.GeneratePrivKeyAddressPairs(1)
2019-11-25 19:46:02 +00:00
testAddr := addrs[0]
testPrivKey := privKeys[0]
2019-12-03 14:35:40 +00:00
tApp.InitializeFromGenesisStates(
2019-12-07 00:12:07 +00:00
app.NewAuthGenState(addrs, []sdk.Coins{cs(c("xrp", 100))}),
2019-12-07 01:25:25 +00:00
NewPFGenState("xrp", d("1.00")),
NewCDPGenState("xrp", d("1.5")),
2019-12-03 14:35:40 +00:00
)
// check balance
2019-12-07 01:25:25 +00:00
ctx := tApp.NewContext(false, abci.Header{})
tApp.CheckBalance(t, ctx, testAddr, cs(c("xrp", 100)))
2019-12-03 14:35:40 +00:00
tApp.EndBlock(abci.RequestEndBlock{})
tApp.Commit()
2019-11-25 19:46:02 +00:00
// Create CDP
2019-12-03 14:35:40 +00:00
msgs := []sdk.Msg{cdp.NewMsgCreateOrModifyCDP(testAddr, "xrp", i(10), i(5))}
simapp.SignCheckDeliver(t, tApp.Codec(), tApp.BaseApp, abci.Header{Height: tApp.LastBlockHeight() + 1}, msgs, []uint64{0}, []uint64{0}, true, true, testPrivKey)
2019-11-25 19:46:02 +00:00
2019-12-03 14:35:40 +00:00
// check balance
ctx = tApp.NewContext(true, abci.Header{})
tApp.CheckBalance(t, ctx, testAddr, cs(c("usdx", 5), c("xrp", 90)))
2019-11-25 19:46:02 +00:00
// Modify CDP
2019-12-03 14:35:40 +00:00
msgs = []sdk.Msg{cdp.NewMsgCreateOrModifyCDP(testAddr, "xrp", i(40), i(5))}
simapp.SignCheckDeliver(t, tApp.Codec(), tApp.BaseApp, abci.Header{Height: tApp.LastBlockHeight() + 1}, msgs, []uint64{0}, []uint64{1}, true, true, testPrivKey)
2019-11-25 19:46:02 +00:00
2019-12-03 14:35:40 +00:00
// check balance
ctx = tApp.NewContext(true, abci.Header{})
tApp.CheckBalance(t, ctx, testAddr, cs(c("usdx", 10), c("xrp", 50)))
2019-11-25 19:46:02 +00:00
// Delete CDP
2019-12-03 14:35:40 +00:00
msgs = []sdk.Msg{cdp.NewMsgCreateOrModifyCDP(testAddr, "xrp", i(-50), i(-10))}
simapp.SignCheckDeliver(t, tApp.Codec(), tApp.BaseApp, abci.Header{Height: tApp.LastBlockHeight() + 1}, msgs, []uint64{0}, []uint64{2}, true, true, testPrivKey)
2019-11-25 19:46:02 +00:00
2019-12-03 14:35:40 +00:00
// check balance
ctx = tApp.NewContext(true, abci.Header{})
tApp.CheckBalance(t, ctx, testAddr, cs(c("xrp", 100)))
2019-11-25 19:46:02 +00:00
}