Skip to content

Commit 75a3c9f

Browse files
authored
strip ALL pact value infos, recursively as well, add tests (#1287)
* strip ALL pact value infos, recursively as well, add tests * changelog entry
1 parent 030e255 commit 75a3c9f

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---
33
### Bugfixes
44
- Fix name resolution within module redeploy (#1235)
5-
- Fixed issue with the hash of cap guards, `hash` native and principals (#1273) (#1278)
5+
- Fixed issue with the hash of cap guards, `hash` native and principals (#1273) (#1278) (#1287)
66
- Fixed error message for calling a non-function value (#1268)
77

88
### Eval

src/Pact/Eval.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ enforcePactValue :: Pretty n => (Term n) -> Eval e PactValue
11341134
enforcePactValue t = case toPactValue t of
11351135
Left s -> evalError' t $ "Only value-level terms permitted: " <> pretty s
11361136
Right v -> do
1137-
elide <- ifExecutionFlagSet' FlagDisablePact48 id elideModRefInfo
1137+
elide <- ifExecutionFlagSet' FlagDisablePact48 id stripAllPactValueInfo
11381138
return (elide v)
11391139

11401140
reduceApp :: App (Term Ref) -> Eval e (Term Name)

src/Pact/Types/PactValue.hs

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module Pact.Types.PactValue
3333
, _PObject
3434
, _PModRef
3535
, stripPactValueInfo
36+
, stripAllPactValueInfo
3637
) where
3738

3839
import Control.Applicative ((<|>))
@@ -129,6 +130,14 @@ stripPactValueInfo = \case
129130
PGuard gu -> PGuard gu
130131
PModRef mr -> PModRef mr{_modRefInfo = def }
131132

133+
stripAllPactValueInfo :: PactValue -> PactValue
134+
stripAllPactValueInfo = \case
135+
PLiteral lit -> PLiteral lit
136+
PList vec -> PList (stripAllPactValueInfo <$> vec)
137+
PObject om -> PObject (stripAllPactValueInfo <$> om)
138+
PGuard gu -> PGuard (stripAllPactValueInfo <$> gu)
139+
PModRef mr -> PModRef mr{_modRefInfo = def }
140+
132141
-- | Lenient conversion, implying that conversion back won't necc. succeed.
133142
-- Integers are coerced to Decimal for simple representation.
134143
-- Non-value types are turned into their String representation.

tests/pact/hash.repl

+24-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44

55
(begin-tx)
66
(env-exec-config ["DisablePact48"])
7+
(interface iface
8+
(defun f:bool (a:module{iface}))
9+
)
710

811
(module my-mod G
912
(defcap G() true)
1013

1114
(defschema hashes h:string)
1215
(deftable hashes-table:{hashes})
16+
(implements iface)
1317

1418
(defun get-hash (k:string)
1519
(at "h" (read hashes-table k)))
1620

21+
(defun f:bool (a:module{iface}) true)
22+
1723
(defun insert-hash (k:string h:string)
1824
(write hashes-table k {"h":h})
1925
(concat ["added hash ", h, " to table"])
@@ -25,27 +31,39 @@
2531
; pre fork module hashing
2632
(insert-hash "a" (hash my-mod))
2733
(insert-hash "b" (hash my-mod))
34+
(insert-hash "c" (hash [my-mod, {'a:my-mod}, (create-user-guard (f my-mod))]))
35+
(insert-hash "d" (hash [my-mod, {'a:my-mod}, (create-user-guard (f my-mod))]))
2836
(let*
2937
( (h1 (get-hash "a"))
3038
(h2 (get-hash "b"))
39+
(h3 (get-hash "c"))
40+
(h4 (get-hash "d"))
3141
)
32-
(enforce (= h1 "eU1QsrHzLyYN9620ongvIlpxzzX1KiVGbTDBT6zbh14") "h1 does not match expected value")
33-
(enforce (= h2 "q9JZXDohMARxsVUtQWCiK7APdaiYpvqfJyq-aF3LhAA") "h2 does not match expected value")
34-
(expect-failure "hashes do not match pre-fork" (enforce (= h1 h2) "boom"))
42+
(enforce (= h1 "orgMn9G2BN4Mvq4IX7XbF016YdAhoLLtEIpUPglM3-c") "h1 does not match expected value")
43+
(enforce (= h2 "A7RKCqSxlJMPSoZshF2Rviny30yVUXK6CDnjfwKc-dU") "h2 does not match expected value")
44+
(enforce (= h3 "2Hic2Iy60yTYtCn1Ih6J7X359KAjPjdOkyEUGbR9pa8") "h3 does not match expected value")
45+
(enforce (= h4 "ltxrif1Y_w9qg2pM-V93lMjU15HIA48WBqp3RzlZ0cU") "h4 does not match expected value")
46+
(expect-failure "hashes do not match pre-fork - simple case" (enforce (= h1 h2) "boom"))
47+
(expect-failure "hashes do not match pre-fork - recursive case" (enforce (= h3 h4) "boom"))
3548
)
3649

3750

3851
(env-exec-config [])
3952
; post fork module hashing
4053
(insert-hash "a" (hash my-mod))
4154
(insert-hash "b" (hash my-mod))
42-
55+
(insert-hash "c" (hash [my-mod, {'a:my-mod}, (create-user-guard (f my-mod))]))
56+
(insert-hash "d" (hash [my-mod, {'a:my-mod}, (create-user-guard (f my-mod))]))
4357

4458
(let*
4559
( (h1 (get-hash "a"))
4660
(h2 (get-hash "b"))
61+
(h3 (get-hash "c"))
62+
(h4 (get-hash "d"))
4763
)
48-
(enforce (= h1 "0j95GFheG-uAWbGAjvTqV4QSGE74ZY38jxnNuHJ2p8A") "h1 does not match expected value")
49-
(expect "hashes match post-fork" true (enforce (= h1 h2) "boom"))
64+
(enforce (= h1 "vediBPdnKkzahPDZY2UF_hkS8i7pIXqwsCj925gLng8") "h1 does not match expected value")
65+
(enforce (= h3 "_c98nMfdnxKUdjoE7EQR9RUHfqJDJjlljL2JGGwUqiA") "h3 does not match expected value")
66+
(expect "hashes match post-fork - simple case" true (enforce (= h1 h2) "boom"))
67+
(expect "hashes match post-fork - recursive case" true (enforce (= h1 h2) "boom"))
5068
)
5169
(commit-tx)

0 commit comments

Comments
 (0)