enforce min & max lease period

master
michael 2022-09-05 22:17:55 +00:00
parent f1ea4edca8
commit 8711758f20
4 changed files with 33 additions and 9 deletions

View File

@ -4,13 +4,17 @@
HERE=$(cd $(dirname $BASH_SOURCE) && pwd) HERE=$(cd $(dirname $BASH_SOURCE) && pwd)
source $HERE/testutil.sh source $HERE/testutil.sh
# echo $BOB cosmos-testd tx cosmostest new-auction asdf asdf 200 token $(now + 3500) \
# cosmos-testd q cosmostest show-auction $(get_last_auction_index) | jq -y --from bob \
# exit 0 | expect_fail "Can't create auction below min lease period"
cosmos-testd tx cosmostest new-auction asdf asdf 200 token $(now + 8200000) \
-y --from bob \
| expect_fail "Can't create auction above max lease period"
before=$(get_balance $BOB token) before=$(get_balance $BOB token)
cosmos-testd tx cosmostest new-auction asdf asdf 200 token $(now + 100) \ cosmos-testd tx cosmostest new-auction asdf asdf 200 token $(now + 3700) \
-y --from bob \ -y --from bob \
| expect_success "New auction is created" | expect_success "New auction is created"

View File

@ -1,10 +1,12 @@
package auctionconfig package auctionconfig
// Length of the auction in blocks-- currently 10.
// Assuming a block time of 3sec, this should be ~30sec.
const ( const (
// Times // Times
AuctionTime = 10 AuctionTime = 10 // 10 blocks = ~10-30 seconds
// Lease Period Requirements (seconds)
MinLeasePeriod = 3_600 // 1 hour
MaxLeasePeriod = 8_035_200 // 3 months
// Gas Fees // Gas Fees
AuctionGas = 10 AuctionGas = 10

View File

@ -38,7 +38,7 @@ func (k Keeper) FinalizeExpiredAuctions(ctx sdk.Context) {
return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err) return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err)
} }
// Remainig Unpaid: Full bid amount // Remaining Unpaid: Full bid amount
auction.Remaining = auction.Best.Amount auction.Remaining = auction.Best.Amount
// clear auction // clear auction

View File

@ -18,10 +18,28 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
next, found := k.Keeper.GetNextAuction(ctx) next, found := k.Keeper.GetNextAuction(ctx)
if !found { if !found {
return nil, errors.New("Auction not found") return nil, errors.New("unable to get next auction index")
} }
index := strconv.FormatUint(next.AuctionId, 10) index := strconv.FormatUint(next.AuctionId, 10)
auctionLen := msg.LeaseEnd - uint64(ctx.BlockTime().Unix())
if auctionLen < auctionconfig.MinLeasePeriod {
return nil, fmt.Errorf(
"Auction length %d is below min lease period of %d",
auctionLen,
auctionconfig.MinLeasePeriod,
)
}
if auctionLen > auctionconfig.MaxLeasePeriod {
return nil, fmt.Errorf(
"Auction length %d is above max lease period of %d",
auctionLen,
auctionconfig.MaxLeasePeriod,
)
}
auction := types.Auction{ auction := types.Auction{
Index: index, Index: index,
Name: msg.Name, Name: msg.Name,