Skip to content

Commit

Permalink
Merge pull request #363 from geniusyield/refactor-bp-test
Browse files Browse the repository at this point in the history
feat(#361): test for reading simple script for Maestro, BF provider
  • Loading branch information
4TT1L4 authored Oct 9, 2024
2 parents 04c69a4 + b863148 commit abc35af
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions atlas-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/GeniusYield/Types/Script/SimpleScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Check warning on line 12 in tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs

View workflow job for this annotation

GitHub Actions / validate / build

The import of ‘GeniusYield.Types.Script’ is redundant
import GeniusYield.Types.UTxO (GYUTxO (utxoRefScript))

Check warning on line 13 in tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs

View workflow job for this annotation

GitHub Actions / validate / build

The import of ‘GeniusYield.Types.UTxO’ is redundant
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCaseSteps)

Expand Down Expand Up @@ -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]
Expand Down
31 changes: 31 additions & 0 deletions tests/GeniusYield/Test/SimpleScript.hs
Original file line number Diff line number Diff line change
@@ -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)
]
9 changes: 2 additions & 7 deletions tests/atlas-tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Test.Tasty.HUnit (
assertEqual,
testCase,
(@=?),
(@?=),
)

import GeniusYield.Examples.Gift
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -85,6 +82,7 @@ main = do
, refInputTests
, feeTrackingTests
, stakeTests (head configs)
, simpleScriptTests configs
, providersTests configs providerToken netId
]

Expand All @@ -111,6 +109,3 @@ findPackageRoot = do
if here
then return "."
else fail "Cannot find package root"

mockDataDir :: FilePath
mockDataDir = "tests/mock-data"

0 comments on commit abc35af

Please sign in to comment.