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

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

Open
thomashoneyman opened this issue May 5, 2024 · 0 comments
Open

Comments

@thomashoneyman
Copy link
Contributor

thomashoneyman commented May 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant