Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix enforce-pact-version decimal parser #1334

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Pact/Native.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,21 +1238,23 @@ enforceVersion i as = do
pactVersion'
<- if cond then pure compatVersion else checkNonLocalAllowed i $> pactVersion
case as of
[TLitString minVersion] -> doMin minVersion pactVersion' >> return (toTerm True)
[TLitString minVersion] -> doMin minVersion pactVersion' $> toTerm True
[TLitString minVersion,TLitString maxVersion] ->
doMin minVersion pactVersion' >> doMax maxVersion pactVersion' >> return (toTerm True)
doMin minVersion pactVersion' >> doMax maxVersion pactVersion' $> toTerm True
_ -> argsError i as
where
compatVersion :: Text
compatVersion = "4.2.1"
doMin = doMatch "minimum" (>) (<)
doMax = doMatch "maximum" (<) (>)
doMatch msg failCmp succCmp fullV pactVersion' =
doMatch msg failCmp succCmp fullV pactVersion' = do
foldM_ matchPart False $ zip (T.splitOn "." pactVersion') (T.splitOn "." fullV)
where
parseNum orgV s = case AP.parseOnly (AP.many1 AP.digit) s of
parseNum :: Text -> Text -> Eval e Integer
parseNum orgV s = case AP.parseOnly AP.decimal s of
Left _ -> evalError' i $ "Invalid version component: " <> pretty (orgV,s)
Right v -> return v

matchPart True _ = return True
matchPart _ (pv,mv) = do
pv' <- parseNum pactVersion' pv
Expand Down
26 changes: 26 additions & 0 deletions tests/pact/versions.repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


(expect
"pact version bounds work for current pact version"
true
(enforce-pact-version "3.0.0" "6.0.0"))

(expect
"enforce-pact-version works for current pact version"
true
(enforce-pact-version (pact-version)))

(expect-failure
"pact version bounds fail for current version if wrong bounds"
(enforce-pact-version "6.0.0" "100.0.0"))

;; regression #1327
(expect
"enforce-pact-version succeeds for current version if lower bound set"
true
(enforce-pact-version "1.0.0"))

(expect
"enforce-pact-version succeeds (double digit regression)"
true
(enforce-pact-version "3.0000.0" "88.420.0"))
Loading