Skip to content

Commit

Permalink
fix gas costing and add gas tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg committed Feb 22, 2024
1 parent f899c60 commit 2e2703d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Pact/Gas/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ defaultGasTable =

,("poseidon-hash-hack-a-chain", 124)
,("hyperlane-message-id", 2)
,("hyperlane-decode-token-message", 2)
]

{-# NOINLINE defaultGasTable #-}
Expand Down
3 changes: 1 addition & 2 deletions src/Pact/Native.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,6 @@ hyperlaneDecodeTokenMessageDef =
where
getWord256be = get @Word256

-- TODO: We check the size. Is this ok?
-- | Reads a given number of bytes and the rest because binary data padded up to 32 bytes.
getRecipient :: Word256 -> Get BS.ByteString
getRecipient size = do
Expand Down Expand Up @@ -1729,4 +1728,4 @@ padRight s =

-- | Returns the modular of 32 bytes.
restSize :: Integral a => a -> a
restSize size = (32 - size) `mod` 32
restSize size = (32 - size) `mod` 32
14 changes: 13 additions & 1 deletion tests/pact/hyperlane.repl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@
(expect-failure
"Decoding requires recipient to be a guard."
(hyperlane-decode-token-message "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAewAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEJrOjQ2MmU5N2EwOTk5ODdmNTVmNmEyYjUyZTdiZmQ1MmEzNmI0YjViNDcwZmVkMDgxNmEzZDliMjZmOTQ1MGJhNjkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
)
)

; Gas tests.
(env-gasmodel "table")
(env-gaslimit 10000)

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