1

Currently, we use "live" versions of our contracts running on a substrate contracts node in our JavaScript tests. This makes them integration tests and difficult to include in simple GitHub actions. It would be ideal if we could somehow run the contract as a mock inside our JS environment. Is it possible to run the contract wasm from within our JS/TS environment as a mock contract? Does anyone have any experience of this?

3
  • "run a contract as a mock" doesn't look like a well defined term to me. Can you please elaborate what you mean? I posted an answer on how you could run some integration tests. Commented May 11, 2022 at 18:03
  • I mean have a mocked/fake contract in JavaScript without running any code in rust. Essentially having a mirror of the contract but in JavaScript/TypeScript. I realise that the wasm probably can't be repurposed for this but you never know. I see there are contract tests in polkadot-js but I'm not sure how they function.
    – forgetso
    Commented May 11, 2022 at 20:22
  • You want to rewrite the contract in javascript? Commented May 11, 2022 at 22:21

2 Answers 2

1

In order to do an integration test you would need to spawn a substrate-contracts-node and then use the polkadot.js javscript library in order to interact with it. Another way would be to use the cargo-contract command line tool in order to interact with the node. That way you could even script it with some shell script.

0

We use Github Actions, Cypress, and a contracts-node binary to run E2E tests for Contracts UI. Here is our CI workflow, hope it helps.

We use cypress-file-upload to attach the .contract file to the tests.

A solution without Cypress is to rename it to .json and import it into your tests. Most JavaScript bundlers can be configured to support JSON modules and the .contract file is valid JSON

import incrementer from './contracts/incrementer.json'; 
const wasm = incrementer.source.wasm;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.