Skip to content

Commit

Permalink
Add supplemental datum plutus test (#6025)
Browse files Browse the repository at this point in the history
* Add supplemental datum plutus script
This script checks for the presence of a particular datum in the tx

* Update hprop_plutus_v3 to use the supplemental datum script
Add plutusV3SupplementalDatumScript script value
  • Loading branch information
Jimbo4350 authored Oct 29, 2024
1 parent b735932 commit 02cd604
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions bench/plutus-scripts-bench/plutus-scripts-bench.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ library
Cardano.Benchmarking.PlutusScripts.Loop2024
Cardano.Benchmarking.PlutusScripts.LoopV3
Cardano.Benchmarking.PlutusScripts.SchnorrSecp256k1Loop
Cardano.Benchmarking.PlutusScripts.SupplementalDatum

--------------------------
-- IOG dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import qualified Cardano.Benchmarking.PlutusScripts.HashOntoG2AndAdd as HashG2Ad
import qualified Cardano.Benchmarking.PlutusScripts.Loop2024 as Loop2024
import qualified Cardano.Benchmarking.PlutusScripts.LoopV3 as LoopV3
import qualified Cardano.Benchmarking.PlutusScripts.SchnorrSecp256k1Loop as Schnorr
import qualified Cardano.Benchmarking.PlutusScripts.SupplementalDatum as SupplementalDatum
import Cardano.Benchmarking.ScriptAPI


Expand All @@ -40,6 +41,7 @@ getAllScripts =
, Loop2024.script
, LoopV3.script
, Schnorr.script
, SupplementalDatum.script
]

listPlutusScripts ::
Expand Down
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
7 changes: 7 additions & 0 deletions cardano-testnet/src/Testnet/Defaults.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Testnet.Defaults
, defaultMainnetTopology
, defaultUtxoKeys
, plutusV3Script
, plutusV3SupplementalDatumScript
) where

import Cardano.Api (AnyShelleyBasedEra (..), CardanoEra (..), File (..),
Expand Down Expand Up @@ -543,3 +544,9 @@ defaultUtxoKeys n =
plutusV3Script :: Text
plutusV3Script =
"{ \"type\": \"PlutusScriptV3\", \"description\": \"\", \"cborHex\": \"46450101002499\" }"

plutusV3SupplementalDatumScript :: Text
plutusV3SupplementalDatumScript =
"{ \"type\": \"PlutusScriptV3\", \"description\": \"\", \"cborHex\": \"590e59590e560100003233223322323232323232323232323232323232253353010300e35353232325335333573466e1d200000201501413232323232333222123330010040030023232325335333573466e1d200000201d01c1323232323232323232323232323232323333333333332333233233222222222222222212333333333333333300101101000f00e00d00c00b00a00900800700600500400300230013574202860026ae8404cc0948c8c8c94cd4ccd5cd19b87480000080cc0c84cc8848cc00400c008c074d5d080098029aba135744002260589201035054310035573c0046aae74004dd5000998128009aba101123232325335333573466e1d200000203203113232333322221233330010050040030023232325335333573466e1d2000002037036133221233001003002302e357420026605e4646464a66a666ae68cdc3a4000004076074264244600400660646ae8400454cd4ccd5cd19b87480080080ec0e84c8ccc888488ccc00401401000cdd69aba1002375a6ae84004dd69aba1357440026ae880044c0d12401035054310035573c0046aae74004dd50009aba135744002260609201035054310035573c0046aae74004dd51aba1003300735742004646464a66a666ae68cdc3a400000406e06c224440062a66a666ae68cdc3a400400406e06c264244460020086eb8d5d08008a99a999ab9a3370e900200101b81b099091118010021aba1001130304901035054310035573c0046aae74004dd51aba10013302c75c6ae84d5d10009aba200135744002260569201035054310035573c0046aae74004dd50009bad3574201e60026ae84038c008c009d69981180a9aba100c33302702475a6ae8402cc8c8c94cd4ccd5cd19b87480000080c00bc4cc8848cc00400c008c8c8c94cd4ccd5cd19b87480000080cc0c84cc8848cc00400c008cc09dd69aba10013026357426ae880044c0b1241035054310035573c0046aae74004dd51aba10013232325335333573466e1d20000020330321332212330010030023302775a6ae84004c098d5d09aba20011302c491035054310035573c0046aae74004dd51aba13574400226052921035054310035573c0046aae74004dd51aba100a3302375c6ae84024ccc09c8c8c8c94cd4ccd5cd19b87480000080c40c04c84888888c01401cdd71aba100115335333573466e1d200200203103013212222223002007301b357420022a66a666ae68cdc3a40080040620602642444444600600e60506ae8400454cd4ccd5cd19b87480180080c40c04cc884888888cc01802001cdd69aba10013019357426ae8800454cd4ccd5cd19b87480200080c40c04c84888888c00401cc068d5d08008a99a999ab9a3370e9005001018818099910911111198020040039bad3574200260306ae84d5d1000898152481035054310035573c0046aae74004dd500080f9aba10083300201f3574200e6eb8d5d080319981380b198138111191919299a999ab9a3370e9000001018818089110010a99a999ab9a3370e9001001018818089110008a99a999ab9a3370e900200101881808911001898152481035054310035573c0046aae74004dd50009aba1005330230143574200860026ae8400cc004d5d09aba2003302475a604aeb8d5d10009aba2001357440026ae88004d5d10009aba2001357440026ae88004d5d10009aba2001357440026ae88004d5d10009aba200113016491035054310035573c0046aae74004dd51aba10063574200a646464a66a666ae68cdc3a400000403a0382642444444600a00e6eb8d5d08008a99a999ab9a3370e900100100e80e0999109111111980100400398039aba10013301500f357426ae8800454cd4ccd5cd19b87480100080740704c84888888c00c01cc050d5d08008a99a999ab9a3370e900300100e80e099910911111198030040039bad35742002600a6ae84d5d10008a99a999ab9a3370e900400100e80e0990911111180080398031aba100115335333573466e1d200a00201d01c13322122222233004008007375a6ae84004c010d5d09aba2001130164901035054310035573c0046aae74004dd51aba13574400a4646464a66a666ae68cdc3a400000403a038264666444246660020080060046eb4d5d0801180a9aba10013232325335333573466e1d20000020210201323332221222222233300300a0090083301a017357420046ae84004cc069d71aba1357440026ae8800454cd4ccd5cd19b87480080080840804cc8848888888cc01c024020cc064058d5d0800991919299a999ab9a3370e90000010120118999109198008018011bad357420026eb4d5d09aba20011301d491035054310035573c0046aae74004dd51aba1357440022a66a666ae68cdc3a4008004042040266442444444466004012010666036030eb4d5d08009980cbae357426ae8800454cd4ccd5cd19b87480180080840804c848888888c010020cc064058d5d08008a99a999ab9a3370e900400101081009919199991110911111119998008058050048041980d80c1aba10033301901a3574200466603a034eb4d5d08009a991919299a999ab9a3370e90000010130128998119bad357420026eb4d5d09aba20011301f4901035054310035573c0046aae74004dd51aba135744002446602a0040026ae88004d5d10008a99a999ab9a3370e90050010108100999109111111198028048041980c80b1aba10013232325335333573466e1d200000202402313301c75c6ae840044c075241035054310035573c0046aae74004dd51aba1357440022a66a666ae68cdc3a401800404204022444444400c26034921035054310035573c0046aae74004dd51aba1357440026ae880044c059241035054310035573c0046aae74004dd50009191919299a999ab9a3370e900000100e00d899910911111111111980280680618099aba10013301475a6ae84d5d10008a99a999ab9a3370e900100100e00d899910911111111111980100680618099aba10013301475a6ae84d5d10008a9919a999ab9a3370e900200180e80e0999109111111111119805006806180a1aba10023001357426ae8800854cd4ccd5cd19b874801800c0740704c8ccc888488888888888ccc018038034030c054d5d080198011aba1001375a6ae84d5d10009aba200215335333573466e1d200800301d01c133221222222222223300700d00c3014357420046eb4d5d09aba200215335333573466e1d200a00301d01c132122222222222300100c3014357420042a66a666ae68cdc3a401800603a038266442444444444446600601a01860286ae84008dd69aba1357440042a66a666ae68cdc3a401c00603a038266442444444444446601201a0186eb8d5d08011bae357426ae8800854cd4ccd5cd19b874804000c0740704cc88488888888888cc020034030dd71aba1002375a6ae84d5d10010a99a999ab9a3370e900900180e80e0999109111111111119805806806180a1aba10023014357426ae8800854cd4ccd5cd19b874805000c0740704c8488888888888c010030c050d5d08010980b2481035054310023232325335333573466e1d200000202001f13212223003004375c6ae8400454c8cd4ccd5cd19b874800800c0840804c84888c004010c004d5d08010a99a999ab9a3370e9002001810810099910911198010028021bae3574200460026ae84d5d10010980d2481035054310023232325335333573466e1d200000202402313212223003004301b357420022a66a666ae68cdc3a4004004048046224440042a66a666ae68cdc3a4008004048046224440022603a921035054310035573c0046aae74004dd50009aab9e00235573a0026ea8004d55cf0011aab9d00137540024646464a66a666ae68cdc3a40000040360342642444600600860246ae8400454cd4ccd5cd19b874800800806c0684c84888c008010c048d5d08008a99a999ab9a3370e900200100d80d099091118008021bae3574200226028921035054310035573c0046aae74004dd50009191919299a999ab9a3370e900000100d00c8999109198008018011bae357420026eb4d5d09aba200113013491035054310035573c0046aae74004dd50009aba20011300e491035054310035573c0046aae74004dd500091100191111111111111110030a4c260169201035054350030132225335333573466e1d20000010130121300c491035054330015335333573466e20005200001301213300333702900000119b81480000044c8cc8848cc00400c008cdc200180099b840020013300400200130122225335333573466e1d200000101201110021330030013370c00400240024646464a66a666ae68cdc3a400000402202020202a66a666ae68cdc3a40040040220202022260149201035054310035573c0046aae74004dd500091191919299a999ab9a3370e9000001008808089110010a99a999ab9a3370e90010010088080990911180180218029aba100115335333573466e1d2004002011010112220011300a4901035054310035573c0046aae74004dd50009191919299a999ab9a3370e90000010078070999109198008018011bae357420026eb4d5d09aba200113008491035054310035573c0046aae74004dd5000919118011bac001300e2233335573e0024020466a01e60086ae84008c00cd5d10010041191919299a999ab9a3370e900000100680609909118010019bae357420022a66a666ae68cdc3a400400401a01826424460020066eb8d5d0800898032481035054310035573c0046aae74004dd500091191919299a999ab9a3370e900100100680608910008a99a999ab9a3370e9000001006806099091180100198029aba1001130064901035054310035573c0046aae74004dd5000919319ab9c00100322322300237560026016446666aae7c00480348c8cd4034cc024c018d55ce80098029aab9e0013004357440066ae8400801448004c01c894cd40044020884cd4024d400888004c0100048848cc00400c008c014894cd4004400c8854cd4ccd5cd19baf4c01010100002006005100613004001122002122001122002122122330010040032323001001230022330020020011\" }"


Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
txin1 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0

plutusScript <- H.note $ work </> "always-succeeds-script.plutusV3"
H.writeFile plutusScript $ Text.unpack plutusV3Script
H.writeFile plutusScript $ Text.unpack plutusV3SupplementalDatumScript

let sendAdaToScriptAddressTxBody = work </> "send-ada-to-script-address-tx-body"

Expand All @@ -105,6 +105,10 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
, "--script-data-value", "0"
]

supplementalDatumJsonFile
<- H.note $ work </> "supplemental-datum.json"
H.writeFile supplementalDatumJsonFile "{\"int\":1}"

scriptStakeRegistrationCertificate
<- H.note $ work </> "script-stake-registration-certificate"

Expand Down Expand Up @@ -152,6 +156,7 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
txout = mconcat [ utxoAddr, "+", show @Int 2_000_000
, "+", mintValue
]
txoutWithSupplementalDatum = mconcat [utxoAddr, "+", show @Int 1_000_000]

void $ execCli' execConfig
[ anyEraToString anyEra, "transaction", "build"
Expand All @@ -168,6 +173,8 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
, "--certificate-script-file", plutusScript
, "--certificate-redeemer-value", "0"
, "--tx-out", txout
, "--tx-out", txoutWithSupplementalDatum
, "--tx-out-datum-embed-file", supplementalDatumJsonFile
, "--out-file", spendScriptUTxOTxBody
]

Expand All @@ -182,5 +189,6 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
[ "latest", "transaction", "submit"
, "--tx-file", spendScriptUTxOTx
]

H.success

0 comments on commit 02cd604

Please sign in to comment.