diff --git a/tests/test_auction_flow.sh b/tests/test_auction_flow.sh index e1a1792..c7cfa4f 100755 --- a/tests/test_auction_flow.sh +++ b/tests/test_auction_flow.sh @@ -4,13 +4,17 @@ HERE=$(cd $(dirname $BASH_SOURCE) && pwd) source $HERE/testutil.sh -# echo $BOB -# cosmos-testd q cosmostest show-auction $(get_last_auction_index) | jq -# exit 0 +cosmos-testd tx cosmostest new-auction asdf asdf 200 token $(now + 3500) \ + -y --from bob \ + | 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) -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 \ | expect_success "New auction is created" diff --git a/x/cosmostest/auctionconfig/config.go b/x/cosmostest/auctionconfig/config.go index 8687150..d913e36 100644 --- a/x/cosmostest/auctionconfig/config.go +++ b/x/cosmostest/auctionconfig/config.go @@ -1,10 +1,12 @@ package auctionconfig -// Length of the auction in blocks-- currently 10. -// Assuming a block time of 3sec, this should be ~30sec. const ( // 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 AuctionGas = 10 diff --git a/x/cosmostest/keeper/auction_state.go b/x/cosmostest/keeper/auction_state.go index c0e6a7f..ce81fb2 100644 --- a/x/cosmostest/keeper/auction_state.go +++ b/x/cosmostest/keeper/auction_state.go @@ -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) } - // Remainig Unpaid: Full bid amount + // Remaining Unpaid: Full bid amount auction.Remaining = auction.Best.Amount // clear auction diff --git a/x/cosmostest/keeper/msg_server_new_auction.go b/x/cosmostest/keeper/msg_server_new_auction.go index 76895df..beae755 100644 --- a/x/cosmostest/keeper/msg_server_new_auction.go +++ b/x/cosmostest/keeper/msg_server_new_auction.go @@ -18,10 +18,28 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) ( next, found := k.Keeper.GetNextAuction(ctx) 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) + 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{ Index: index, Name: msg.Name,