0g-chain/x/auction/abci_test.go

48 lines
1.5 KiB
Go
Raw Normal View History

2019-12-05 13:53:28 +00:00
package auction_test
2019-11-25 19:46:02 +00:00
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
2019-12-05 13:53:28 +00:00
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/auction"
2019-11-25 19:46:02 +00:00
)
func TestKeeper_EndBlocker(t *testing.T) {
2019-12-05 13:53:28 +00:00
// Setup
_, addrs := app.GeneratePrivKeyAddressPairs(1)
seller := addrs[0]
tApp := app.NewTestApp()
authGenState := tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100))})
tApp.InitializeFromGenesisStates(authGenState)
ctx := tApp.NewContext(true, abci.Header{})
keeper := tApp.GetAuctionKeeper()
2019-11-25 19:46:02 +00:00
2019-12-05 13:53:28 +00:00
auctionID, err := keeper.StartForwardAuction(ctx, seller, c("token1", 20), c("token2", 0))
require.NoError(t, err)
2019-11-25 19:46:02 +00:00
2019-12-05 13:53:28 +00:00
// Run the endblocker, simulating a block height just before auction expiry
preExpiryHeight := ctx.BlockHeight() + int64(auction.DefaultMaxAuctionDuration) - 1
auction.EndBlocker(ctx.WithBlockHeight(preExpiryHeight), keeper)
2019-11-25 19:46:02 +00:00
2019-12-05 13:53:28 +00:00
// 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)
2019-11-25 19:46:02 +00:00
require.False(t, found)
}
2019-12-05 13:53:28 +00:00
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) }