Fix broken auction test.
[?]
Sep 12, 2020, 12:34 AM
YWNTVA7PN7MC3HNTER3OCFHQAVKNJUK7KRQDZYFK24S5JLWHNU4ACDependencies
- [2]
LTSVBVA2Update to a recent haskoin-core. Fix Stack build. - [3]
EFSXYZPOAutoformat everything with brittany. - [4]
UUR6SMCAAdd start of specs for auctions. - [5]
GLFF5ZDKFactor winningBids for easier testing. - [6]
HBULCDN6Add tests for auction winner determination algorithm. - [7]
LHJ2HFXVAdd property test for auction algorithm. - [8]
3GBSDS5PFix out-of-date test code, add skeleton for payments spec.
Change contents
- edit in test/Aftok/AuctionSpec.hs at line 11
import Data.List ((!!)) - replacement in test/Aftok/AuctionSpec.hs at line 13[3.615]→[3.309:336](∅→∅),[3.742]→[3.309:336](∅→∅),[3.66552]→[3.309:336](∅→∅),[3.309]→[3.309:336](∅→∅)
import Data.UUIDimport qualified Data.UUID.V4 as U - replacement in test/Aftok/AuctionSpec.hs at line 42
spec =lettestB0 = Bid (UserId nil)(Seconds 3)(Satoshi 100)(read "2016-03-05 15:59:26.033176 UTC")testB1 = Bid (UserId nil)(Seconds 60)(Satoshi 1000)(read "2016-03-05 15:59:26.033177 UTC")testB2 = Bid (UserId nil)(Seconds 60)(Satoshi 100)(read "2016-03-05 15:59:26.033178 UTC")testB3 = Bid (UserId nil)(Seconds 90)(Satoshi 100)(read "2016-03-05 15:59:26.033179 UTC")testB4 = Bid (UserId nil)(Seconds 60)(Satoshi 100)(read "2016-03-05 15:59:26.033180 UTC")indodescribe "bid ordering" $ doit "ensures that bids with lowest seconds/btc ratio are first" $ dobidOrder testB0 testB1 `shouldBe` LTbidOrder testB1 testB2 `shouldBe` LTbidOrder testB2 testB3 `shouldBe` LTspec = dousers <- runIO $ fmap UserId <$> replicateM 5 U.nextRandomlet testB0 = Bid (users !! 0)(Seconds 3)(Satoshi 100)(read "2016-03-05 15:59:20.000000 UTC")testB1 = Bid (users !! 1)(Seconds 60)(Satoshi 1000)(read "2016-03-05 15:59:21.000000 UTC")testB2 = Bid (users !! 2)(Seconds 60)(Satoshi 100)(read "2016-03-05 15:59:22.000000 UTC")testB3 = Bid (users !! 3)(Seconds 90)(Satoshi 100)(read "2016-03-05 15:59:23.000000 UTC")testB4 = Bid (users !! 4)(Seconds 60)(Satoshi 100)(read "2016-03-05 15:59:24.000000 UTC")describe "bid ordering" $ doit "ensures that bids with lowest seconds/btc ratio are first" $ dobidOrder testB0 testB1 `shouldBe` LTbidOrder testB1 testB2 `shouldBe` LTbidOrder testB2 testB3 `shouldBe` LT - replacement in test/Aftok/AuctionSpec.hs at line 70
it "ensures breaks ties in bid ordering by timestamp" $ dobidOrder testB2 testB4 `shouldBe` LTit "ensures breaks ties in bid ordering by timestamp" $ dobidOrder testB2 testB4 `shouldBe` LT - replacement in test/Aftok/AuctionSpec.hs at line 73
describe "winning bids" $ doit"determines a sufficient number of winners to fulfill the raise amount"$ letresult = runAuction' (Satoshi 1250)[testB0, testB1, testB2, testB3, testB4]split =Bid (UserId nil) (Seconds 30) (Satoshi 50) (testB4 ^. bidTime)expected = sortBy bidOrder [testB0, testB1, testB2, split]incase result ofWinningBids winners ->sortBy bidOrder winners `shouldBe` expecteddescribe "winning bids" $ doit"determines a sufficient number of winners to fulfill the raise amount"$ letresult = runAuction' (Satoshi 1250)[testB0, testB1, testB2, testB3, testB4]split =Bid (users !! 4) (Seconds 31) (Satoshi 50) (testB4 ^. bidTime)expected = sortBy bidOrder [testB0, testB1, testB2, split]incase result ofWinningBids winners ->sortBy bidOrder winners `shouldBe` expected - replacement in test/Aftok/AuctionSpec.hs at line 87
InsufficientBids _ ->assertFailure"Sufficinent bids were presented, but auction algorithm asserted otherwise."InsufficientBids _ ->assertFailure"Sufficinent bids were presented, but auction algorithm asserted otherwise." - replacement in test/Aftok/AuctionSpec.hs at line 91[3.840]→[3.68753:68834](∅→∅),[3.68834]→[2.64388:64456](∅→∅),[2.64456]→[3.68892:69033](∅→∅),[3.68892]→[3.68892:69033](∅→∅),[3.69033]→[2.64457:64536](∅→∅)
it "ensures that the raise amount is fully consumed by the winning bids"$ forAll ((,) <$> arbitrarySatoshi btc <*> listOf genBid)$ \(raiseAmount', bids) -> case runAuction' raiseAmount' bids ofWinningBids xs -> bidsTotal xs == raiseAmount'InsufficientBids t -> t == (raiseAmount' `subs` bidsTotal bids)it "ensures that the raise amount is fully consumed by the winning bids"$ forAll ((,) <$> arbitrarySatoshi btc <*> listOf genBid)$ \(raiseAmount', bids) -> case runAuction' raiseAmount' bids ofWinningBids xs -> bidsTotal xs == raiseAmount'InsufficientBids t -> t == (raiseAmount' `subs` bidsTotal bids)