0

I can't compile solidity code in my Jest files, but without Jest it works fine.

Here is a test file:

const fs = require("fs")
const solc = require("solc")

describe("test", () => {
  test("", () => {
    const input = {
      "test.sol": fs.readFileSync("test.sol", "utf8")
    }

    const output = solc.compile({ sources: input })

    const bin = "0x" + output.contracts["test.sol:Test"].bytecode
    const abi = output.contracts["test.sol:Test"].interface

    console.log({ bin })
    console.log({ abi })
  })
})

Here is an error: TypeError: soljson.cwrap is not a function

If removed from this code all Jest things (describe, test), it works fine.

  • have you tried to move the compile outside the describe and then use the test just to retrieve the value from the output field? – mirg Apr 13 '18 at 10:16
  • Yes. There is the same error. – user33994 Apr 13 '18 at 10:24
  • what about moving the compile inside another module e include it inside the tests with require/import – mirg Apr 13 '18 at 10:25
2

Per this comment on solc-js issue #31, you can append this stanza to package.json.

"jest": {
  "testEnvironment": "node"
}

(which I guess tells jest to run in node, which will bring in the things that solc needs).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy