@@ -81,6 +81,8 @@ import Convex.MockChain.Defaults qualified as Defaults
8181import Convex.MonadLog (MonadLog )
8282import Convex.NodeParams (NodeParams (.. ), ledgerProtocolParameters )
8383import Convex.ThreatModel (ExceptT , ThreatModel , ThreatModelEnv (.. ), ThreatModelOutcome (.. ), getThreatModelName , runExceptT , runThreatModelCheck )
84+ import Convex.ThreatModel.Cardano.Api (mockWalletHashes , txSigners )
85+ import Convex.Wallet (Wallet )
8486import Convex.Wallet.MockWallet qualified as Wallet
8587import Data.Aeson (ToJSON (.. ), (.=) )
8688import Data.Aeson qualified as Aeson
@@ -90,7 +92,7 @@ import Data.ByteString.Lazy.Char8 qualified as LBS
9092import Data.Foldable (foldl' , for_ , traverse_ )
9193import Data.IORef (IORef , modifyIORef , newIORef , readIORef )
9294import Data.Map qualified as Map
93- import Data.Maybe (fromMaybe )
95+ import Data.Maybe (fromMaybe , mapMaybe )
9496import Data.Set qualified as Set
9597import Data.Word (Word32 )
9698import GHC.Generics (Generic )
@@ -110,6 +112,18 @@ import PlutusTx.Coverage (
110112import Prettyprinter qualified as Pretty
111113import System.Exit (ExitCode )
112114
115+ {- | Detect which mock wallet signed a transaction by examining its witnesses.
116+ Returns an error message if no known mock wallet is found among the signers.
117+ -}
118+ detectSigningWallet :: C. Tx C. ConwayEra -> Either String Wallet
119+ detectSigningWallet tx =
120+ case txSigners tx of
121+ [] -> Left " Transaction has no signers — cannot determine wallet for threat model"
122+ signers ->
123+ case mapMaybe (\ h -> lookup h mockWalletHashes) signers of
124+ (w : _) -> Right w
125+ [] -> Left " Transaction signers do not match any known mock wallet"
126+
113127{- | A testing interface defines the state and behavior of one or more smart contracts.
114128
115129The type parameter @state@ represents the model's view of the world. It should
@@ -460,9 +474,12 @@ positiveTest opts mGetTmResultsRef tms evs (Actions actions) = monadicIO $ do
460474 -- Run each threat model in an isolated MockchainT context
461475 liftIO $ forM allToRun $ \ tm -> do
462476 let name = fromMaybe " Unnamed" (getThreatModelName tm)
463- (outcome, tmFinalState) <-
464- runMockchainIO (runThreatModelCheck Wallet. w1 tm [env]) params mcState
465- pure (name, outcome, mcsCoverageData tmFinalState)
477+ case detectSigningWallet tx of
478+ Left err -> pure (name, TMError err, mempty )
479+ Right wallet -> do
480+ (outcome, tmFinalState) <-
481+ runMockchainIO (runThreatModelCheck wallet tm [env]) params mcState
482+ pure (name, outcome, mcsCoverageData tmFinalState)
466483 _ -> pure []
467484
468485 -- Extract just the (name, outcome) pairs for downstream processing
0 commit comments