pact
pact copied to clipboard
Testing tables cross-chains in repl
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"))