From f2b45e64eaa4579d131849206dccd9bf340a6eea Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 25 Jul 2023 11:42:23 -0700 Subject: [PATCH 1/2] Modify encoding to not output "i":null in JSON --- src/Pact/Types/Term.hs | 65 ++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/src/Pact/Types/Term.hs b/src/Pact/Types/Term.hs index 3a691ac56..05ec3f3e4 100644 --- a/src/Pact/Types/Term.hs +++ b/src/Pact/Types/Term.hs @@ -752,84 +752,75 @@ unprop t = TermUnknown (show t) instance J.Encode n => J.Encode (Term n) where build = \case - (TModule d b i) -> J.object + (TModule d b i) -> J.object $ [ prop TermBody J..= b , prop TermModule J..= d - , inf i - ] - (TList ts ty i) -> J.object + ] ++ inf i + (TList ts ty i) -> J.object $ [ prop TermList J..= J.Array ts , prop TermType J..= ty - , inf i - ] + ] ++ inf i (TDef d _i) -> J.build d -- TNative intentionally not marshallable - (TNative n _fn tys _exs d tl i) -> J.object + (TNative n _fn tys _exs d tl i) -> J.object $ [ prop TermNatFunTypes J..= J.Array tys , prop TermName J..= n , prop TermFun J..= J.null {- TODO fn -} , prop TermNatTopLevel J..= tl , prop TermNatExamples J..= J.null {- TODO exs -} , prop TermNatDocs J..= d - , inf i - ] - (TConst d m c met i) -> J.object + ] ++ inf i + (TConst d m c met i) -> J.object $ [ prop TermModName J..= m , prop TermConstArg J..= d , prop TermMeta J..= met , prop TermConstVal J..= c - , inf i - ] + ] ++ inf i (TApp a _i) -> J.build a - (TVar n i) -> J.object + (TVar n i) -> J.object $ [ prop TermVar J..= n - , inf i - ] - (TBinding bs b c i) -> J.object + ] ++ inf i + (TBinding bs b c i) -> J.object $ [ prop TermBody J..= b , prop TermPairs J..= J.Array bs , prop TermType J..= c - , inf i - ] + ] ++ inf i (TObject o _i) -> J.build o - (TLiteral l i) -> J.object - [ inf i - , prop TermLiteral J..= l + (TLiteral l i) -> J.object $ + inf i ++ + [ prop TermLiteral J..= l ] (TLam tlam _i) -> J.build tlam - (TGuard k i) -> J.object + (TGuard k i) -> J.object $ [ prop TermGuard J..= k - , inf i - ] + ] ++ inf i (TUse u _i) -> J.build u - (TStep s tmeta i) -> J.object + (TStep s tmeta i) -> J.object $ [ prop TermBody J..= s , prop TermMeta J..= tmeta - , inf i - ] - (TSchema sn smod smeta sfs i) -> J.object + ] ++ inf i + (TSchema sn smod smeta sfs i) -> J.object $ [ prop TermModName J..= smod , prop TermName J..= sn , prop TermMeta J..= smeta - , inf i - , prop TermFields J..= J.Array sfs + ] ++ inf i ++ + [ prop TermFields J..= J.Array sfs ] - (TTable tn tmod th tty tmeta i) -> J.object + (TTable tn tmod th tty tmeta i) -> J.object $ [ prop TermHash J..= th , prop TermModName J..= tmod , prop TermName J..= tn , prop TermMeta J..= tmeta , prop TermType J..= tty - , inf i - ] - (TDynamic r m i) -> J.object + ] ++ inf i + (TDynamic r m i) -> J.object $ [ prop TermDynRef J..= r - , inf i , prop TermDynMem J..= m - ] + ] ++ inf i (TModRef mr _i) -> J.build mr where - inf i = "i" J..= i + inf (Info Nothing) = [] + inf i = [ "i" J..= i ] instance FromJSON n => FromJSON (Term n) where From d33030b2964b06650dfb6d45dc1eb1c64b9d57eb Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 21 Aug 2023 16:47:10 -0700 Subject: [PATCH 2/2] Update golden tests with the new hash expectations --- golden/accounts-module-crossChainSendCR/golden | 2 +- golden/accounts-module-crossChainSendCRBackCompat/golden | 2 +- golden/accounts-module-eventCR/golden | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/golden/accounts-module-crossChainSendCR/golden b/golden/accounts-module-crossChainSendCR/golden index 6e021abc8..9953ec6a2 100644 --- a/golden/accounts-module-crossChainSendCR/golden +++ b/golden/accounts-module-crossChainSendCR/golden @@ -1 +1 @@ -{"gas":0,"result":{"status":"success","data":{"a":{"int":3}}},"reqKey":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","logs":"1mwhFumbCoQ2VpOJqEVD0IgAAOmY2RhDuW1PiVD1pGk","events":[{"params":["1","xchain.p",[{"int":3}]],"name":"X_YIELD","module":{"namespace":null,"name":"pact"},"moduleHash":"AHE7loAN5c-ajfetxFoDkmVcixfwr0-tKfKh7mylSvo"}],"metaData":null,"continuation":{"executed":null,"pactId":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","stepHasRollback":false,"step":0,"yield":{"data":{"a":{"int":3}},"source":"","provenance":{"targetChainId":"1","moduleHash":"AHE7loAN5c-ajfetxFoDkmVcixfwr0-tKfKh7mylSvo"}},"continuation":{"args":[{"int":3}],"def":"xchain.p"},"stepCount":2},"txId":null} \ No newline at end of file +{"gas":0,"result":{"status":"success","data":{"a":{"int":3}}},"reqKey":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","logs":"zSoMddrOTQFY_PG-n2GNlpLn5MoIkVtQQGlN9qds4bM","events":[{"params":["1","xchain.p",[{"int":3}]],"name":"X_YIELD","module":{"namespace":null,"name":"pact"},"moduleHash":"AHE7loAN5c-ajfetxFoDkmVcixfwr0-tKfKh7mylSvo"}],"metaData":null,"continuation":{"executed":null,"pactId":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","stepHasRollback":false,"step":0,"yield":{"data":{"a":{"int":3}},"source":"","provenance":{"targetChainId":"1","moduleHash":"AHE7loAN5c-ajfetxFoDkmVcixfwr0-tKfKh7mylSvo"}},"continuation":{"args":[{"int":3}],"def":"xchain.p"},"stepCount":2},"txId":null} \ No newline at end of file diff --git a/golden/accounts-module-crossChainSendCRBackCompat/golden b/golden/accounts-module-crossChainSendCRBackCompat/golden index ad58847d5..9a7cc6da1 100644 --- a/golden/accounts-module-crossChainSendCRBackCompat/golden +++ b/golden/accounts-module-crossChainSendCRBackCompat/golden @@ -1 +1 @@ -{"gas":0,"result":{"status":"success","data":{"a":{"int":3}}},"reqKey":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","logs":"o4k6VwRSTWZnHAXGvzx-Q7yoUDRBtTYU9Uuv6W_6FmI","metaData":null,"continuation":{"executed":null,"pactId":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","stepHasRollback":false,"step":0,"yield":{"data":{"a":{"int":3}},"provenance":{"targetChainId":"1","moduleHash":"AHE7loAN5c-ajfetxFoDkmVcixfwr0-tKfKh7mylSvo"}},"continuation":{"args":[{"int":3}],"def":"xchain.p"},"stepCount":2},"txId":null} \ No newline at end of file +{"gas":0,"result":{"status":"success","data":{"a":{"int":3}}},"reqKey":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","logs":"iQA0Bk4mmrB64fFsTV97HRTr21Dqkg66O2GfGv6opqI","metaData":null,"continuation":{"executed":null,"pactId":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","stepHasRollback":false,"step":0,"yield":{"data":{"a":{"int":3}},"provenance":{"targetChainId":"1","moduleHash":"AHE7loAN5c-ajfetxFoDkmVcixfwr0-tKfKh7mylSvo"}},"continuation":{"args":[{"int":3}],"def":"xchain.p"},"stepCount":2},"txId":null} \ No newline at end of file diff --git a/golden/accounts-module-eventCR/golden b/golden/accounts-module-eventCR/golden index f96e7975c..eb1373b72 100644 --- a/golden/accounts-module-eventCR/golden +++ b/golden/accounts-module-eventCR/golden @@ -1 +1 @@ -{"gas":0,"result":{"status":"success","data":1},"reqKey":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","logs":"cqZ-6rAE2TTv8ZXj8EbwsR_eUOp_RquGGnt4nnc4ck4","events":[{"params":["Alice",10.1],"name":"CAP","module":{"namespace":null,"name":"events-test"},"moduleHash":"fBdyelQUFqIWDrvMFLe0_WJ6DpEpCsnAhBR2X7nd71U"}],"metaData":null,"continuation":null,"txId":null} \ No newline at end of file +{"gas":0,"result":{"status":"success","data":1},"reqKey":"DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g","logs":"Zd51RR1xifJHz6FDAfJA-I42f5gWoiVinU-VH_1A88M","events":[{"params":["Alice",10.1],"name":"CAP","module":{"namespace":null,"name":"events-test"},"moduleHash":"fBdyelQUFqIWDrvMFLe0_WJ6DpEpCsnAhBR2X7nd71U"}],"metaData":null,"continuation":null,"txId":null} \ No newline at end of file