Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#355): refactor blueprint test to utilise unified testing framework #360

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions atlas-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ test-suite atlas-privnet-tests
bytestring,
containers,
lens,
mtl,
plutus-tx,
tasty,
tasty-hunit
Expand Down
28 changes: 16 additions & 12 deletions tests-privnet/GeniusYield/Test/Privnet/Blueprint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ module GeniusYield.Test.Privnet.Blueprint (
blueprintTests,
) where

import Control.Monad (void)
import Control.Monad.Except (handleError)
import Data.ByteString (ByteString)
import Data.ByteString.Base16 qualified as BS16
import GeniusYield.Test.Privnet.Asserts (assertThrown, isTxBodyErrorAutoBalance)
import GeniusYield.Test.Privnet.Ctx
import GeniusYield.Test.Privnet.Asserts (isTxBodyErrorAutoBalance)
import GeniusYield.Test.Privnet.Setup
import GeniusYield.Test.Utils (TestInfo (testWallets), Wallets (..))
import GeniusYield.TxBuilder
import GeniusYield.Types
import PlutusTx.Builtins qualified as PlutusTx
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCaseSteps)

$(makeBPTypes "tests/aiken/bar/plutus.json")

Expand All @@ -26,25 +27,28 @@ blueprintTests :: Setup -> TestTree
blueprintTests setup =
testGroup
"blueprint"
[ testCaseSteps "e2e blueprint validator test" $ \info -> withSetup info setup $ \ctx -> do
let user = ctxUserF ctx
val = scriptFromBPSerialisedScript $ applyParamsToBPValidator_baz_baz_spend BPBool1True (BPbaz_ParamConstr0ParamConstr 23 (g "ff")) 10 (g "ddee")
[ mkPrivnetTestFor' "e2e blueprint validator test" GYInfo setup $ \(testWallets -> Wallets {w1 = user}) -> do
let val = scriptFromBPSerialisedScript $ applyParamsToBPValidator_baz_baz_spend BPBool1True (BPbaz_ParamConstr0ParamConstr 23 (g "ff")) 10 (g "ddee")
dat = datumFromPlutusData $ BPbaz_MyDatum0DatumA 10 (g "aabbccdd")
oref <- ctxRun ctx user $ do
oref <- asUser user $ do
valAddr <- scriptAddress val
txBody <- buildTxBody $ mustHaveOutput @'PlutusV3 (GYTxOut {gyTxOutValue = valueFromLovelace 10_000_000, gyTxOutRefS = Nothing, gyTxOutDatum = Just (dat, GYTxOutUseInlineDatum), gyTxOutAddress = valAddr})
tid <- signAndSubmitConfirmed txBody
pure $ txOutRefFromTuple (tid, 0)
let satRedeemer = redeemerFromPlutusData $ BPbaz_MyRedeemer0MyRedeemer 5 (g "aabbccddee")
unsatRedeemer = redeemerFromPlutusData $ BPbaz_MyRedeemer0MyRedeemer 6 (g "aabbccddee")
assertThrown isTxBodyErrorAutoBalance $ ctxRun ctx user $ do
buildTxBody $ mustHaveInput @'PlutusV3 $ GYTxIn oref (GYTxInWitnessScript (GYInScript val) dat unsatRedeemer)
info "Successfully failed to consume from blueprint script for unsatisfying redeemer"
tid <- ctxRun ctx user $ do
handleError
(\e -> if isTxBodyErrorAutoBalance e then pure () else throwError e)
$ asUser user
$ do
void $ buildTxBody $ mustHaveInput @'PlutusV3 $ GYTxIn oref (GYTxInWitnessScript (GYInScript val) dat unsatRedeemer)
lg "Successfully failed to consume from blueprint script for unsatisfying redeemer"
tid <- asUser user $ do
txBody <- buildTxBody $ mustHaveInput @'PlutusV3 $ GYTxIn oref (GYTxInWitnessScript (GYInScript val) dat satRedeemer)
signAndSubmitConfirmed txBody
info $ "Successfully consumed from blueprint script, with tx id: " <> show tid
lg $ "Successfully consumed from blueprint script, with tx id: " <> show tid
]
where
g :: ByteString -> PlutusTx.BuiltinByteString
g = PlutusTx.toBuiltin . BS16.decodeLenient
lg = gyLogInfo' "blueprint"
Loading