diff --git a/agora.cabal b/agora.cabal index 5f8ded4..6f1b244 100644 --- a/agora.cabal +++ b/agora.cabal @@ -138,3 +138,12 @@ test-suite agora-test type: exitcode-stdio-1.0 main-is: Spec.hs hs-source-dirs: test + +benchmark agora-bench + import: lang, deps + hs-source-dirs: bench + main-is: Main.hs + type: exitcode-stdio-1.0 + build-depends: + , plutarch-benchmark + , agora \ No newline at end of file diff --git a/bench.csv b/bench.csv new file mode 100644 index 0000000..867f837 --- /dev/null +++ b/bench.csv @@ -0,0 +1,3 @@ +name,cpu,mem,size +full_scripts:authorityTokenPolicy,1280339,4400,276 +full_scripts:stakePolicy,2649897,9000,786 diff --git a/bench/Main.hs b/bench/Main.hs new file mode 100644 index 0000000..6fc2704 --- /dev/null +++ b/bench/Main.hs @@ -0,0 +1,28 @@ +module Main (main) where + +import Prelude + +-------------------------------------------------------------------------------- + +import Plutarch.Benchmark +import Plutus.V1.Ledger.Value qualified as Value + +-------------------------------------------------------------------------------- + +import Agora.AuthorityToken qualified as Agora +import Agora.SafeMoney qualified as Agora +import Agora.Stake qualified as Agora + +-------------------------------------------------------------------------------- + +main :: IO () +main = do + benchMain benchmarks + +benchmarks :: [NamedBenchmark] +benchmarks = + benchGroup + "full_scripts" + [ bench "authorityTokenPolicy" $ Agora.authorityTokenPolicy (Agora.AuthorityToken (Value.assetClass "" "")) + , bench "stakePolicy" $ Agora.stakePolicy (Agora.Stake @Agora.LQ) + ] diff --git a/cabal.project b/cabal.project index bd0d96f..ec42141 100644 --- a/cabal.project +++ b/cabal.project @@ -1,3 +1,4 @@ packages: ./. +benchmarks: true tests: true diff --git a/flake.nix b/flake.nix index 0c51115..e574172 100644 --- a/flake.nix +++ b/flake.nix @@ -42,7 +42,7 @@ inherit (plutarch) cabalProjectLocal; extraSources = plutarch.extraSources ++ [{ src = inputs.plutarch; - subdirs = [ "." ]; + subdirs = [ "." "plutarch-benchmark" ]; }]; modules = [ (plutarch.haskellModule system) ]; shell = { @@ -64,7 +64,11 @@ inherit (plutarch) tools; - additional = ps: [ ps.plutarch ps.tasty-quickcheck ]; + additional = ps: [ + ps.plutarch + ps.plutarch-benchmark + ps.tasty-quickcheck + ]; }; }; diff --git a/hie.yaml b/hie.yaml index 23b82b5..bea0b14 100644 --- a/hie.yaml +++ b/hie.yaml @@ -2,5 +2,7 @@ cradle: cabal: - path: "./src" component: "lib:agora" + - path: "./bench" + component: "benchmark:agora-bench" - path: "./test" component: "test:agora-test" diff --git a/src/Agora/Stake.hs b/src/Agora/Stake.hs index 1e1915c..8e46218 100644 --- a/src/Agora/Stake.hs +++ b/src/Agora/Stake.hs @@ -103,15 +103,15 @@ stakePolicy _stake = ctx <- pletFields @'["txInfo", "purpose"] ctx' PMinting ownSymbol <- pmatch $ pfromData ctx.purpose - -- TODO: add this to 'valueCorrect' let stValue = psingletonValue # (pfield @"_0" # ownSymbol) # pconstant "ST" # 1 passert "A UTXO must exist with the correct output" $ anyOutput @(StakeDatum gt) # pfromData ctx.txInfo # ( plam $ \value stakeDatum' -> P.do stakeDatum <- pletFields @'["owner", "stakedAmount"] stakeDatum' + let expectedValue = paddValue # (discreteValue # stakeDatum.stakedAmount) # stValue let ownerSignsTransaction = ptxSignedBy # ctx.txInfo # stakeDatum.owner - let valueCorrect = pdata value #== pdata (paddValue # (discreteValue # stakeDatum.stakedAmount) # stValue) + let valueCorrect = pdata value #== pdata expectedValue ownerSignsTransaction #&& valueCorrect )