OpenZeppelin Test Environment: Scrypt not found

Whn running tests I get the following error:

This relative module was not found:

* ./build/Release/scrypt in ./node_modules/scrypt/index.js
  [=========================] 100% (completed)

 WEBPACK  Failed to compile with 1 error(s)

Error in ./node_modules/scrypt/index.js

  Module not found: './build/Release/scrypt' in '.../node_modules/scrypt'

 ERROR  mochapack exited with code 1.

Scrypt is installed and built with node-gyp.
Using Node version 10.16.3

my deps (oddly enough when running tests I was required to install electron):

  "dependencies": {
    "@openzeppelin/cli": "^2.8.2",
    "@openzeppelin/contracts": "^3.0.1",
    "@openzeppelin/gsn-helpers": "^0.2.3",
    "@openzeppelin/gsn-provider": "^0.1.10",
    "babel": "^6.23.0",
    "core-js": "^3.6.4",
    "electron": "^9.0.5",
    "scrypt": "^6.0.3",
    "vue": "^2.6.11",
    "vue-router": "^3.3.4",
    "vuex": "^3.4.0",
    "web3": "1.2.7"
  },
  "devDependencies": {
    "@openzeppelin/test-environment": "^0.1.4",
    "@openzeppelin/test-helpers": "^0.5.6",
    "@vue/cli-plugin-babel": "^4.3.0",
    "@vue/cli-plugin-eslint": "^4.3.0",
    "@vue/cli-plugin-unit-mocha": "^4.3.1",
    "@vue/cli-service": "^4.3.0",
    "@vue/test-utils": "1.0.0-beta.31",
    "babel-eslint": "^10.1.0",
    "chai": "^4.1.2",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "mocha": "^7.1.2",
    "vue-template-compiler": "^2.6.11"
  },
1 Like

Hi @Steeve,

I tried some simple tests using OpenZeppelin Test Environment and your dependencies and wasn’t able to reproduce the error.

I don’t know why you needed electron.

Are you able to share a test that creates the error?

Here is my test file, very simple:
Update: it seems the scrypt issue was discussed in ganache-cli issue #134… I tried that fix but got a missing node loader error.

const { accounts, contract } = require('@openzeppelin/test-environment');
const [ owner ] = accounts;

const { expect } = require('chai');

const MyContract = contract.fromArtifact('SimpleStorage'); // Loads a compiled contract

describe('MyContract' , async function () {
  it('deployer is owner', async function () {
    const myContract = await MyContract.new({ from: owner });
    await MyContract.set([6]);
    expect(await myContract.get()).to.equal(6);
  });
});

1 Like

electron appears to be part of test-helpers suite:

This dependency was not found:

* electron in ./node_modules/@openzeppelin/test-helpers/node_modules/swarm-js/node_modules/got/index.js, ./node_modules/swarm-js/node_modules/got/index.js

To install it, you can run: npm install --save electron

opening file zeppelin/test-helpers/node_modules/swarm-js/node_modules/got/index.js
lines 44-45 we see the electron requirement:

                if (opts.useElectronNet && process.versions.electron) {
                        const electron = require('electron');
                        fn = electron.net || electron.remote.net;
                }
1 Like

Hi @Steeve,

Unfortunately I can’t reproduce the error that you are getting, see the contract, test and package.json I have below.

I am running on WSL2
node v10.21.0
npm 6.14.5

What operating system and npm versions are you using?

SimpleStorage.sol

// SPDX-License-Identifier: GPL-3.0
// from: https://solidity.readthedocs.io/en/v0.6.10/introduction-to-smart-contracts.html#storage-example
pragma solidity >=0.4.16 <0.7.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

SimpleStorage.test.js

Minor modifications on your test

const { accounts, contract } = require('@openzeppelin/test-environment');
const [ owner ] = accounts;

const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');

const { expect } = require('chai');

const MyContract = contract.fromArtifact('SimpleStorage'); // Loads a compiled contract

describe('Simple Storage' , async function () {
  it('can get set value', async function () {
    const myContract = await MyContract.new({ from: owner });
    await myContract.set([6]);
    expect(await myContract.get()).to.be.bignumber.equal(new BN('6'));
  });
});

Run Test

$ npm run test

> steeve@1.0.0 test /home/abcoathup/projects/steeve
> mocha --exit --recursive test



  Simple Storage
    βœ“ can get set value (766ms)


  1 passing (779ms)

package.json

{
  "name": "steeve",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha --exit --recursive test"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@openzeppelin/cli": "^2.8.2",
    "@openzeppelin/contracts": "^3.1.0",
    "@openzeppelin/test-environment": "^0.1.4",
    "@openzeppelin/test-helpers": "^0.5.6",
    "chai": "^4.2.0",
    "mocha": "^8.0.1"
  }
}

I don’t have electron in my dependencies

$ npm ls electron
steeve@1.0.0 /home/abcoathup/projects/steeve
└── (empty)

Hi,

Im running Ubuntu 16.04 with node 10.16.3 and yarn 1.13.0

I use web3 and oz-gsn in my dependencies. web3 references swarm (thus electron)…
Could you run npm list swarm-js and see the result? my here shows swarm-js is used throughout every web3 related dep:

+-- @openzeppelin/cli@2.8.2
| +-- truffle-config@1.1.16
| | `-- truffle-provider@0.1.16
| |   +-- truffle-interface-adapter@0.2.5
| |   | `-- web3@1.2.1
| |   |   `-- web3-bzz@1.2.1
| |   |     `-- swarm-js@0.1.39  deduped
| |   `-- web3@1.2.1
| |     `-- web3-bzz@1.2.1
| |       `-- swarm-js@0.1.39  deduped
| `-- typechain-target-web3-v1@1.0.4
|   `-- web3@1.2.9
|     `-- web3-bzz@1.2.9
|       `-- swarm-js@0.1.40 
+-- @openzeppelin/gsn-helpers@0.2.3
| `-- web3@1.2.9
|   `-- web3-bzz@1.2.9
|     `-- swarm-js@0.1.40 
+-- @openzeppelin/gsn-provider@0.1.10
| `-- web3@1.2.9
|   `-- web3-bzz@1.2.9
|     `-- swarm-js@0.1.40 
+-- @openzeppelin/test-environment@0.1.4
| +-- @truffle/contract@4.2.10
| | +-- @truffle/interface-adapter@0.4.9
| | | `-- web3@1.2.1
| | |   `-- web3-bzz@1.2.1
| | |     `-- swarm-js@0.1.39  deduped
| | +-- ethereum-ens@0.8.0
| | | `-- web3@1.2.9
| | |   `-- web3-bzz@1.2.9
| | |     `-- swarm-js@0.1.40 
| | `-- web3@1.2.1
| |   `-- web3-bzz@1.2.1
| |     `-- swarm-js@0.1.39  deduped
| `-- ganache-core@2.10.2
|   `-- web3@1.2.4
|     `-- web3-bzz@1.2.4
|       `-- swarm-js@0.1.39  deduped
+-- @openzeppelin/test-helpers@0.5.6
| +-- @truffle/contract@4.2.1
| | `-- web3@1.2.1
| |   `-- web3-bzz@1.2.1
| |     `-- swarm-js@0.1.39  deduped
| `-- web3@1.2.9
|   `-- web3-bzz@1.2.9
|     `-- swarm-js@0.1.40 
`-- web3@1.2.2
  `-- web3-bzz@1.2.2
    `-- swarm-js@0.1.39 

I need to greatly simplify the web3 deps

1 Like
$ npm list swarm-js
steeve@1.0.0 /home/abcoathup/projects/steeve
β”œβ”€β”¬ @openzeppelin/cli@2.8.2
β”‚ β”œβ”€β”¬ truffle-config@1.1.16
β”‚ β”‚ └─┬ truffle-provider@0.1.16
β”‚ β”‚   β”œβ”€β”¬ truffle-interface-adapter@0.2.5
β”‚ β”‚   β”‚ └─┬ web3@1.2.1
β”‚ β”‚   β”‚   └─┬ web3-bzz@1.2.1
β”‚ β”‚   β”‚     └── swarm-js@0.1.39  deduped
β”‚ β”‚   └─┬ web3@1.2.1
β”‚ β”‚     └─┬ web3-bzz@1.2.1
β”‚ β”‚       └── swarm-js@0.1.39  deduped
β”‚ β”œβ”€β”¬ typechain-target-web3-v1@1.0.4
β”‚ β”‚ └─┬ web3@1.2.9
β”‚ β”‚   └─┬ web3-bzz@1.2.9
β”‚ β”‚     └── swarm-js@0.1.40
β”‚ └─┬ web3@1.2.2
β”‚   └─┬ web3-bzz@1.2.2
β”‚     └── swarm-js@0.1.39
β”œβ”€β”¬ @openzeppelin/test-environment@0.1.4
β”‚ β”œβ”€β”¬ @truffle/contract@4.2.10
β”‚ β”‚ β”œβ”€β”¬ @truffle/interface-adapter@0.4.9
β”‚ β”‚ β”‚ └─┬ web3@1.2.1
β”‚ β”‚ β”‚   └─┬ web3-bzz@1.2.1
β”‚ β”‚ β”‚     └── swarm-js@0.1.39  deduped
β”‚ β”‚ └─┬ web3@1.2.1
β”‚ β”‚   └─┬ web3-bzz@1.2.1
β”‚ β”‚     └── swarm-js@0.1.39  deduped
β”‚ └─┬ ganache-core@2.10.2
β”‚   └─┬ web3@1.2.4
β”‚     └─┬ web3-bzz@1.2.4
β”‚       └── swarm-js@0.1.39
└─┬ @openzeppelin/test-helpers@0.5.6
  └─┬ @truffle/contract@4.2.1
    └─┬ web3@1.2.1
      └─┬ web3-bzz@1.2.1
        └── swarm-js@0.1.39  deduped

I assume that something else is causing the Scrypt not found.

Ok, thanks,
On further checking it appears the issue is related on the webpack configuration and web3 issue #1105.

So I must edit some my webpack config in the UI framework to exclude the node module directory or specific files from the compilation build.

As for scrypt, a manual edit and adding node-loader to my webpack build may resolve this once I get screen time to work on this.

EDIT: the solution was in my package.json scripts
I was using "test:unit": "vue-cli-service test:unit", intended for my UI
I added the mocha test script: "test": "mocha --exit --recursive test",
works as expected.

1 Like

Hi @Steeve,

It sounds like you have tracked it down. Good to hear.