Skip to content

Commit

Permalink
adapt to traces
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Nov 7, 2024
1 parent c468d24 commit 0d6dfe7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
16 changes: 13 additions & 3 deletions app/Commands/Dev/Nockma/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ runCommand opts = do
t@(TermCell {}) -> case opts ^. nockmaRunAnomaDir of
Just path -> do
anomaDir <- AnomaPath <$> fromAppPathDir path
runInAnoma anomaDir t (fromMaybe [] (unfoldList <$> parsedArgs))
runInAnoma anomaDir t (maybe [] unfoldList parsedArgs)
Nothing -> do
let formula = anomaCallTuple parsedArgs
(counts, res) <-
Expand All @@ -37,5 +37,15 @@ runCommand opts = do

runInAnoma :: (Members AppEffects r) => AnomaPath -> Term Natural -> [Term Natural] -> Sem r ()
runInAnoma anoma t args = runAppError @SimpleError . runAnoma anoma $ do
res <- runNockma t args
putStrLn (ppPrint res)
res <-
runNockma
RunNockmaInput
{ _runNockmaProgram = t,
_runNockmaArgs = args
}
let traces = res ^. runNockmaTraces
renderStdOutLn (annotate AnnImportant $ "Traces (" <> show (length traces) <> "):")
forM_ traces $ \tr ->
renderStdOutLn (ppPrint tr)
renderStdOutLn (annotate AnnImportant "Result:")
renderStdOutLn (ppPrint (res ^. runNockmaResult))
6 changes: 0 additions & 6 deletions src/Anoma/Effect/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ grpcCliProcess method = do
std_out = CreatePipe
}

-- | Assumes the node and client are already running
-- runAnomaTest :: forall r a. (Members '[Reader ListenPort, Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a
-- runAnomaTest anomapath body = runReader anomapath . runProcess $
-- (`interpret` inject body) $ \case
-- GetAnomaProcesses -> error "unsupported"
-- AnomaRpc method i -> anomaRpc' method i
runAnoma :: forall r a. (Members '[Logger, EmbedIO, Error SimpleError] r) => AnomaPath -> Sem (Anoma ': r) a -> Sem r a
runAnoma anomapath body = runReader anomapath . runProcess $
withSpawnAnomaNode $ \grpcport _nodeOut nodeH ->
Expand Down
32 changes: 22 additions & 10 deletions src/Anoma/Effect/RunNockma.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ import Juvix.Prelude.Aeson (ToJSON, Value)
import Juvix.Prelude.Aeson qualified as Aeson

data RunNockmaInput = RunNockmaInput
{ _runNockmaProgram :: AnomaResult,
_runNockmaInput :: [Nockma.Term Natural]
{ _runNockmaProgram :: Nockma.Term Natural,
_runNockmaArgs :: [Nockma.Term Natural]
}

data RunNockmaResult = RunNockmaResult
{ _runNockmaResult :: Nockma.Term Natural,
_runNockmaTraces :: [Nockma.Term Natural]
}

makeLenses ''RunNockmaInput
makeLenses ''RunNockmaResult

fromJSON :: (Members '[Error SimpleError, Logger] r) => (Aeson.FromJSON a) => Value -> Sem r a
fromJSON v = case Aeson.fromJSON v of
Expand All @@ -28,12 +34,11 @@ fromJSON v = case Aeson.fromJSON v of
runNockma ::
forall r.
(Members '[Anoma, Error SimpleError, Logger] r) =>
Nockma.Term Natural ->
[Nockma.Term Natural] ->
Sem r (Nockma.Term Natural)
runNockma prog inputs = do
let prog' = encodeJam64 prog
args = map (NockInputJammed . encodeJam64) inputs
RunNockmaInput ->
Sem r RunNockmaResult
runNockma i = do
let prog' = encodeJam64 (i ^. runNockmaProgram)
args = map (NockInputJammed . encodeJam64) (i ^. runNockmaArgs)
msg =
RunNock
{ _runNockJammedProgram = prog',
Expand All @@ -44,8 +49,15 @@ runNockma prog inputs = do
logValue title val = logVerbose (mkAnsiText (annotate AnnImportant (pretty title <> ":\n") <> pretty (Aeson.jsonEncodeToPrettyText val)))
logValue "Request Payload" msg
resVal :: Value <- anomaRpc runNockGrpcUrl (Aeson.toJSON msg) >>= fromJSON
logValue "Request Payload" resVal
logValue "Response Payload" resVal
res :: Response <- fromJSON resVal
case res of
ResponseProof x -> decodeCue64 x
ResponseSuccess s -> do
result <- decodeCue64 (s ^. successResult)
traces <- mapM decodeCue64 (s ^. successTraces)
return
RunNockmaResult
{ _runNockmaResult = result,
_runNockmaTraces = traces
}
ResponseError err -> throw (SimpleError (mkAnsiText err))
20 changes: 18 additions & 2 deletions src/Anoma/Rpc/RunNock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,36 @@ $( deriveJSON
''RunNock
)

data NockSuccess = NockSuccess
{ _successResult :: Text,
_successTraces :: [Text]
}

$( deriveJSON
defaultOptions
{ fieldLabelModifier = \case
"_successResult" -> "result"
"_successTraces" -> "output"
_ -> impossibleError "All fields must be covered"
}
''NockSuccess
)

data Response
= ResponseProof Text
= ResponseSuccess NockSuccess
| ResponseError Text

$( deriveJSON
defaultOptions
{ unwrapUnaryRecords = True,
sumEncoding = ObjectWithSingleField,
constructorTagModifier = \case
"ResponseProof" -> "proof"
"ResponseSuccess" -> "success"
"ResponseError" -> "error"
_ -> impossibleError "All constructors must be covered"
}
''Response
)

makeLenses ''Response
makeLenses ''NockSuccess
11 changes: 8 additions & 3 deletions test/Anoma/Compilation/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ mkAnomaNodeTest a@AnomaTest {..} =
. runSimpleErrorHUnit
. runAnoma testAnomaPath
$ do
out <- runNockma program args'
let rinput =
RunNockmaInput
{ _runNockmaProgram = program,
_runNockmaArgs = args'
}
out <- runNockma rinput
runM
. runReader out
. runReader []
. runReader (out ^. runNockmaResult)
. runReader (out ^. runNockmaTraces)
$ _anomaCheck

withRootCopy :: (Prelude.Path Abs Dir -> IO a) -> IO a
Expand Down

0 comments on commit 0d6dfe7

Please sign in to comment.