Skip to content

Commit

Permalink
chore: clean up unified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
euonymos committed Aug 25, 2024
1 parent 1fd3b83 commit 15078db
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 231 deletions.
1 change: 1 addition & 0 deletions atlas-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ test-suite atlas-unified-tests
, atlas-cardano
, base
, containers
, extra
, tasty
, tasty-hunit
, text
Expand Down
2 changes: 1 addition & 1 deletion src/GeniusYield/Test/Privnet/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ withSetup' targetSev putLog (Setup cokont) kont = do

-- | Given a test name, runs the test under privnet.
mkPrivnetTestFor :: TestName -> Setup -> (TestInfo -> GYTxGameMonadIO ()) -> TestTree
mkPrivnetTestFor name = mkPrivnetTestFor' name GYInfo
mkPrivnetTestFor name = mkPrivnetTestFor' name GYDebug

-- | Given a test name, runs the test under privnet with target logging severity.
mkPrivnetTestFor' :: TestName -> GYLogSeverity -> Setup -> (TestInfo -> GYTxGameMonadIO ()) -> TestTree
Expand Down
5 changes: 4 additions & 1 deletion src/GeniusYield/Test/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ fakeIron = fromFakeCoin $ FakeCoin "Iron"
-------------------------------------------------------------------------------

-- | General information about the test environment to help in running polymorphic tests.
data TestInfo = TestInfo { testGoldAsset :: !GYAssetClass, testIronAsset :: !GYAssetClass, testWallets :: !Wallets }
data TestInfo = TestInfo
{ testGoldAsset :: !GYAssetClass
, testIronAsset :: !GYAssetClass
, testWallets :: !Wallets }

-- | Available wallets.
data Wallets = Wallets
Expand Down
38 changes: 31 additions & 7 deletions tests-unified/GeniusYield/Test/Unified/BetRef/Operations.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module GeniusYield.Test.Unified.BetRef.Operations
( betRefValidator'
( mkScript
, mkBetRefValidator
, betRefAddress
, placeBet
, takeBets
Expand All @@ -11,13 +12,37 @@ import GeniusYield.Types

import GeniusYield.Test.Unified.OnChain.BetRef.Compiled

-- | Queries the cuurent slot, calculates parameters and builds
-- a script that is ready to be deployed.
mkScript
:: GYTxQueryMonad m
=> Integer -- ^ How many slots betting should be open
-> Integer -- ^ How many slots should pass before oracle reveals answer
-> GYPubKeyHash -- ^ Oracle PKH
-> GYValue -- ^ Bet step value
-> m (BetRefParams, GYScript PlutusV2)
mkScript betUntil betReveal oraclePkh betStep = do
currSlot <- slotToInteger <$> slotOfCurrentBlock
-- Calculate params for the script
let betUntil' = slotFromApi $ fromInteger $ currSlot + betUntil
let betReveal' = slotFromApi $ fromInteger $ currSlot + betReveal
betUntilTime <- slotToBeginTime betUntil'
betRevealTime <- slotToBeginTime betReveal'
let params = BetRefParams
(pubKeyHashToPlutus oraclePkh)
(timeToPlutus betUntilTime)
(timeToPlutus betRevealTime)
(valueToPlutus betStep)
gyLogDebug' "" $ printf "Parameters: %s" (show params)
pure (params, validatorToScript $ mkBetRefValidator params)

-- | Validator in question, obtained after giving required parameters.
betRefValidator' :: BetRefParams -> GYValidator 'PlutusV2
betRefValidator' brp = validatorFromPlutus $ betRefValidator brp
mkBetRefValidator :: BetRefParams -> GYValidator 'PlutusV2
mkBetRefValidator brp = validatorFromPlutus $ betRefValidator brp

-- | Address of the validator, given params.
betRefAddress :: (HasCallStack, GYTxQueryMonad m) => BetRefParams -> m GYAddress
betRefAddress brp = scriptAddress $ betRefValidator' brp
betRefAddress brp = scriptAddress $ mkBetRefValidator brp

-- | Operation to place bet.
placeBet :: (HasCallStack, GYTxQueryMonad m)
Expand Down Expand Up @@ -66,7 +91,7 @@ placeBet refScript brp guess bet ownAddr mPreviousBetsUtxoRef = do
<> mustBeSignedBy pkh

-- | Operation to take UTxO corresponding to previous bets.
takeBets :: (HasCallStack, GYTxMonad m)
takeBets :: (HasCallStack, GYTxQueryMonad m)
=> GYTxOutRef -- ^ Reference Script.
-> BetRefParams -- ^ Validator params.
-> GYTxOutRef -- ^ Script UTxO to consume.
Expand All @@ -89,9 +114,8 @@ input :: BetRefParams -> GYTxOutRef -> GYTxOutRef -> BetRefDatum -> BetRefAction
input brp refScript inputRef dat red =
mustHaveInput GYTxIn
{ gyTxInTxOutRef = inputRef
-- , gyTxInWitness = GYTxInWitnessKey
, gyTxInWitness = GYTxInWitnessScript
(GYInReference refScript $ validatorToScript $ betRefValidator' brp)
(GYInReference refScript $ validatorToScript $ mkBetRefValidator brp)
(datumFromPlutusData dat)
(redeemerFromPlutusData red)
}
Loading

0 comments on commit 15078db

Please sign in to comment.