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

58 lines
1.9 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"
"github.com/stretchr/testify/suite"
2020-04-30 14:23:41 +00:00
2019-11-25 19:46:02 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
2020-04-30 14:23:41 +00:00
2019-12-05 13:53:28 +00:00
"github.com/kava-labs/kava/x/auction"
"github.com/kava-labs/kava/x/auction/testutil"
types "github.com/kava-labs/kava/x/auction/types"
2019-11-25 19:46:02 +00:00
)
type abciTestSuite struct {
testutil.Suite
}
func (suite *abciTestSuite) SetupTest() {
suite.Suite.SetupTest(4)
}
2019-12-05 13:53:28 +00:00
func TestABCITestSuite(t *testing.T) {
suite.Run(t, new(abciTestSuite))
}
func (suite *abciTestSuite) TestKeeper_BeginBlocker() {
buyer := suite.Addrs[0]
returnAddrs := []sdk.AccAddress{suite.Addrs[1]}
returnWeights := []sdk.Int{sdk.NewInt(1)}
2019-12-05 13:53:28 +00:00
suite.AddCoinsToNamedModule(suite.ModAcc.Name, cs(c("token1", 100), c("token2", 100), c("debt", 100)))
2019-11-25 19:46:02 +00:00
// Start an auction and place a bid
auctionID, err := suite.Keeper.StartCollateralAuction(suite.Ctx, suite.ModAcc.Name, c("token1", 20), c("token2", 50), returnAddrs, returnWeights, c("debt", 40))
suite.Require().NoError(err)
suite.Require().NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, buyer, c("token2", 30)))
2019-11-25 19:46:02 +00:00
// Run the beginblocker, simulating a block time 1ns before auction expiry
preExpiryTime := suite.Ctx.BlockTime().Add(types.DefaultBidDuration - 1)
auction.BeginBlocker(suite.Ctx.WithBlockTime(preExpiryTime), suite.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 := suite.Keeper.GetAuction(suite.Ctx, auctionID)
suite.True(found)
2019-12-05 13:53:28 +00:00
// Run the endblocker, simulating a block time equal to auction expiry
expiryTime := suite.Ctx.BlockTime().Add(types.DefaultBidDuration)
auction.BeginBlocker(suite.Ctx.WithBlockTime(expiryTime), suite.Keeper)
2019-12-05 13:53:28 +00:00
// Check auction has been closed
_, found = suite.Keeper.GetAuction(suite.Ctx, auctionID)
suite.False(found)
2019-11-25 19:46:02 +00:00
}
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...) }