-
Notifications
You must be signed in to change notification settings - Fork 720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add supplemental datum plutus test #6025
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
74 changes: 74 additions & 0 deletions
74
bench/plutus-scripts-bench/src/Cardano/Benchmarking/PlutusScripts/SupplementalDatum.hs
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,74 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE ImportQualifiedPost #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE Strict #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
{-# OPTIONS_GHC -fno-full-laziness #-} | ||
{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-} | ||
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-} | ||
{-# OPTIONS_GHC -fno-spec-constr #-} | ||
{-# OPTIONS_GHC -fno-specialise #-} | ||
{-# OPTIONS_GHC -fno-strictness #-} | ||
{-# OPTIONS_GHC -fno-unbox-small-strict-fields #-} | ||
{-# OPTIONS_GHC -fno-unbox-strict-fields #-} | ||
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-} | ||
|
||
module Cardano.Benchmarking.PlutusScripts.SupplementalDatum (script) where | ||
|
||
import Cardano.Api.Shelley (PlutusScript (..), PlutusScriptV3, PlutusScriptVersion (..), | ||
Script (..), toScriptInAnyLang) | ||
|
||
import Cardano.Benchmarking.ScriptAPI | ||
import Language.Haskell.TH | ||
import Language.Haskell.TH.Syntax | ||
import PlutusTx.Prelude as Tx hiding (Semigroup (..), (.), (<$>)) | ||
import Prelude as Haskell (String, (.), (<$>)) | ||
import PlutusTx | ||
import qualified Data.ByteString.Short as SBS | ||
import qualified PlutusLedgerApi.V1.Scripts as V1 | ||
import qualified PlutusLedgerApi.V3 as V3 | ||
import qualified PlutusTx.AssocMap as PlutusTx | ||
import qualified PlutusTx.Builtins as PlutusTx | ||
import qualified PlutusTx.Prelude as PlutusTx | ||
|
||
scriptName :: Haskell.String | ||
scriptName | ||
= prepareScriptName $(LitE . StringL . loc_module <$> qLocation) | ||
|
||
script :: PlutusBenchScript | ||
script = mkPlutusBenchScript scriptName (toScriptInAnyLang (PlutusScript PlutusScriptV3 scriptSerialized)) | ||
|
||
-- | Write to disk with: cabal run plutus-scripts-bench -- print SupplementalDatum -o supplemental-datum.plutus | ||
{-# INLINABLE typedValidator #-} | ||
typedValidator :: V3.ScriptContext -> Bool | ||
typedValidator scriptContext = | ||
PlutusTx.elem supplementalDatum datums | ||
where | ||
txInfo = V3.scriptContextTxInfo scriptContext | ||
datumMap = V3.txInfoData txInfo | ||
datums = PlutusTx.elems datumMap | ||
|
||
{-# INLINABLE supplementalDatum #-} | ||
supplementalDatum :: V1.Datum | ||
supplementalDatum = V1.Datum (PlutusTx.mkI 1) | ||
|
||
untypedValidator :: BuiltinData -> BuiltinUnit | ||
untypedValidator ctx = | ||
PlutusTx.check (typedValidator (PlutusTx.unsafeFromBuiltinData ctx) ) | ||
|
||
supplementalDatumBs :: SBS.ShortByteString | ||
supplementalDatumBs = V3.serialiseCompiledCode $$(PlutusTx.compile [|| untypedValidator ||]) | ||
|
||
scriptSerialized :: PlutusScript PlutusScriptV3 | ||
scriptSerialized = PlutusScriptSerialised supplementalDatumBs |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining how this was generated here, would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to add this process to the documentation and then link to it. @CarlosLopezDeLara where should this documentation go?