From 213fb0c2c0755417596936c6c760a1d8618403fb Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 7 Oct 2024 15:22:57 +0530 Subject: [PATCH 1/4] style(#361): format expected simple script result in parse test --- tests/atlas-tests.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/atlas-tests.hs b/tests/atlas-tests.hs index 23850674..3824f2fb 100644 --- a/tests/atlas-tests.hs +++ b/tests/atlas-tests.hs @@ -76,7 +76,13 @@ main = do , 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"]] + ss + @?= RequireAllOf + [ RequireTimeAfter (slotFromWord64 1000) + , RequireSignature "966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37" + , RequireMOf 2 [RequireSignature "2f3d4cf10d0471a1db9f2d2907de867968c27bca6272f062cd1c2413", RequireSignature "f856c0c5839bab22673747d53f1ae9eed84afafb085f086e8e988614", RequireSignature "b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538"] + , RequireAnyOf [RequireSignature "4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b5321", RequireSignature "3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf8"] + ] , slotConversionTests , coinSelectionTests , gyTxBodyTests From e9c186b272fc19035f2342433c3556e515692c69 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 7 Oct 2024 16:26:40 +0530 Subject: [PATCH 2/4] test(#361): add more tests for simple script --- atlas-cardano.cabal | 1 + src/GeniusYield/Types/Script/SimpleScript.hs | 2 -- .../GeniusYield/Test/Privnet/SimpleScripts.hs | 7 ++++++ tests/GeniusYield/Test/SimpleScript.hs | 22 +++++++++++++++++++ tests/atlas-tests.hs | 2 ++ 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/GeniusYield/Test/SimpleScript.hs 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..ccbe7efe 100644 --- a/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs +++ b/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs @@ -4,10 +4,14 @@ 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.TxBuilder (GYTxQueryMonad (utxoAtTxOutRef)) 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 +43,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..e6f20e3f --- /dev/null +++ b/tests/GeniusYield/Test/SimpleScript.hs @@ -0,0 +1,22 @@ +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 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 3824f2fb..77d86e19 100644 --- a/tests/atlas-tests.hs +++ b/tests/atlas-tests.hs @@ -28,6 +28,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 @@ -91,6 +92,7 @@ main = do , refInputTests , feeTrackingTests , stakeTests (head configs) + , simpleScriptTests configs , providersTests configs providerToken netId ] From 94f9626f327b45a393788c9509b194a488385a7c Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 7 Oct 2024 18:03:36 +0530 Subject: [PATCH 3/4] test(#361): move read simple-script test from file to dedicated module --- tests/GeniusYield/Test/SimpleScript.hs | 13 +++++++++++-- tests/atlas-tests.hs | 13 ------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tests/GeniusYield/Test/SimpleScript.hs b/tests/GeniusYield/Test/SimpleScript.hs index e6f20e3f..7968b763 100644 --- a/tests/GeniusYield/Test/SimpleScript.hs +++ b/tests/GeniusYield/Test/SimpleScript.hs @@ -8,13 +8,22 @@ import GeniusYield.GYConfig import GeniusYield.Test.Privnet.Asserts (assertEqual) import GeniusYield.Types import Test.Tasty (TestTree, testGroup) -import Test.Tasty.HUnit (testCase) +import Test.Tasty.HUnit (testCase, (@?=)) simpleScriptTests :: [GYCoreConfig] -> TestTree simpleScriptTests configs = testGroup "simple-script" - [ testCase "able to read on-chain simple script" $ do + [ 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"] diff --git a/tests/atlas-tests.hs b/tests/atlas-tests.hs index 77d86e19..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 @@ -75,15 +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 @@ -119,6 +109,3 @@ findPackageRoot = do if here then return "." else fail "Cannot find package root" - -mockDataDir :: FilePath -mockDataDir = "tests/mock-data" From eed687ff62657bc623e259b0485ecc416b00c360 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 7 Oct 2024 18:23:27 +0530 Subject: [PATCH 4/4] style(#361): remove redundant import --- tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs b/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs index ccbe7efe..5d686615 100644 --- a/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs +++ b/tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs @@ -8,7 +8,6 @@ import GeniusYield.Test.Privnet.Asserts (assertEqual) import GeniusYield.Test.Privnet.Ctx import GeniusYield.Test.Privnet.Setup import GeniusYield.TxBuilder -import GeniusYield.TxBuilder (GYTxQueryMonad (utxoAtTxOutRef)) import GeniusYield.Types import GeniusYield.Types.Script (GYAnyScript (GYSimpleScript)) import GeniusYield.Types.UTxO (GYUTxO (utxoRefScript))