Fix broken auction test.

[?]
Sep 12, 2020, 12:34 AM
YWNTVA7PN7MC3HNTER3OCFHQAVKNJUK7KRQDZYFK24S5JLWHNU4AC

Dependencies

  • [2] LTSVBVA2 Update to a recent haskoin-core. Fix Stack build.
  • [3] EFSXYZPO Autoformat everything with brittany.
  • [4] UUR6SMCA Add start of specs for auctions.
  • [5] GLFF5ZDK Factor winningBids for easier testing.
  • [6] HBULCDN6 Add tests for auction winner determination algorithm.
  • [7] LHJ2HFXV Add property test for auction algorithm.
  • [8] 3GBSDS5P Fix out-of-date test code, add skeleton for payments spec.

Change contents

  • edit in test/Aftok/AuctionSpec.hs at line 11
    [3.309]
    [3.66500]
    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.UUID
    [3.66552]
    [3.66553]
    import qualified Data.UUID.V4 as U
  • replacement in test/Aftok/AuctionSpec.hs at line 42
    [3.412][3.1224:1231](),[3.1231][3.66867:67877]()
    spec =
    let
    testB0 = 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")
    in
    do
    describe "bid ordering" $ do
    it "ensures that bids with lowest seconds/btc ratio are first" $ do
    bidOrder testB0 testB1 `shouldBe` LT
    bidOrder testB1 testB2 `shouldBe` LT
    bidOrder testB2 testB3 `shouldBe` LT
    [3.412]
    [3.1352]
    spec = do
    users <- runIO $ fmap UserId <$> replicateM 5 U.nextRandom
    let 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" $ do
    it "ensures that bids with lowest seconds/btc ratio are first" $ do
    bidOrder testB0 testB1 `shouldBe` LT
    bidOrder testB1 testB2 `shouldBe` LT
    bidOrder testB2 testB3 `shouldBe` LT
  • replacement in test/Aftok/AuctionSpec.hs at line 70
    [3.1353][3.67878:67992]()
    it "ensures breaks ties in bid ordering by timestamp" $ do
    bidOrder testB2 testB4 `shouldBe` LT
    [3.1353]
    [3.290]
    it "ensures breaks ties in bid ordering by timestamp" $ do
    bidOrder testB2 testB4 `shouldBe` LT
  • replacement in test/Aftok/AuctionSpec.hs at line 73
    [3.291][3.67993:68584]()
    describe "winning bids" $ do
    it
    "determines a sufficient number of winners to fulfill the raise amount"
    $ let
    result = 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]
    in
    case result of
    WinningBids winners ->
    sortBy bidOrder winners `shouldBe` expected
    [3.291]
    [3.1605]
    describe "winning bids" $ do
    it
    "determines a sufficient number of winners to fulfill the raise amount"
    $ let
    result = 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]
    in
    case result of
    WinningBids winners ->
    sortBy bidOrder winners `shouldBe` expected
  • replacement in test/Aftok/AuctionSpec.hs at line 87
    [3.1606][3.68585:68752]()
    InsufficientBids _ ->
    assertFailure
    "Sufficinent bids were presented, but auction algorithm asserted otherwise."
    [3.1606]
    [3.839]
    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 of
    WinningBids xs -> bidsTotal xs == raiseAmount'
    InsufficientBids t -> t == (raiseAmount' `subs` bidsTotal bids)
    [3.840]
    [3.2103]
    it "ensures that the raise amount is fully consumed by the winning bids"
    $ forAll ((,) <$> arbitrarySatoshi btc <*> listOf genBid)
    $ \(raiseAmount', bids) -> case runAuction' raiseAmount' bids of
    WinningBids xs -> bidsTotal xs == raiseAmount'
    InsufficientBids t -> t == (raiseAmount' `subs` bidsTotal bids)