kadena-io / pact

The Pact Smart Contract Language
https://pact-language.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
580 stars 100 forks source link

FV: Unable to use (contains) in schema invariant due to parse error #1360

Open thomashoneyman opened 3 months ago

thomashoneyman commented 3 months ago

Issue description

I am unable to write an invariant in a defschema using the (contains) function as described in the documentation:

https://docs.kadena.io/pact/reference/properties-and-invariants/list-operators#containsh-567445985

Steps to reproduce

The below REPL file:

(module test GOV
  (defcap GOV () true)

  (defconst WAT "WAT")
  (defconst WOT "WOT")

  (defschema wat
    @model [ (invariant (contains target [WOT WAT])) ]
    target:string)

  (deftable wat-table:{wat})

  (defun add-target (target:string)
    (insert wat-table "wat" { "target": target }))
)

(verify "test")

produces the following output:

➜ pact wat.repl
:OutputFailure: pact/wat.repl:8:24: could not parse (contains target [WOT WAT]): in [WOT,WAT], type error: string vs [string] (CallStack (from HasCallStack):   typeError, called at src-tool/Pact/Analyze/Parse/Prop.hs:762:22 in pact-4.11-inplace:Pact.Analyze.Parse.Prop)
Load successful

Expected Behavior

Replacing the (contains) with multiple equality checks works as expected, catching the error in (add-target):

(module test GOV
  (defcap GOV () true)

  (defconst WAT "WAT")
  (defconst WOT "WOT")

  (defschema wat
    @model [ (invariant (or (= target WOT) (= target WAT))) ]
    target:string)

  (deftable wat-table:{wat})

  (defun add-target (target:string)
    (insert wat-table "wat" { "target": target }))
)

(verify "test")

This produces the expected output:

wat.repl:8:24:OutputFailure: Invalidating model found in test.add-target
  Program trace:
    entering function test.add-target with argument
      target = ""

      insert into wat-table at key "wat" with { target: "" } succeeds
      returning with "Write succeeded"

Debug Information

This is using Pact 4.11.