-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathatlas-tests.hs
117 lines (106 loc) · 4.72 KB
/
atlas-tests.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module Main (main) where
import Cardano.Api qualified as Api
import Data.ByteString qualified as BS
import Data.ByteString.Lazy qualified as LBS
import System.Directory (doesFileExist)
import System.FilePath ((</>))
import Test.Tasty (defaultMain, testGroup)
import Test.Tasty.Golden (goldenVsString)
import Test.Tasty.HUnit (
assertEqual,
testCase,
(@=?),
)
import GeniusYield.Examples.Gift
import GeniusYield.GYConfig (
coreConfigIO,
findMaestroTokenAndNetId,
)
import GeniusYield.Imports
import GeniusYield.Test.Blueprint (blueprintTests)
import GeniusYield.Test.CoinSelection (coinSelectionTests)
import GeniusYield.Test.Config (configTests)
import GeniusYield.Test.FeeTracking (feeTrackingTests)
import GeniusYield.Test.GYTxBody (gyTxBodyTests)
import GeniusYield.Test.GYTxOutRefCbor (gyTxOutRefCborTests)
import GeniusYield.Test.GYTxSkeleton (gyTxSkeletonTests)
import GeniusYield.Test.Providers (providersTests)
import GeniusYield.Test.RefInput (refInputTests)
import GeniusYield.Test.SimpleScript (simpleScriptTests)
import GeniusYield.Test.SlotConfig (slotConversionTests)
import GeniusYield.Test.Stake (stakeTests)
import GeniusYield.Types
-------------------------------------------------------------------------------
-- main
-------------------------------------------------------------------------------
main :: IO ()
main = do
configs <- forM ["maestro-config.json", "blockfrost-config.json"] coreConfigIO
(providerToken, netId) <- findMaestroTokenAndNetId configs
rootDir <- findPackageRoot
defaultMain $
testGroup
"atlas"
[ testGroup
"serializeToRawBytes"
[ goldenVsString "serialized-v1" (rootDir </> "fixtures" </> "script-v1.cbor") $ do
return $ LBS.fromStrict $ Api.serialiseToRawBytes simpleScriptAPIv1
, goldenVsString "serialized-v2" (rootDir </> "fixtures" </> "script-v2.cbor") $ do
return $ LBS.fromStrict $ Api.serialiseToRawBytes simpleScriptAPIv2
, testCase "Encoding is the same" $ do
v1 <- BS.readFile $ rootDir </> "fixtures" </> "script-v1.cbor"
v2 <- BS.readFile $ rootDir </> "fixtures" </> "script-v2.cbor"
assertEqual "v1==v2" v1 v2
]
, testGroup
"textEnvelope"
[ goldenVsString "serialized-v1" (rootDir </> "fixtures" </> "script-env-v1.json") $ do
return $ Api.textEnvelopeToJSON Nothing simpleScriptAPIv1
, goldenVsString "serialized-v2" (rootDir </> "fixtures" </> "script-env-v2.json") $ do
return $ Api.textEnvelopeToJSON Nothing simpleScriptAPIv2
, testCase "correctly read script" $ do
envelopeContents <- BS.readFile $ rootDir </> "fixtures" </> "script-env-v2.json"
let envelopeContentsParsed = readScript' @'PlutusV2 envelopeContents
pure giftValidatorV2 @=? envelopeContentsParsed
, -- we can deserialize v1 as v1.
testCase "deserialize v1" $ do
e <- Api.readFileTextEnvelope (Api.proxyToAsType Proxy) (Api.File $ rootDir </> "fixtures" </> "script-env-v1.json")
Right simpleScriptAPIv1 @=? first show e
, testCase "deserialize v1" $ do
e <- Api.readFileTextEnvelope (Api.proxyToAsType Proxy) (Api.File $ rootDir </> "fixtures" </> "script-env-v1.json")
let expected :: Either String (Api.PlutusScript Api.PlutusScriptV2)
expected = Left "(TextEnvelopeTypeError [TextEnvelopeType \"PlutusScriptV2\"] (TextEnvelopeType \"PlutusScriptV1\"))"
expected @=? first (dropWhile (/= '(') . show) e
]
, blueprintTests
, slotConversionTests
, coinSelectionTests
, gyTxBodyTests
, configTests
, gyTxSkeletonTests
, gyTxOutRefCborTests
, refInputTests
, feeTrackingTests
, stakeTests (head configs)
, simpleScriptTests configs
, providersTests configs providerToken netId
]
-------------------------------------------------------------------------------
-- simple script
-------------------------------------------------------------------------------
simpleScriptAPIv1 :: Api.PlutusScript Api.PlutusScriptV1
simpleScriptAPIv1 = validatorToApi giftValidatorV1
simpleScriptAPIv2 :: Api.PlutusScript Api.PlutusScriptV2
simpleScriptAPIv2 = validatorToApi giftValidatorV2
-------------------------------------------------------------------------------
-- utilities
-------------------------------------------------------------------------------
{- | Useful when tests are run with @cabal run@ from the root of the project,
not the package.
-}
findPackageRoot :: IO FilePath
findPackageRoot = do
here <- doesFileExist "atlas-cardano.cabal"
if here
then return "."
else fail "Cannot find package root"