|
| 1 | +{-# LANGUAGE RecordWildCards #-} |
| 2 | + |
1 | 3 | module Spec.HydraAuctionOnchain.Validators.StandingBid (spec) where
|
2 | 4 |
|
| 5 | +import Data.List (singleton) |
3 | 6 | import HydraAuctionOnchain.Scripts (compileScript)
|
4 | 7 | import HydraAuctionOnchain.Validators.StandingBid (standingBidValidator)
|
5 | 8 | import Plutarch (Script)
|
6 |
| -import PlutusLedgerApi.V2 (CurrencySymbol, ScriptContext) |
7 |
| -import Spec.HydraAuctionOnchain.Helpers (shouldFail) |
| 9 | +import PlutusLedgerApi.V2 |
| 10 | + ( Address |
| 11 | + , CurrencySymbol |
| 12 | + , Datum (Datum) |
| 13 | + , OutputDatum (OutputDatum) |
| 14 | + , Redeemer (Redeemer) |
| 15 | + , ScriptContext (..) |
| 16 | + , ScriptPurpose (Spending) |
| 17 | + , TxInInfo (TxInInfo) |
| 18 | + , TxInfo (..) |
| 19 | + , TxOut (..) |
| 20 | + , TxOutRef |
| 21 | + , dataToBuiltinData |
| 22 | + , toData |
| 23 | + ) |
| 24 | +import PlutusTx.AssocMap qualified as AMap (singleton) |
| 25 | +import Spec.HydraAuctionOnchain.Gen (genTxInfoTemplate) |
| 26 | +import Spec.HydraAuctionOnchain.Helpers (shouldFail, shouldSucceed) |
8 | 27 | import Spec.HydraAuctionOnchain.Types.AuctionTerms (AuctionTerms)
|
| 28 | +import Spec.HydraAuctionOnchain.Types.Redeemers (StandingBidRedeemer (NewBidRedeemer)) |
| 29 | +import Spec.HydraAuctionOnchain.Types.StandingBidState (StandingBidState) |
9 | 30 | import Test.Tasty (TestTree, testGroup)
|
10 | 31 | import Test.Tasty.QuickCheck (Property, testProperty)
|
11 | 32 |
|
12 | 33 | spec :: TestTree
|
13 | 34 | spec =
|
14 | 35 | testGroup
|
15 | 36 | "StandingBid"
|
16 |
| - [ testProperty "Fails when own input is missing" prop_ownInputMissing_fails |
| 37 | + [ testProperty "Succeeds" prop_validInput_succeeds |
| 38 | + , testProperty "Fails when own input is missing" prop_ownInputMissing_fails |
17 | 39 | ]
|
18 | 40 |
|
| 41 | +prop_validInput_succeeds :: Property |
| 42 | +prop_validInput_succeeds = shouldSucceed undefined |
| 43 | + |
19 | 44 | prop_ownInputMissing_fails :: Property
|
20 | 45 | prop_ownInputMissing_fails = shouldFail undefined
|
21 | 46 |
|
| 47 | +data TestContext = TestContext |
| 48 | + { auctionCs :: CurrencySymbol |
| 49 | + , auctionTerms :: AuctionTerms |
| 50 | + , datum :: StandingBidState |
| 51 | + , txInfoTemplate :: TxInfo |
| 52 | + , standingBidInputOref :: TxOutRef |
| 53 | + , scriptAddress :: Address |
| 54 | + } |
| 55 | + |
| 56 | +testNewBid :: TestContext -> Script |
| 57 | +testNewBid TestContext {..} = |
| 58 | + let |
| 59 | + standingBidInput :: TxInInfo |
| 60 | + standingBidInput = |
| 61 | + TxInInfo standingBidInputOref $ |
| 62 | + TxOut |
| 63 | + { txOutAddress = scriptAddress |
| 64 | + , txOutValue = undefined |
| 65 | + , txOutDatum = OutputDatum $ Datum $ dataToBuiltinData $ toData datum |
| 66 | + , txOutReferenceScript = Nothing |
| 67 | + } |
| 68 | + |
| 69 | + newBidRedeemer :: StandingBidRedeemer |
| 70 | + newBidRedeemer = NewBidRedeemer |
| 71 | + |
| 72 | + redeemer :: Redeemer |
| 73 | + redeemer = Redeemer $ dataToBuiltinData $ toData newBidRedeemer |
| 74 | + |
| 75 | + scriptPurpose :: ScriptPurpose |
| 76 | + scriptPurpose = Spending standingBidInputOref |
| 77 | + |
| 78 | + ctx :: ScriptContext |
| 79 | + ctx = |
| 80 | + ScriptContext |
| 81 | + { scriptContextTxInfo = |
| 82 | + txInfoTemplate |
| 83 | + { txInfoInputs = singleton standingBidInput |
| 84 | + , txInfoOutputs = outputs |
| 85 | + , txInfoRedeemers = AMap.singleton scriptPurpose redeemer |
| 86 | + } |
| 87 | + , scriptContextPurpose = scriptPurpose |
| 88 | + } |
| 89 | + in |
| 90 | + compile auctionCs auctionTerms datum newBidRedeemer ctx |
| 91 | + |
22 | 92 | compile
|
23 | 93 | :: CurrencySymbol
|
24 | 94 | -> AuctionTerms
|
25 | 95 | -> StandingBidState
|
26 | 96 | -> StandingBidRedeemer
|
27 | 97 | -> ScriptContext
|
28 | 98 | -> Script
|
29 |
| -compile auctionCs auctionTerms datum redeemer = |
| 99 | +compile auctionCs auctionTerms datum redeemer ctx = |
30 | 100 | compileScript $
|
31 | 101 | popaque $
|
32 | 102 | standingBidValidator
|
33 | 103 | # pconstant auctionCs
|
34 | 104 | # pconstant auctionTerms
|
35 | 105 | # pconstant datum
|
36 | 106 | # pconstant redeemer
|
| 107 | + # pconstant ctx |
0 commit comments