Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

changed bid raise logic and updates tests #215

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
- uses: actions/[email protected]
name: Setup Haskell Stack
with:
ghc-version: 9.0.1 # higher than necessary, but is cached in the runner
ghc-version: 9.2.1
stack-version: 2.3

- uses: actions/download-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion packages/minter-contracts/bin/english_auction_tez.tz
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
DIG 3 ;
COMPARE ;
GE ;
OR ;
AND ;
OR ;
NOT ;
IF { NOW ;
Expand Down
6 changes: 1 addition & 5 deletions packages/minter-contracts/ligo/src/english_auction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ pauseable_admin_storage %pauseable_admin

We determine whether a given bid is of a sufficiently high value as follows:

The bid is greater than the the previous bid plus the ceiling of the `min_raise_percent` of it.

OR

The bid is greater than the previous bid plus the `min_raise`
The bid is greater than the the previous bid plus the ceiling of the `min_raise_percent` of it AND the bid is greater than the previous bid plus the `min_raise`

OR

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ let dont_return_bid (auction : auction) : bool =
#endif

let valid_bid_amount (auction, bid_amount : auction * tez) : bool =
(bid_amount >= (auction.current_bid + (percent_of_bid_tez (auction.min_raise_percent, auction.current_bid)))) ||
(bid_amount >= auction.current_bid + auction.min_raise) ||
((bid_amount >= (auction.current_bid + (percent_of_bid_tez (auction.min_raise_percent, auction.current_bid)))) &&
(bid_amount >= auction.current_bid + auction.min_raise)) ||
((bid_amount >= auction.current_bid) && first_bid(auction))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ hprop_First_bid_is_valid_IFF_it_meets_opening_price =
else placeBid contract firstBid `expectFailure` failedWith contract
([mt|INVALID_BID_AMOUNT|], (((testOpeningPrice, firstBid), seller, startTime), startTime))

hprop_Subsequent_bids_are_valid_if_they_are_above_'min_raise' :: Property
hprop_Subsequent_bids_are_valid_if_they_are_above_'min_raise' =
hprop_Subsequent_bids_are_valid_IFF_they_are_above_'min_raise'_and_'min_raise_percent' :: Property
hprop_Subsequent_bids_are_valid_IFF_they_are_above_'min_raise'_and_'min_raise_percent' =
property $ do
testData@TestData{testOpeningPrice} <- forAll genTestData

Expand Down Expand Up @@ -87,60 +87,22 @@ hprop_Subsequent_bids_are_valid_if_they_are_above_'min_raise' =
label "Second bid is above `min_raise`, but below `min_raise_percent`"

clevelandProp $ do
setup@Setup{seller, contract} <- testSetup testData'
bidder1 <- newAddress "bidder-1"
bidder2 <- newAddress "bidder-2"

withSender seller $ configureAuction testData' setup
waitForAuctionToStart testData'

withSender bidder1 $ placeBid contract firstBid
withSender bidder2 $ placeBid contract secondBid

hprop_Subsequent_bids_are_valid_if_they_are_above_'min_raise_percent' :: Property
hprop_Subsequent_bids_are_valid_if_they_are_above_'min_raise_percent' =
property $ do
testData@TestData{testOpeningPrice} <- forAll genTestData

firstBid <- forAll $ genBid testData testOpeningPrice
let minRaisePercentOfFirstBid = minRaisePercentOfBid testData firstBid

-- Generate a `min_raise` with a 50% chance of it being above `min_raise_percent * firstBid`
-- and 50% of it being below.
testMinRaise <- forAll $ do
(lowerBound, upperBound) <-
Gen.element
[ (1, minRaisePercentOfFirstBid)
, (minRaisePercentOfFirstBid, minRaisePercentOfFirstBid * 2)
]
genMutez' (Range.linear lowerBound upperBound)

let testData' = testData { testMinRaise = testMinRaise }

let secondBidLowerBound = firstBid + minRaisePercentOfFirstBid
let secondBidUpperBound = firstBid + (minRaisePercentOfFirstBid * 2)
secondBid <- forAll $ genMutez' (Range.linear secondBidLowerBound secondBidUpperBound)

-- These generators have been carefully calibrated to ensure `secondBid` is not ALWAYS
-- above BOTH `min_raise` and `min_raise_percent`.
-- For this property to be meaningful, we want there to be a fair chance of `secondBid`
-- being above `min_raise_percent`, but below `min_raise`.
when (secondBid < firstBid + testMinRaise) $
label "Second bid is above `min_raise_percent`, but below `min_raise`"

clevelandProp $ do
setup@Setup{seller, contract} <- testSetup testData'
setup@Setup{seller, contract, startTime} <- testSetup testData'
bidder1 <- newAddress "bidder-1"
bidder2 <- newAddress "bidder-2"

withSender seller $ configureAuction testData' setup
waitForAuctionToStart testData'

withSender bidder1 $ placeBid contract firstBid
withSender bidder2 $ placeBid contract secondBid

hprop_Subsequent_bids_are_invalid_if_they_are_below_'min_raise'_and_'min_raise_percent' :: Property
hprop_Subsequent_bids_are_invalid_if_they_are_below_'min_raise'_and_'min_raise_percent' =
withSender bidder2 $
if secondBid >= firstBid + minRaisePercentOfFirstBid
then placeBid contract secondBid
else placeBid contract secondBid `expectFailure` failedWith contract
([mt|INVALID_BID_AMOUNT|], ((firstBid, secondBid) , bidder1, startTime), startTime)

hprop_Subsequent_bids_are_invalid_if_they_are_below_'min_raise'_or_'min_raise_percent' :: Property
hprop_Subsequent_bids_are_invalid_if_they_are_below_'min_raise'_or_'min_raise_percent' =
property $ do
testData@TestData{testOpeningPrice} <- forAll genTestData

Expand All @@ -154,7 +116,7 @@ hprop_Subsequent_bids_are_invalid_if_they_are_below_'min_raise'_and_'min_raise_p

let minRaisePercentOfFirstBid = minRaisePercentOfBid testData' firstBid
let secondBidLowerBound = firstBid
let secondBidUpperBound = firstBid + (testMinRaise `min` minRaisePercentOfFirstBid) - 1
let secondBidUpperBound = firstBid + (testMinRaise `max` minRaisePercentOfFirstBid) - 1
secondBid <- forAll $ genMutez' (Range.linear secondBidLowerBound secondBidUpperBound)

clevelandProp $ do
Expand Down Expand Up @@ -556,10 +518,10 @@ genManyBids testData = do
-- | Generate a valid bid, such that it is:
--
-- * Greater than the previous bid or opening price.
-- * Above either the `min_raise` or the `min_raise_percent` thresholds.
-- * Above both the `min_raise` and the `min_raise_percent` thresholds.
genBid :: TestData -> Mutez -> Gen Mutez
genBid testData@TestData{testMinRaise} previousBid = do
raiseLowerBound <- Gen.element [testMinRaise, minRaisePercentOfBid testData previousBid]
let raiseLowerBound = testMinRaise `max` minRaisePercentOfBid testData previousBid
raise <- genMutez' (Range.linear raiseLowerBound (raiseLowerBound + 1000))
pure $ previousBid + raise

Expand Down
14 changes: 6 additions & 8 deletions packages/minter-contracts/test/auction/auction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,25 @@ describe('test NFT auction', () => {
//TODO: test contents of error message
return expect(failedOpeningBid).rejects.toHaveProperty('errors');
});
test('place bid meeting opening price and then raise it by valid amount by min_raise_percent', async () => {
test('place bid meeting opening price and then raise it by valid amount by min_raise_percent but not min_raise', async () => {
$log.info(`Alice bids 10tz`);
const opBid = await nftAuctionAlice.methods.bid(0).send({ amount : 10 });
await opBid.confirmation();
$log.info(`Bid placed. Amount sent: ${opBid.amount} mutez`);

$log.info(`Eve bids 11tz, a 10% raise of previous bid but less than a 10tz increase`);
const opBid2 = await nftAuctionEve.methods.bid(0).send({ amount : 11 });
await opBid2.confirmation();
$log.info(`Bid placed. Amount sent: ${opBid2.amount} mutez`);
const opBid2 = nftAuctionEve.methods.bid(0).send({ amount : 11 });
return expect(opBid2).rejects.toHaveProperty('errors'); //Still difficulty testing complicated error messages including non text data
});
test('place bid meeting opening price and then raise it by valid amount by min_raise', async () => {
test('place bid meeting opening price and then raise it by valid amount by min_raise but not min_raise_percent', async () => {
$log.info(`Alice bids 200tz`);
const opBid = await nftAuctionAlice.methods.bid(0).send({ amount : 200 });
await opBid.confirmation();
$log.info(`Bid placed. Amount sent: ${opBid.amount} mutez`);

$log.info(`Eve bids 210tz, a 10tz increase but less than a 10% raise of previous bid `);
const opBid2 = await nftAuctionEve.methods.bid(0).send({ amount : 210 });
await opBid2.confirmation();
$log.info(`Bid placed. Amount sent: ${opBid2.amount} mutez`);
const opBid2 = nftAuctionEve.methods.bid(0).send({ amount : 210 });
return expect(opBid2).rejects.toHaveProperty('errors');
});
test('bid too small should fail', async () => {
$log.info(`Alice bids 20tz`);
Expand Down