diff --git a/atlas-cardano.cabal b/atlas-cardano.cabal index 40a900eb..bb5ce888 100644 --- a/atlas-cardano.cabal +++ b/atlas-cardano.cabal @@ -317,6 +317,7 @@ test-suite atlas-tests GeniusYield.Test.Providers GeniusYield.Test.Providers.Mashup GeniusYield.Test.RefInput + GeniusYield.Test.SimpleScript GeniusYield.Test.SlotConfig GeniusYield.Test.Stake diff --git a/src/GeniusYield/Types/Script/SimpleScript.hs b/src/GeniusYield/Types/Script/SimpleScript.hs index fcc92914..b9f9bdbf 100644 --- a/src/GeniusYield/Types/Script/SimpleScript.hs +++ b/src/GeniusYield/Types/Script/SimpleScript.hs @@ -122,11 +122,9 @@ hashSimpleScript = scriptHashFromApi . hashSimpleScript' hashSimpleScript' :: GYSimpleScript -> Api.ScriptHash hashSimpleScript' = Api.hashScript . Api.SimpleScript . simpleScriptToApi --- FIXME: Need to test this. simpleScriptFromCBOR :: Text -> Maybe GYSimpleScript simpleScriptFromCBOR = simpleScriptFromCBOR' . encodeUtf8 --- FIXME: Need to test this. simpleScriptFromCBOR' :: ByteString -> Maybe GYSimpleScript simpleScriptFromCBOR' b = do bs <- rightToMaybe (BS16.decode b) diff --git a/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs b/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs index bae2ff43..5d686615 100644 --- a/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs +++ b/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs @@ -4,10 +4,13 @@ module GeniusYield.Test.Privnet.SimpleScripts ( import Control.Lens (each, (%~), (&)) import Control.Monad (when) +import GeniusYield.Test.Privnet.Asserts (assertEqual) import GeniusYield.Test.Privnet.Ctx import GeniusYield.Test.Privnet.Setup import GeniusYield.TxBuilder import GeniusYield.Types +import GeniusYield.Types.Script (GYAnyScript (GYSimpleScript)) +import GeniusYield.Types.UTxO (GYUTxO (utxoRefScript)) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (testCaseSteps) @@ -39,6 +42,9 @@ exerciseASimpleScript ctx info toUseRefScript = do info $ "Successfully funded the simple script, with tx id: " <> show txIdFund info "Now consuming from the simple script" let toConsume = txOutRefFromTuple (txIdFund, 0) + when toUseRefScript $ do + toConsumeUtxo <- ctxRun ctx fundUser $ utxoAtTxOutRef' toConsume + assertEqual "Reference script must be equal to actual script" (Just $ GYSimpleScript multiSigSimpleScript) (utxoRefScript toConsumeUtxo) txIdConsume <- ctxRun ctx fundUser $ do txBodyConsume <- buildTxBody $ mustHaveInput @'PlutusV2 $ GYTxIn toConsume (GYTxInWitnessSimpleScript $ if toUseRefScript then GYInReferenceSimpleScript toConsume multiSigSimpleScript else GYInSimpleScript multiSigSimpleScript) submitTxBodyConfirmed txBodyConsume $ userPaymentSKey <$> [user1, user2, user3] diff --git a/tests/GeniusYield/Test/SimpleScript.hs b/tests/GeniusYield/Test/SimpleScript.hs new file mode 100644 index 00000000..7968b763 --- /dev/null +++ b/tests/GeniusYield/Test/SimpleScript.hs @@ -0,0 +1,31 @@ +module GeniusYield.Test.SimpleScript ( + simpleScriptTests, +) where + +import Control.Monad (forM_) +import Data.Maybe (fromJust) +import GeniusYield.GYConfig +import GeniusYield.Test.Privnet.Asserts (assertEqual) +import GeniusYield.Types +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.HUnit (testCase, (@?=)) + +simpleScriptTests :: [GYCoreConfig] -> TestTree +simpleScriptTests configs = + testGroup + "simple-script" + [ testCase "able to read simple-script from file" $ do + ss <- readSimpleScript "tests/mock-data/simple-script.json" + ss + @?= RequireAllOf + [ RequireTimeAfter (slotFromWord64 1000) + , RequireSignature "966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37" + , RequireMOf 2 [RequireSignature "2f3d4cf10d0471a1db9f2d2907de867968c27bca6272f062cd1c2413", RequireSignature "f856c0c5839bab22673747d53f1ae9eed84afafb085f086e8e988614", RequireSignature "b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538"] + , RequireAnyOf [RequireSignature "4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b5321", RequireSignature "3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf8"] + ] + , testCase "able to read on-chain simple script" $ do + forM_ configs $ \config -> withCfgProviders config mempty $ \provider -> do + utxo <- fromJust <$> gyQueryUtxoAtTxOutRef provider "bce517a8353c663e9f19feb3aaf28e7d1ce8579c988a7e86ca60b5527b1bd4e4#0" + let sscript = RequireAnyOf [RequireSignature "07fb2b78b3917d3f6bfa3a59de61f3c225cbf0d5564a1cbc6f96d6eb"] + assertEqual "Simple script not equal" (Just $ GYSimpleScript sscript) (utxoRefScript utxo) + ] diff --git a/tests/atlas-tests.hs b/tests/atlas-tests.hs index 23850674..ec2fa748 100644 --- a/tests/atlas-tests.hs +++ b/tests/atlas-tests.hs @@ -11,7 +11,6 @@ import Test.Tasty.HUnit ( assertEqual, testCase, (@=?), - (@?=), ) import GeniusYield.Examples.Gift @@ -28,6 +27,7 @@ import GeniusYield.Test.GYTxBody (gyTxBodyTests) 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 @@ -74,9 +74,6 @@ main = do expected @=? first (dropWhile (/= '(') . show) e ] , blueprintTests - , testCase "able to read simple-script" $ do - ss <- readSimpleScript (mockDataDir "simple-script.json") - ss @?= RequireAllOf [RequireTimeAfter (slotFromWord64 1000), RequireSignature "966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37", RequireMOf 2 [RequireSignature "2f3d4cf10d0471a1db9f2d2907de867968c27bca6272f062cd1c2413", RequireSignature "f856c0c5839bab22673747d53f1ae9eed84afafb085f086e8e988614", RequireSignature "b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538"], RequireAnyOf [RequireSignature "4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b5321", RequireSignature "3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf8"]] , slotConversionTests , coinSelectionTests , gyTxBodyTests @@ -85,6 +82,7 @@ main = do , refInputTests , feeTrackingTests , stakeTests (head configs) + , simpleScriptTests configs , providersTests configs providerToken netId ] @@ -111,6 +109,3 @@ findPackageRoot = do if here then return "." else fail "Cannot find package root" - -mockDataDir :: FilePath -mockDataDir = "tests/mock-data"