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: aiken-based bet-ref example #358

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cabal.project.local~
.DS_Store
maestro-config.json
blockfrost-config.json
log.txt
*.skey
.direnv
secrets/
Expand Down
3 changes: 3 additions & 0 deletions atlas-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ test-suite atlas-unified-tests
build-depends:
atlas-cardano,
base,
bytestring,
cardano-api,
containers,
extra,
lens,
mtl,
plutus-core,
plutus-ledger-api,
Expand Down
8 changes: 5 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ source-repository-package
-- TODO: Temporary, until proposed changes are in upstream (track https://github.com/mlabs-haskell/clb/pull/44)
source-repository-package
type: git
location: https://github.com/sourabhxyz/clb
tag: 09414a93047b4c7f6e03e20d1730c9c0f88e1d46
--sha256: sha256-y5fF8IDywt/pQ3HsRE6CpAlqK4uiU/SRuDIqSHxBED0=
location: https://github.com/mlabs-haskell/clb
tag: 080e2b4852f162d33e8a3d5e2faaa9b5400d878c
--sha256: sha256-IazNffJyUIPZh3ypiSBpfdZAenWD5oixfzrhYJlrI8s=
subdir:
clb

-- Obtaining cardano-node stuff for 9.1.0. These aren't published on CHaP yet.
source-repository-package
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
cabal = {} ;
hlint = {};
haskell-language-server = {};
fourmolu = {};
};
# Non-Haskell shell tools go here
shell.buildInputs = with pkgs; [
Expand Down
28 changes: 14 additions & 14 deletions src/GeniusYield/Test/Clb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ import Cardano.Slotting.Time (
)
import Clb (
Clb,
ClbConfig (..),
ClbState (..),
ClbT,
EmulatedLedgerState (..),
Log (Log),
LogEntry (LogEntry),
LogLevel (..),
MockConfig (..),
SlotConfig (..),
ValidationResult (..),
getCurrentSlot,
getFails,
logError,
logInfo,
sendTx,
submitTx,
txOutRefAt,
txOutRefAtPaymentCred,
unLog,
Expand Down Expand Up @@ -162,7 +162,7 @@ liftClb = GYTxMonadClb . lift . lift . lift . lift
-}
mkTestFor :: String -> (TestInfo -> GYTxMonadClb a) -> Tasty.TestTree
mkTestFor name action =
testNoErrorsTraceClb v w Clb.defaultConway name $ do
testNoErrorsTraceClb v w Clb.defaultConwayClbConfig name $ do
asClb pureGen (w1 testWallets) nextWalletInt $
action TestInfo {testGoldAsset = fakeCoin fakeGold, testIronAsset = fakeCoin fakeIron, testWallets}
where
Expand Down Expand Up @@ -196,17 +196,17 @@ mkTestFor name action =
nextWalletInt = 10

-- \| Helper for building tests
testNoErrorsTraceClb :: GYValue -> GYValue -> Clb.MockConfig ApiEra -> String -> AtlasClb a -> Tasty.TestTree
testNoErrorsTraceClb :: GYValue -> GYValue -> Clb.ClbConfig ApiEra -> String -> AtlasClb a -> Tasty.TestTree
testNoErrorsTraceClb funds walletFunds cfg msg act =
testCaseInfo msg $
maybe (pure mockLog) assertFailure $
mbErrors >>= \errors -> pure (mockLog <> "\n\nError :\n-------\n" <> errors)
where
-- _errors since we decided to store errors in the log as well.
(mbErrors, mock) = Clb.runClb (act >> Clb.checkErrors) $ Clb.initClb cfg (valueToApi funds) (valueToApi walletFunds)
(mbErrors, mock) = Clb.runClb (act >> Clb.checkErrors) $ Clb.initClb cfg (valueToApi funds) (valueToApi walletFunds) Nothing
mockLog = "\nEmulator log :\n--------------\n" <> logString
options = defaultLayoutOptions {layoutPageWidth = AvailablePerLine 150 1.0}
logDoc = Clb.ppLog $ Clb.mockInfo mock
logDoc = Clb.ppLog $ Clb._clbLog mock
logString = renderString $ layoutPretty options logDoc

mkSimpleWallet :: TL.KeyPair r L.StandardCrypto -> User
Expand Down Expand Up @@ -238,12 +238,12 @@ mustFailWith isExpectedError act = do
tryError (void act) >>= \case
Left e@(isExpectedError -> True) -> do
gyLogInfo' "" . printf "Successfully caught expected exception %s" $ show e
infoLog <- liftClb $ gets mockInfo
infoLog <- liftClb $ gets (^. Clb.clbLog)
postFails <- liftClb getFails
liftClb $
put
st
{ mockInfo = infoLog <> mkMustFailLog preFails postFails
{ _clbLog = infoLog <> mkMustFailLog preFails postFails
-- , mustFailLog = mkMustFailLog preFails postFails
}
Left err -> liftClb $ logError $ "Action failed with unexpected exception: " ++ show err
Expand All @@ -260,7 +260,7 @@ instance MonadError GYTxMonadException GYTxMonadClb where

instance GYTxQueryMonad GYTxMonadClb where
networkId = do
magic <- liftClb $ gets (mockConfigNetworkId . mockConfig)
magic <- liftClb $ gets (clbConfigNetworkId . Clb._clbConfig)
-- TODO: Add epoch slots and network era to clb and retrieve from there.
pure . GYPrivnet $
GYNetworkInfo
Expand All @@ -270,7 +270,7 @@ instance GYTxQueryMonad GYTxMonadClb where

lookupDatum :: GYDatumHash -> GYTxMonadClb (Maybe GYDatum)
lookupDatum h = liftClb $ do
mdh <- gets mockDatums
mdh <- gets (^. Clb.knownDatums)
return $ do
d <- Map.lookup (datumHashToPlutus h) mdh
return $ datumFromPlutus d
Expand Down Expand Up @@ -309,7 +309,7 @@ instance GYTxQueryMonad GYTxMonadClb where

utxoAtTxOutRef ref = do
-- All UTxOs map
utxos <- liftClb $ gets (L.unUTxO . L.S.utxosUtxo . L.S.lsUTxOState . _memPoolState . emulatedLedgerState)
utxos <- liftClb $ gets (L.unUTxO . L.S.utxosUtxo . L.S.lsUTxOState . Clb._ledgerState . Clb._chainState)
-- Maps keys to Plutus TxOutRef
let m = Map.mapKeys (txOutRefToPlutus . txOutRefFromApi . Api.S.fromShelleyTxIn) utxos

Expand Down Expand Up @@ -412,7 +412,7 @@ instance GYTxMonad GYTxMonadClb where
let txBody = getTxBody tx
dumpBody txBody
gyLogDebug' "" $ "encoded tx: " <> txToHex tx
vRes <- liftClb . sendTx $ txToApi tx
vRes <- liftClb . Clb.submitTx $ txToApi tx
case vRes of
Success _state _onChainTx -> pure $ txBodyTxId txBody
Fail _ err -> throwAppError . someBackendError . T.pack $ show err
Expand Down Expand Up @@ -469,14 +469,14 @@ instance GYTxGameMonad GYTxMonadClb where

slotConfig' :: GYTxMonadClb (UTCTime, NominalDiffTime)
slotConfig' = liftClb $ do
sc <- gets $ mockConfigSlotConfig . mockConfig
sc <- gets $ Clb.clbConfigSlotConfig . _clbConfig
let len = fromInteger (scSlotLength sc) / 1000
zero = posixSecondsToUTCTime $ timeToPOSIX $ timeFromPlutus $ scSlotZeroTime sc
return (zero, len)

protocolParameters :: GYTxMonadClb (ConwayCore.PParams (Api.S.ShelleyLedgerEra ApiEra))
protocolParameters = do
pparams <- liftClb $ gets $ mockConfigProtocol . mockConfig
pparams <- liftClb $ gets $ clbConfigProtocol . _clbConfig
pure $ coerce pparams

instance GYTxSpecialQueryMonad GYTxMonadClb where
Expand Down
Loading