Merge branch 'master' into emiflake/stake

This commit is contained in:
Emily Martins 2022-02-18 21:26:51 +01:00
commit 2a6ed6d19e
7 changed files with 51 additions and 4 deletions

View file

@ -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

3
bench.csv Normal file
View file

@ -0,0 +1,3 @@
name,cpu,mem,size
full_scripts:authorityTokenPolicy,1280339,4400,276
full_scripts:stakePolicy,2649897,9000,786
1 name cpu mem size
2 full_scripts:authorityTokenPolicy 1280339 4400 276
3 full_scripts:stakePolicy 2649897 9000 786

28
bench/Main.hs Normal file
View file

@ -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)
]

View file

@ -1,3 +1,4 @@
packages: ./.
benchmarks: true
tests: true

View file

@ -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
];
};
};

View file

@ -2,5 +2,7 @@ cradle:
cabal:
- path: "./src"
component: "lib:agora"
- path: "./bench"
component: "benchmark:agora-bench"
- path: "./test"
component: "test:agora-test"

View file

@ -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
)