2020-01-12 15:12:22 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-04-30 14:23:41 +00:00
|
|
|
|
2020-01-12 15:12:22 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2020-04-30 14:23:41 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/kava-labs/kava/x/auction/testutil"
|
2020-01-12 15:12:22 +00:00
|
|
|
"github.com/kava-labs/kava/x/auction/types"
|
|
|
|
)
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
type auctionTestSuite struct {
|
|
|
|
testutil.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *auctionTestSuite) SetupTest() {
|
|
|
|
suite.Suite.SetupTest(4)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAuctionTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(auctionTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *auctionTestSuite) TestSurplusAuctionBasic() {
|
|
|
|
buyer := suite.Addrs[0]
|
|
|
|
|
|
|
|
// TODO: use cdp.LiquidatorMacc once CDP module is available
|
|
|
|
// sellerModName := cdp.LiquidatorMacc
|
|
|
|
sellerAddr := authtypes.NewModuleAddress(suite.ModAcc.Name)
|
|
|
|
suite.AddCoinsToNamedModule(suite.ModAcc.Name, cs(c("token1", 100), c("token2", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// Create an auction (lot: 20 token1, initialBid: 0 token2)
|
2022-01-08 00:39:27 +00:00
|
|
|
auctionID, err := suite.Keeper.StartSurplusAuction(suite.Ctx, suite.ModAcc.Name, c("token1", 20), "token2") // lobid denom
|
|
|
|
suite.NoError(err)
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check seller's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// PlaceBid (bid: 10 token, lot: same as starting)
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, buyer, c("token2", 10)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check buyer's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyer, cs(c("token1", 100), c("token2", 90)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check seller's coins have not increased (because proceeds are burned)
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// increment bid same bidder
|
2022-01-08 00:39:27 +00:00
|
|
|
err = suite.Keeper.PlaceBid(suite.Ctx, auctionID, buyer, c("token2", 20))
|
|
|
|
suite.NoError(err)
|
2020-01-12 15:12:22 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// Close auction just at auction expiry time
|
|
|
|
suite.Ctx = suite.Ctx.WithBlockTime(suite.Ctx.BlockTime().Add(types.DefaultBidDuration))
|
|
|
|
suite.NoError(suite.Keeper.CloseAuction(suite.Ctx, auctionID))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check buyer's coins increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyer, cs(c("token1", 120), c("token2", 80)))
|
2020-01-12 15:12:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *auctionTestSuite) TestDebtAuctionBasic() {
|
2020-01-12 15:12:22 +00:00
|
|
|
// Setup
|
2022-01-08 00:39:27 +00:00
|
|
|
seller := suite.Addrs[0]
|
|
|
|
suite.AddCoinsToNamedModule(suite.ModAcc.Name, cs(c("debt", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// Start auction
|
2022-01-08 00:39:27 +00:00
|
|
|
auctionID, err := suite.Keeper.StartDebtAuction(suite.Ctx, suite.ModAcc.Name, c("token1", 20), c("token2", 99999), c("debt", 20))
|
|
|
|
suite.NoError(err)
|
2020-01-12 14:17:47 +00:00
|
|
|
// Check buyer's coins have not decreased (except for debt), as lot is minted at the end
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(suite.ModAcc.GetAddress(), cs(c("debt", 80)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// Place a bid
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, seller, c("token2", 10)))
|
|
|
|
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check seller's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(seller, cs(c("token1", 80), c("token2", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check buyer's coins have increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(suite.ModAcc.GetAddress(), cs(c("token1", 20), c("debt", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// Close auction at just after auction expiry
|
2022-01-08 00:39:27 +00:00
|
|
|
ctx := suite.Ctx.WithBlockTime(suite.Ctx.BlockTime().Add(types.DefaultBidDuration))
|
|
|
|
suite.NoError(suite.Keeper.CloseAuction(ctx, auctionID))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check seller's coins increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(seller, cs(c("token1", 80), c("token2", 110)))
|
2020-01-12 15:12:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *auctionTestSuite) TestDebtAuctionDebtRemaining() {
|
|
|
|
seller := suite.Addrs[0]
|
|
|
|
|
|
|
|
buyerAddr := authtypes.NewModuleAddress(suite.ModAcc.Name)
|
|
|
|
suite.AddCoinsToNamedModule(suite.ModAcc.Name, cs(c("debt", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Start auction
|
2022-01-08 00:39:27 +00:00
|
|
|
auctionID, err := suite.Keeper.StartDebtAuction(suite.Ctx, suite.ModAcc.Name, c("token1", 10), c("token2", 99999), c("debt", 20))
|
|
|
|
suite.NoError(err)
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check buyer's coins have not decreased (except for debt), as lot is minted at the end
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyerAddr, cs(c("debt", 80)))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Place a bid
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, seller, c("token2", 10)))
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check seller's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(seller, cs(c("token1", 90), c("token2", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check buyer's coins have increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyerAddr, cs(c("token1", 10), c("debt", 90)))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Close auction at just after auction expiry
|
2022-01-08 00:39:27 +00:00
|
|
|
ctx := suite.Ctx.WithBlockTime(suite.Ctx.BlockTime().Add(types.DefaultBidDuration))
|
|
|
|
suite.NoError(suite.Keeper.CloseAuction(ctx, auctionID))
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check seller's coins increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(seller, cs(c("token1", 90), c("token2", 110)))
|
2020-01-14 15:04:47 +00:00
|
|
|
// check that debt has increased due to corresponding debt being greater than bid
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyerAddr, cs(c("token1", 10), c("debt", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *auctionTestSuite) TestCollateralAuctionBasic() {
|
2020-01-12 15:12:22 +00:00
|
|
|
// Setup
|
2022-01-08 00:39:27 +00:00
|
|
|
buyer := suite.Addrs[0]
|
|
|
|
returnAddrs := suite.Addrs[1:]
|
2020-01-12 15:12:22 +00:00
|
|
|
returnWeights := is(30, 20, 10)
|
2022-01-08 00:39:27 +00:00
|
|
|
sellerModName := suite.ModAcc.Name
|
|
|
|
sellerAddr := suite.ModAcc.GetAddress()
|
|
|
|
suite.AddCoinsToNamedModule(sellerModName, cs(c("token1", 100), c("token2", 100), c("debt", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// Start auction
|
2022-01-08 00:39:27 +00:00
|
|
|
auctionID, err := suite.Keeper.StartCollateralAuction(suite.Ctx, sellerModName, c("token1", 20), c("token2", 50), returnAddrs, returnWeights, c("debt", 40))
|
|
|
|
suite.NoError(err)
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check seller's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 100), c("debt", 60)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// Place a forward bid
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, buyer, c("token2", 10)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check bidder's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyer, cs(c("token1", 100), c("token2", 90)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check seller's coins have increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 110), c("debt", 70)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check return addresses have not received coins
|
2022-01-08 00:39:27 +00:00
|
|
|
for _, ra := range suite.Addrs[1:] {
|
|
|
|
suite.CheckAccountBalanceEqual(ra, cs(c("token1", 100), c("token2", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Place a reverse bid
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, buyer, c("token2", 50))) // first bid up to max bid to switch phases
|
|
|
|
suite.NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, buyer, c("token1", 15)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check bidder's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyer, cs(c("token1", 100), c("token2", 50)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check seller's coins have increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 150), c("debt", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check return addresses have received coins
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(suite.Addrs[1], cs(c("token1", 102), c("token2", 100)))
|
|
|
|
suite.CheckAccountBalanceEqual(suite.Addrs[2], cs(c("token1", 102), c("token2", 100)))
|
|
|
|
suite.CheckAccountBalanceEqual(suite.Addrs[3], cs(c("token1", 101), c("token2", 100)))
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// Close auction at just after auction expiry
|
2022-01-08 00:39:27 +00:00
|
|
|
ctx := suite.Ctx.WithBlockTime(suite.Ctx.BlockTime().Add(types.DefaultBidDuration))
|
|
|
|
suite.NoError(suite.Keeper.CloseAuction(ctx, auctionID))
|
2020-01-12 15:12:22 +00:00
|
|
|
// Check buyer's coins increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyer, cs(c("token1", 115), c("token2", 50)))
|
2020-01-12 15:12:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *auctionTestSuite) TestCollateralAuctionDebtRemaining() {
|
2020-01-14 15:04:47 +00:00
|
|
|
// Setup
|
2022-01-08 00:39:27 +00:00
|
|
|
buyer := suite.Addrs[0]
|
|
|
|
returnAddrs := suite.Addrs[1:]
|
2020-01-14 15:04:47 +00:00
|
|
|
returnWeights := is(30, 20, 10)
|
2022-01-08 00:39:27 +00:00
|
|
|
sellerModName := suite.ModAcc.Name
|
|
|
|
sellerAddr := suite.ModAcc.GetAddress()
|
|
|
|
suite.AddCoinsToNamedModule(sellerModName, cs(c("token1", 100), c("token2", 100), c("debt", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Start auction
|
2022-01-08 00:39:27 +00:00
|
|
|
auctionID, err := suite.Keeper.StartCollateralAuction(suite.Ctx, sellerModName, c("token1", 20), c("token2", 50), returnAddrs, returnWeights, c("debt", 40))
|
|
|
|
suite.NoError(err)
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check seller's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 100), c("debt", 60)))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Place a forward bid
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.NoError(suite.Keeper.PlaceBid(suite.Ctx, auctionID, buyer, c("token2", 10)))
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check bidder's coins have decreased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyer, cs(c("token1", 100), c("token2", 90)))
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check seller's coins have increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 110), c("debt", 70)))
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check return addresses have not received coins
|
2022-01-08 00:39:27 +00:00
|
|
|
for _, ra := range suite.Addrs[1:] {
|
|
|
|
suite.CheckAccountBalanceEqual(ra, cs(c("token1", 100), c("token2", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
ctx := suite.Ctx.WithBlockTime(suite.Ctx.BlockTime().Add(types.DefaultBidDuration))
|
|
|
|
suite.NoError(suite.Keeper.CloseAuction(ctx, auctionID))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// check that buyers coins have increased
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(buyer, cs(c("token1", 120), c("token2", 90)))
|
2020-01-14 15:04:47 +00:00
|
|
|
// Check return addresses have not received coins
|
2022-01-08 00:39:27 +00:00
|
|
|
for _, ra := range suite.Addrs[1:] {
|
|
|
|
suite.CheckAccountBalanceEqual(ra, cs(c("token1", 100), c("token2", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
}
|
|
|
|
// check that token2 has increased by 10, debt by 40, for a net debt increase of 30 debt
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.CheckAccountBalanceEqual(sellerAddr, cs(c("token1", 80), c("token2", 110), c("debt", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *auctionTestSuite) TestStartSurplusAuction() {
|
2020-01-12 15:12:22 +00:00
|
|
|
someTime := time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)
|
|
|
|
type args struct {
|
|
|
|
seller string
|
|
|
|
lot sdk.Coin
|
|
|
|
bidDenom string
|
|
|
|
}
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
blockTime time.Time
|
|
|
|
args args
|
|
|
|
expectPass bool
|
2020-04-23 16:35:58 +00:00
|
|
|
expPanic bool
|
2020-01-12 15:12:22 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"normal",
|
|
|
|
someTime,
|
2022-01-08 00:39:27 +00:00
|
|
|
args{suite.ModAcc.Name, c("stable", 10), "gov"},
|
2020-04-23 16:35:58 +00:00
|
|
|
true, false,
|
2020-01-12 15:12:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"no module account",
|
|
|
|
someTime,
|
|
|
|
args{"nonExistentModule", c("stable", 10), "gov"},
|
2020-04-23 16:35:58 +00:00
|
|
|
false, true,
|
2020-01-12 15:12:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"not enough coins",
|
|
|
|
someTime,
|
2022-01-08 00:39:27 +00:00
|
|
|
args{suite.ModAcc.Name, c("stable", 101), "gov"},
|
2020-04-23 16:35:58 +00:00
|
|
|
false, false,
|
2020-01-12 15:12:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"incorrect denom",
|
|
|
|
someTime,
|
2022-01-08 00:39:27 +00:00
|
|
|
args{suite.ModAcc.Name, c("notacoin", 10), "gov"},
|
2020-04-23 16:35:58 +00:00
|
|
|
false, false,
|
2020-01-12 15:12:22 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Run(tc.name, func() {
|
|
|
|
suite.SetupTest()
|
2020-01-12 15:12:22 +00:00
|
|
|
// setup
|
|
|
|
initialLiquidatorCoins := cs(c("stable", 100))
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.AddCoinsToNamedModule(suite.ModAcc.Name, initialLiquidatorCoins)
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// run function under test
|
2020-04-23 16:35:58 +00:00
|
|
|
var (
|
|
|
|
id uint64
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if tc.expPanic {
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Panics(func() {
|
|
|
|
_, _ = suite.Keeper.StartSurplusAuction(suite.Ctx, tc.args.seller, tc.args.lot, tc.args.bidDenom)
|
|
|
|
}, tc.name)
|
2020-04-23 16:35:58 +00:00
|
|
|
} else {
|
2022-01-08 00:39:27 +00:00
|
|
|
id, err = suite.Keeper.StartSurplusAuction(suite.Ctx, tc.args.seller, tc.args.lot, tc.args.bidDenom)
|
2020-04-23 16:35:58 +00:00
|
|
|
}
|
2020-01-12 15:12:22 +00:00
|
|
|
|
|
|
|
// check
|
2022-01-08 00:39:27 +00:00
|
|
|
liquidatorCoins := suite.BankKeeper.GetAllBalances(suite.Ctx, suite.ModAcc.GetAddress())
|
|
|
|
actualAuc, found := suite.Keeper.GetAuction(suite.Ctx, id)
|
2020-01-12 15:12:22 +00:00
|
|
|
if tc.expectPass {
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.NoError(err, tc.name)
|
2020-01-12 15:12:22 +00:00
|
|
|
// check coins moved
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Equal(initialLiquidatorCoins.Sub(cs(tc.args.lot)), liquidatorCoins, tc.name)
|
2020-01-12 15:12:22 +00:00
|
|
|
// check auction in store and is correct
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.True(found, tc.name)
|
|
|
|
|
|
|
|
surplusAuction := types.SurplusAuction{BaseAuction: types.BaseAuction{
|
2020-02-03 15:54:00 +00:00
|
|
|
ID: id,
|
2020-01-14 14:00:37 +00:00
|
|
|
Initiator: tc.args.seller,
|
|
|
|
Lot: tc.args.lot,
|
|
|
|
Bidder: nil,
|
|
|
|
Bid: c(tc.args.bidDenom, 0),
|
|
|
|
HasReceivedBids: false,
|
|
|
|
EndTime: types.DistantFuture,
|
|
|
|
MaxEndTime: types.DistantFuture,
|
2022-01-08 00:39:27 +00:00
|
|
|
}}
|
|
|
|
suite.Equal(&surplusAuction, actualAuc, tc.name)
|
2020-04-23 16:35:58 +00:00
|
|
|
} else if !tc.expPanic && !tc.expectPass {
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Error(err, tc.name)
|
2020-01-12 15:12:22 +00:00
|
|
|
// check coins not moved
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Equal(initialLiquidatorCoins, liquidatorCoins, tc.name)
|
2020-01-12 15:12:22 +00:00
|
|
|
// check auction not in store
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.False(found, tc.name)
|
2020-01-12 15:12:22 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-01-14 15:04:47 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *auctionTestSuite) TestCloseAuction() {
|
|
|
|
suite.AddCoinsToNamedModule(suite.ModAcc.Name, cs(c("token1", 100), c("token2", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Create an auction (lot: 20 token1, initialBid: 0 token2)
|
2022-01-08 00:39:27 +00:00
|
|
|
id, err := suite.Keeper.StartSurplusAuction(suite.Ctx, suite.ModAcc.Name, c("token1", 20), "token2") // lot, bid denom
|
|
|
|
suite.NoError(err)
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Attempt to close the auction before EndTime
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Error(suite.Keeper.CloseAuction(suite.Ctx, id))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Attempt to close auction that does not exist
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Error(suite.Keeper.CloseAuction(suite.Ctx, 999))
|
2020-01-14 15:04:47 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *auctionTestSuite) TestCloseExpiredAuctions() {
|
|
|
|
suite.AddCoinsToNamedModule(suite.ModAcc.Name, cs(c("token1", 100), c("token2", 100)))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Start auction 1
|
2022-01-08 00:39:27 +00:00
|
|
|
_, err := suite.Keeper.StartSurplusAuction(suite.Ctx, suite.ModAcc.Name, c("token1", 20), "token2") // lot, bid denom
|
|
|
|
suite.NoError(err)
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Start auction 2
|
2022-01-08 00:39:27 +00:00
|
|
|
_, err = suite.Keeper.StartSurplusAuction(suite.Ctx, suite.ModAcc.Name, c("token1", 20), "token2") // lot, bid denom
|
|
|
|
suite.NoError(err)
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Fast forward the block time
|
2022-01-08 00:39:27 +00:00
|
|
|
ctx := suite.Ctx.WithBlockTime(suite.Ctx.BlockTime().Add(types.DefaultMaxAuctionDuration).Add(1))
|
2020-01-14 15:04:47 +00:00
|
|
|
|
|
|
|
// Close expired auctions
|
2022-01-08 00:39:27 +00:00
|
|
|
err = suite.Keeper.CloseExpiredAuctions(ctx)
|
|
|
|
suite.NoError(err)
|
2020-01-14 15:04:47 +00:00
|
|
|
}
|