0g-chain/x/auction/abci_test.go
Derrick Lee e526fd1639
Split existing auction bid_duration parameter into forward_bid_duration and reverse_bid_duration (#1158)
* Split bid_duration field into forward/reverse durations

* Update params.go

* Update params_test for forward/reverse bid durations

* Remove duplicated import

* Replace bid duration on place bids

* Fix reversed bid errors

* Update auctions test

* Update bidding test

* Update testutil suite to use default forward/reverse bid durations

* Fix missing ReverseBidDuration param field

* Check if auction is reversed on forward bid

* Add test for conversion to reverse auction that reaches maxbid

* Make proto fields backwards compatible

* Use ForwardBidDuration for debt bid

* Make copy of v16 auction types

this doesn't actually work but keeping it in history

* Disable migrations

* Update debt tests to use forward bid duration
2022-02-08 09:03:47 -08:00

58 lines
1.9 KiB
Go

package auction_test
import (
"testing"
"github.com/stretchr/testify/suite"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/auction"
"github.com/kava-labs/kava/x/auction/testutil"
types "github.com/kava-labs/kava/x/auction/types"
)
type abciTestSuite struct {
testutil.Suite
}
func (suite *abciTestSuite) SetupTest() {
suite.Suite.SetupTest(4)
}
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)}
suite.AddCoinsToNamedModule(suite.ModAcc.Name, cs(c("token1", 100), c("token2", 100), c("debt", 100)))
// 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)))
// Run the beginblocker, simulating a block time 1ns before auction expiry
preExpiryTime := suite.Ctx.BlockTime().Add(types.DefaultForwardBidDuration - 1)
auction.BeginBlocker(suite.Ctx.WithBlockTime(preExpiryTime), suite.Keeper)
// Check auction has not been closed yet
_, found := suite.Keeper.GetAuction(suite.Ctx, auctionID)
suite.True(found)
// Run the endblocker, simulating a block time equal to auction expiry
expiryTime := suite.Ctx.BlockTime().Add(types.DefaultForwardBidDuration)
auction.BeginBlocker(suite.Ctx.WithBlockTime(expiryTime), suite.Keeper)
// Check auction has been closed
_, found = suite.Keeper.GetAuction(suite.Ctx, auctionID)
suite.False(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...) }