From 215241edd9a2e09418bbf80fcd59d19d747b9fc1 Mon Sep 17 00:00:00 2001 From: rhuairahrighairigh Date: Thu, 5 Dec 2019 13:53:28 +0000 Subject: [PATCH] update auction module tests --- x/auction/abci_test.go | 45 ++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/x/auction/abci_test.go b/x/auction/abci_test.go index 2fb36bda..7d485335 100644 --- a/x/auction/abci_test.go +++ b/x/auction/abci_test.go @@ -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...) }