Skip to content

Commit feb2b05

Browse files
author
euonymos
committed
feat: backport transitionStage
1 parent 1c33ead commit feb2b05

File tree

7 files changed

+46
-41
lines changed

7 files changed

+46
-41
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ haddocks
2727
# Functions changed by runing local testnet
2828
devnet/db
2929
devnet/genesis-*.json
30-
test.log
30+
test.log

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ run-oura-daemon:
1010
@oura daemon --config ./test/daemon.toml
1111

1212
format:
13-
fourmolu --mode inplace $$(git ls-files '*.hs')
13+
fourmolu --mode inplace $$(git ls-files '*.hs')

src/Cardano/CEM.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,18 @@ class
512512

513513
compilationConfig :: CompilationConfig
514514

515+
-- \| This is the map of all possible machine 'Transition's.
516+
-- This statically associates every 'Transition' with
517+
-- a 'Stage' through source/target 'State's.
518+
transitionStage ::
519+
Proxy script ->
520+
Map.Map
521+
(Spine (Transition script))
522+
( Maybe (Spine (State script)) -- source 'State'
523+
, Maybe (Spine (State script)) -- target 'State'
524+
)
525+
transitionStage _ = Map.empty
526+
515527
-- FIXME: No need to use type synonym anymore (was needed due to Plutus)
516528
type CEMScriptDatum script = (Params script, State script)
517529

src/Cardano/CEM/Examples/Auction.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ $(deriveCEMAssociatedTypes False ''SimpleAuction)
6363
instance CEMScript SimpleAuction where
6464
compilationConfig = MkCompilationConfig "AUC"
6565

66+
transitionStage _ =
67+
Map.fromList
68+
[ (CreateSpine, (Nothing, Just NotStartedSpine))
69+
, (StartSpine, (Just NotStartedSpine, Just CurrentBidSpine))
70+
, (MakeBidSpine, (Just CurrentBidSpine, Just CurrentBidSpine))
71+
, (CloseSpine, (Just CurrentBidSpine, Just WinnerSpine))
72+
, (BuyoutSpine, (Just WinnerSpine, Nothing))
73+
]
74+
6675
perTransitionScriptSpec =
6776
Map.fromList
6877
[

src/Cardano/CEM/Indexing/Event.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Cardano.CEM.Indexing.Event where
66
import Cardano.Api qualified as C
77
import Cardano.Api.ScriptData qualified as C
88
import Cardano.Api.SerialiseRaw qualified as SerialiseRaw
9-
import Cardano.CEM (CEMScript, CEMScriptDatum, State, Transition)
9+
import Cardano.CEM (CEMScript (transitionStage), CEMScriptDatum, State, Transition)
1010
import Cardano.CEM.Address qualified as Address
1111
import Cardano.CEM.Indexing.Tx
1212
import Cardano.CEM.OnChain (CEMScriptCompiled)
@@ -93,11 +93,11 @@ extractEvent network tx = do
9393

9494
-- Look up the transition
9595
let transitions =
96-
first
97-
(\(_, b, c) -> (b, c))
98-
. swap
99-
-- <$> Map.toList (transitionStage $ Proxy @script)
100-
<$> Map.toList (undefined $ Proxy @script) -- TODO: backport transitionStage
96+
-- first
97+
-- (\(_, b, c) -> (b, c))
98+
-- .
99+
swap
100+
<$> Map.toList (transitionStage $ Proxy @script)
101101
let transSpine = lookup (mSourceSpine, mTargetSpine) transitions
102102

103103
-- Return

test/Auction.hs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
module Auction where
44

5-
import Prelude
6-
75
import Cardano.Api.NetworkId (toShelleyNetwork)
86
import Cardano.CEM.Examples.Auction
97
import Cardano.CEM.Examples.Compilation ()
@@ -16,20 +14,20 @@ import Cardano.Extras
1614
import Control.Monad.Trans (MonadIO (..))
1715
import Data.Proxy (Proxy (..))
1816
import GHC.IsList
19-
2017
import Plutarch.Script
2118
import PlutusLedgerApi.V1.Value (assetClassValue)
22-
2319
import Test.Hspec (describe, it, shouldBe)
2420
import TestNFT (testNftAssetClass)
25-
import Text.Show.Pretty (ppShow)
2621
import Utils (
2722
execClb,
2823
mintTestTokens,
2924
perTransitionStats,
3025
submitAndCheck,
3126
submitCheckReturn,
3227
)
28+
import Prelude
29+
30+
-- import Text.Show.Pretty (ppShow)
3331

3432
auctionSpec = describe "AuctionSpec" $ do
3533
it "Serialise" $ do
@@ -76,7 +74,8 @@ auctionSpec = describe "AuctionSpec" $ do
7674
]
7775
, specSigner = bidder1
7876
}
79-
Left (PerTransitionErrors _) <- return result
77+
78+
Left CEMScriptTxInResolutionError <- return result
8079

8180
return ()
8281

@@ -258,14 +257,6 @@ auctionSpec = describe "AuctionSpec" $ do
258257

259258
mEvent <- liftIO $ extractEvent @SimpleAuction network $ resolvedTxToOura preBody utxo
260259
liftIO $ mEvent `shouldBe` Just (Following BuyoutSpine)
261-
submitAndCheck $
262-
MkTxSpec
263-
{ actions =
264-
[ MkSomeCEMAction $
265-
MkCEMAction auctionParams Buyout
266-
]
267-
, specSigner = bidder1
268-
}
269260

270-
stats <- perTransitionStats
271-
liftIO $ putStrLn $ ppShow stats
261+
-- stats <- perTransitionStats
262+
-- liftIO $ putStrLn $ ppShow stats

test/Voting.hs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
module Voting (votingSpec) where
22

3-
import Prelude hiding (readFile)
4-
5-
import Control.Monad.IO.Class (MonadIO (..))
6-
import Data.Proxy
7-
8-
import GHC.IsList
9-
import Text.Show.Pretty (ppShow)
10-
11-
import Plutarch.Script
12-
13-
import Test.Hspec (describe, it, shouldBe)
14-
153
import Cardano.CEM.Examples.Compilation ()
164
import Cardano.CEM.Examples.Voting
175
import Cardano.CEM.Monads
186
import Cardano.CEM.OffChain
197
import Cardano.CEM.OnChain
208
import Cardano.Extras (signingKeyToPKH)
219
import Control.Monad.IO.Class (MonadIO (..))
22-
import Test.Hspec (describe, shouldBe)
10+
import Data.Proxy
11+
import GHC.IsList
12+
import Plutarch.Script
13+
import Test.Hspec (describe, it, shouldBe)
2314
import Utils
2415
import Prelude hiding (readFile)
2516

17+
-- import Text.Show.Pretty (ppShow)
18+
2619
votingSpec = describe "Voting" $ do
2720
it "Serialise" $ do
2821
let !script = cemScriptCompiled (Proxy :: Proxy SimpleVoting)
@@ -65,8 +58,8 @@ votingSpec = describe "Voting" $ do
6558
, specSigner = jury1
6659
}
6760

68-
stats <- perTransitionStats
69-
liftIO $ putStrLn $ ppShow stats
61+
-- stats <- perTransitionStats
62+
-- liftIO $ putStrLn $ ppShow stats
7063

7164
submitAndCheck $
7265
MkTxSpec
@@ -81,8 +74,8 @@ votingSpec = describe "Voting" $ do
8174
, specSigner = creator
8275
}
8376

84-
stats <- perTransitionStats
85-
liftIO $ putStrLn $ ppShow stats
77+
-- stats <- perTransitionStats
78+
-- liftIO $ putStrLn $ ppShow stats
8679

8780
Just state <- queryScriptState params
8881
liftIO $ state `shouldBe` Finalized Abstain

0 commit comments

Comments
 (0)