Skip to content

Commit

Permalink
fix hyperlane gas tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Apr 2, 2024
1 parent 4245018 commit 3835bc8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Pact/GasModel/GasTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ import Pact.JSON.Legacy.Value

-- | Gas benchmark tests for Pact native functions
allNatives :: [NativeDefName]
allNatives = map fst (concatMap snd natives) <> nonNatives
allNatives = map fst (concatMap snd enhancedNatives) <> nonNatives
where
-- Note: Since we are forking natives, the `natives` list
-- does not fully capture all available natives for the tests.
enhancedNatives = hyperlaneAmendedDefs:natives

-- | Non-native concepts to benchmark
nonNatives :: [NativeDefName]
Expand Down
3 changes: 2 additions & 1 deletion src/Pact/Native.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
module Pact.Native
( natives
, nativeDefs
, hyperlaneAmendedDefs
, pact412NativeDefs
, moduleToMap
, distinctDef
Expand Down Expand Up @@ -146,7 +147,7 @@ nativeDefs :: HM.HashMap Text Ref
nativeDefs = mconcat $ map moduleToMap (hyperlaneDefs:natives)

pact412NativeDefs :: HM.HashMap Text Ref
pact412NativeDefs = mconcat $ map moduleToMap $ hyperlaneAmendedDefs:natives
pact412NativeDefs = foldMap moduleToMap $ hyperlaneAmendedDefs:natives

moduleToMap :: NativeModule -> HM.HashMap Text Ref
moduleToMap = HM.fromList . map (asString *** Direct) . snd
Expand Down
9 changes: 6 additions & 3 deletions tests/GasModelSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ untestedNativesCheck = do
, "verify-spv"
, "public-chain-data"
, "dec"
, "hyperlane-decode-token-message"
, "hyperlane-token-erc20","hyperlane-token-msg"
, "list"
, "continue"
, "hyperlane-decode-token-message"
])

allGasTestsAndGoldenShouldPass :: Spec
Expand Down Expand Up @@ -138,14 +139,16 @@ goldenSizeOfPactValues = do
allNativesInGasTable :: Spec
allNativesInGasTable = do
it "all native functions should be in gas table" $ do
let justNatives = map (asString . fst) (concatMap snd natives)
let justNatives = map (asString . fst) (concatMap snd $ hyperlaneAmendedDefs:natives)
absent li name = case (Map.lookup name defaultGasTable) of
Nothing -> name : li
Just _ -> li
absentNatives = foldl' absent [] justNatives
(S.fromList absentNatives)
`shouldBe`
(S.fromList ["CHARSET_ASCII", "CHARSET_LATIN1", "public-chain-data", "list"])
(S.fromList ["CHARSET_ASCII", "CHARSET_LATIN1"
,"hyperlane-token-erc20", "hyperlane-token-msg"
,"public-chain-data", "list"])

-- | Use this to run a single named test.
_runNative :: NativeDefName -> IO (Maybe [(T.Text,Gas)])
Expand Down

0 comments on commit 3835bc8

Please sign in to comment.