Skip to content

Commit

Permalink
Merge pull request #396 from input-output-hk/j-mueller/vesting-trigge…
Browse files Browse the repository at this point in the history
…rs-test

Game tests + sha256 builtin
  • Loading branch information
michaelpj committed Dec 9, 2018
2 parents 0634ef2 + 7e6a2b9 commit e53b063
Show file tree
Hide file tree
Showing 17 changed files with 454 additions and 103 deletions.
3 changes: 3 additions & 0 deletions language-plutus-core/language-plutus-core.cabal
Expand Up @@ -63,6 +63,7 @@ library
Language.PlutusCore.Generators.Test
PlutusPrelude
Common
Data.ByteString.Lazy.Hash
PlcTestUtils
build-tool-depends: alex:alex, happy:happy >= 1.17.1
hs-source-dirs: src prelude stdlib generators common
Expand Down Expand Up @@ -115,6 +116,7 @@ library
build-depends:
base >=4.9 && <5,
bytestring -any,
cryptonite -any,
containers -any,
array -any,
mtl -any,
Expand All @@ -127,6 +129,7 @@ library
composition-prelude >=1.1.0.1,
template-haskell -any,
th-lift-instances -any,
memory -any,
mmorph -any,
cborg -any,
serialise -any,
Expand Down
18 changes: 18 additions & 0 deletions language-plutus-core/src/Data/ByteString/Lazy/Hash.hs
@@ -0,0 +1,18 @@
-- | Hash functions for lazy [[Data.ByteString.Lazy.ByteString]]s
{-# LANGUAGE TypeApplications #-}
module Data.ByteString.Lazy.Hash
( sha2
, sha3
) where

import Crypto.Hash (SHA256, SHA3_256, hashlazy)
import qualified Data.ByteArray as B
import qualified Data.ByteString.Lazy as BSL

-- | Hash a [[BSL.ByteString]] using the SHA-256 hash function.
sha2 :: BSL.ByteString -> BSL.ByteString
sha2 = BSL.fromStrict . B.convert . hashlazy @SHA256

-- | Hash a [[BSL.ByteString]] using the SHA3-256 hash function.
sha3 :: BSL.ByteString -> BSL.ByteString
sha3 = BSL.fromStrict . B.convert . hashlazy @SHA3_256
Expand Up @@ -28,6 +28,7 @@ import PlutusPrelude

import Control.Monad.Trans.Class (lift)
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.Hash as Hash
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap

Expand Down Expand Up @@ -240,8 +241,8 @@ applyBuiltinName Concatenate = applyTypedBuiltinName typedConcatenate
applyBuiltinName TakeByteString = applyTypedBuiltinName typedTakeByteString (BSL.take . fromIntegral)
applyBuiltinName DropByteString = applyTypedBuiltinName typedDropByteString (BSL.drop . fromIntegral)
applyBuiltinName ResizeByteString = applyTypedBuiltinName typedResizeByteString (const id)
applyBuiltinName SHA2 = applyTypedBuiltinName typedSHA2 undefined
applyBuiltinName SHA3 = applyTypedBuiltinName typedSHA3 undefined
applyBuiltinName SHA2 = applyTypedBuiltinName typedSHA2 Hash.sha2
applyBuiltinName SHA3 = applyTypedBuiltinName typedSHA3 Hash.sha3
applyBuiltinName VerifySignature = applyTypedBuiltinName typedVerifySignature undefined
applyBuiltinName EqByteString = applyTypedBuiltinName typedEqByteString (==)
applyBuiltinName TxHash = applyTypedBuiltinName typedTxHash undefined
Expand Down
15 changes: 15 additions & 0 deletions language-plutus-core/test/Evaluation/Constant/Success.hs
Expand Up @@ -10,6 +10,7 @@ import Evaluation.Constant.Apply

import Control.Monad.Morph
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.Hash as Hash
import Data.Maybe
import Hedgehog
import Test.Tasty
Expand Down Expand Up @@ -99,6 +100,18 @@ test_typedTakeByteStringSuccess
$ prop_applyBuiltinNameSuccess typedTakeByteString (BSL.take . fromIntegral)
$ genTypedBuiltinDef

test_typedSHA2Success :: TestTree
test_typedSHA2Success
= testProperty "typedSHA2"
$ prop_applyBuiltinNameSuccess typedSHA2 Hash.sha2
$ genTypedBuiltinDef

test_typedSHA3Success :: TestTree
test_typedSHA3Success
= testProperty "typedSHA3"
$ prop_applyBuiltinNameSuccess typedSHA3 Hash.sha3
$ genTypedBuiltinDef

test_typedDropByteStringSuccess :: TestTree
test_typedDropByteStringSuccess
= testProperty "typedDropByteString"
Expand Down Expand Up @@ -130,6 +143,8 @@ test_applyBuiltinNameSuccess =
, test_typedTakeByteStringSuccess
, test_typedDropByteStringSuccess
, test_typedEqByteStringSuccess
, test_typedSHA2Success
, test_typedSHA3Success
]

-- | Generates in-bounds constants and checks that their evaluation results in an 'EvaluationSuccess'.
Expand Down
22 changes: 22 additions & 0 deletions pkgs/default.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e53b063

Please sign in to comment.