-- | Unit tests for Lorentz.
module Lorentz.Test.Unit
    ( expectContractEntrypoints
    ) where

import Test.HUnit (Assertion, assertFailure)

import Lorentz hiding (contract)
import Michelson.Test.Unit (matchContractEntryPoints)
import Michelson.Typed (convertFullContract)

-- | Expect the given contract to have some specific entrypoints.
expectContractEntrypoints
  :: forall expectedEps contractEps st.
     ( NiceParameterFull expectedEps
     , NiceParameterFull contractEps
     , NiceStorage st
     )
  => Contract contractEps st -> Assertion
expectContractEntrypoints contract =
  withDict (niceParameterEvi @expectedEps) $
  withDict (niceParameterEvi @contractEps) $
  withDict (niceStorageEvi @st) $ do
    let entrypoints = flattenEntryPoints $ parameterEntryPointsToNotes @expectedEps
        contract' = convertFullContract . compileLorentzContract $ contract
    case matchContractEntryPoints contract' entrypoints of
      Left eps -> assertFailure $ "Some entrypoints were not found " <> show eps
      Right _ -> pass