mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
update auction module tests
This commit is contained in:
parent
ab8331f90a
commit
215241edd9
@ -1,4 +1,4 @@
|
|||||||
package auction
|
package auction_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -6,23 +6,42 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
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) {
|
func TestKeeper_EndBlocker(t *testing.T) {
|
||||||
// setup keeper and auction
|
// Setup
|
||||||
mapp, keeper, addresses, _ := setUpMockApp()
|
_, addrs := app.GeneratePrivKeyAddressPairs(1)
|
||||||
header := abci.Header{Height: mapp.LastBlockHeight() + 1}
|
seller := addrs[0]
|
||||||
mapp.BeginBlock(abci.RequestBeginBlock{Header: header})
|
|
||||||
ctx := mapp.BaseApp.NewContext(false, header)
|
|
||||||
|
|
||||||
seller := addresses[0]
|
tApp := app.NewTestApp()
|
||||||
keeper.StartForwardAuction(ctx, seller, sdk.NewInt64Coin("token1", 20), sdk.NewInt64Coin("token2", 0))
|
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
|
ctx := tApp.NewContext(true, abci.Header{})
|
||||||
expiryBlock := ctx.BlockHeight() + int64(DefaultMaxAuctionDuration)
|
keeper := tApp.GetAuctionKeeper()
|
||||||
EndBlocker(ctx.WithBlockHeight(expiryBlock), keeper)
|
|
||||||
|
|
||||||
// check auction has been closed
|
auctionID, err := keeper.StartForwardAuction(ctx, seller, c("token1", 20), c("token2", 0))
|
||||||
_, found := keeper.GetAuction(ctx, 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)
|
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...) }
|
||||||
|
Loading…
Reference in New Issue
Block a user