-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from j-mueller/th
use-cases: Add TH module for tests
- Loading branch information
Showing
9 changed files
with
146 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
-- | Quoted expressions for generating validation data | ||
module Spec.TH( | ||
pendingTxVesting, | ||
pendingTxCrowdfunding | ||
) where | ||
|
||
import Language.Haskell.TH (Exp, Q) | ||
import qualified Language.Plutus.CoreToPLC.Primitives as Prim | ||
import Language.Plutus.Runtime (Hash (..), Height, PendingTx (..), | ||
PendingTxIn (..), PendingTxOut (..), | ||
PendingTxOutRef (..), PendingTxOutType (..), | ||
Value) | ||
import Wallet.API (PubKey (..)) | ||
|
||
import Language.Plutus.Coordination.Contracts.CrowdFunding (CampaignActor) | ||
import Language.Plutus.Coordination.Contracts.Vesting (VestingData (..)) | ||
|
||
-- | Create a `PendingTx () VestingData` from a block height and a value | ||
-- (of funds taken out of the scheme) | ||
pendingTxVesting :: Q Exp | ||
pendingTxVesting = [| \(h :: Height) (out :: Value) -> | ||
let total = 600 | ||
hash = 1123 -- stand-in for a transaction hash | ||
rest = total - out | ||
in PendingTx { | ||
pendingTxCurrentInput = (PendingTxIn (PendingTxOutRef 100 0) (), total), | ||
pendingTxOtherInputs = []::[(PendingTxIn (), Value)], | ||
pendingTxOutputs = (PendingTxOut out Nothing (PubKeyTxOut (PubKey 1))::(PendingTxOut VestingData)):(PendingTxOut rest (Just (VestingData hash out)) DataTxOut::(PendingTxOut VestingData)):([]::[PendingTxOut VestingData]), | ||
pendingTxForge = 0, | ||
pendingTxFee = 0, | ||
pendingTxBlockHeight = h | ||
} |] | ||
|
||
-- | Create a `PendingTx () CampaignActor` from a block height and one or two inputs. | ||
pendingTxCrowdfunding :: Q Exp | ||
pendingTxCrowdfunding = [| \(h :: Height) (v1::Value) (v2::Maybe Value) -> | ||
let i1 = (PendingTxIn (PendingTxOutRef 100 1) (), v1) | ||
i2 = case v2 of | ||
Just v2' -> (PendingTxIn (PendingTxOutRef 200 1) (), v2'):[] | ||
Nothing -> []::[(PendingTxIn (), Value)] | ||
in PendingTx { | ||
pendingTxCurrentInput = i1, | ||
pendingTxOtherInputs = i2, | ||
pendingTxOutputs = []::[PendingTxOut CampaignActor], | ||
pendingTxForge = 0, | ||
pendingTxFee = 0, | ||
pendingTxBlockHeight = h | ||
} | ||
|] |
Oops, something went wrong.