update auction module tests

This commit is contained in:
rhuairahrighairigh 2019-12-05 13:53:28 +00:00
parent ab8331f90a
commit 215241edd9

View File

@ -1,4 +1,4 @@
package auction
package auction_test
import (
"testing"
@ -6,23 +6,42 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/auction"
)
func TestKeeper_EndBlocker(t *testing.T) {
// setup keeper and auction
mapp, keeper, addresses, _ := setUpMockApp()
header := abci.Header{Height: mapp.LastBlockHeight() + 1}
mapp.BeginBlock(abci.RequestBeginBlock{Header: header})
ctx := mapp.BaseApp.NewContext(false, header)
// Setup
_, addrs := app.GeneratePrivKeyAddressPairs(1)
seller := addrs[0]
seller := addresses[0]
keeper.StartForwardAuction(ctx, seller, sdk.NewInt64Coin("token1", 20), sdk.NewInt64Coin("token2", 0))
tApp := app.NewTestApp()
authGenState := tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100))})
tApp.InitializeFromGenesisStates(authGenState)
// run the endblocker, simulating a block height after auction expiry
expiryBlock := ctx.BlockHeight() + int64(DefaultMaxAuctionDuration)
EndBlocker(ctx.WithBlockHeight(expiryBlock), keeper)
ctx := tApp.NewContext(true, abci.Header{})
keeper := tApp.GetAuctionKeeper()
// check auction has been closed
_, found := keeper.GetAuction(ctx, 0)
auctionID, err := keeper.StartForwardAuction(ctx, seller, c("token1", 20), c("token2", 0))
require.NoError(t, err)
// Run the endblocker, simulating a block height just before auction expiry
preExpiryHeight := ctx.BlockHeight() + int64(auction.DefaultMaxAuctionDuration) - 1
auction.EndBlocker(ctx.WithBlockHeight(preExpiryHeight), keeper)
// Check auction has not been closed yet
_, found := keeper.GetAuction(ctx, auctionID)
require.True(t, found)
// Run the endblocker, simulating a block height just after auction expiry
expiryHeight := preExpiryHeight + 1
auction.EndBlocker(ctx.WithBlockHeight(expiryHeight), keeper)
// Check auction has been closed
_, found = keeper.GetAuction(ctx, auctionID)
require.False(t, found)
}
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) }