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

Testing tables cross-chains in repl #1179

Open
EnoF opened this issue Apr 3, 2023 · 0 comments
Open

Testing tables cross-chains in repl #1179

EnoF opened this issue Apr 3, 2023 · 0 comments

Comments

@EnoF
Copy link

EnoF commented Apr 3, 2023

In order to test contracts that do cross-chain transactions, it would be very helpful if the repl separates the data written to tables per chain-id in env-chain-data. This might also have additional consequences regarding the init of the modules per chain. However not sure if those use cases will happen any time soon.

One can still perform such tests now, but you'd have to incorporate the chain id as part of the id used to access the row.

The following test shows what I'd like to be able to test:

(module test GOVERNANCE
  (defcap GOVERNANCE() true)

  (defschema a-schema
    foo:string)
  (deftable a-table:{a-schema})

  (defun add(x:string y:string)
    (insert a-table x { 'foo: y }))

  (defun get(x:string)
    (with-read a-table x
      { 'foo := foo }
      { 'foo :  foo }))
)
(create-table test.a-table)

(env-chain-data { "chain-id": "1" })
(test.add "a" "b")
(expect "Expect a to be found" { "foo": "b" } (test.get "a"))

(env-chain-data { "chain-id": "2" })
(expect-failure "Expect a to not exist" "Cannot read row a" (test.get "a"))
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