# Error: Invalid JSON RPC response: "" with Jest and OpenZeppelin Test Environment

**URL:** https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373
**Category:** Support
**Created:** [July 22, 2020, 9:14pm UTC](https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373 "2020-07-22T21:14:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![naszam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/naszam/32/19397_2.png) [@naszam](https://forum.openzeppelin.com/u/naszam)
#### Post date: [July 22, 2020, 9:14pm UTC](https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373/1 "2020-07-22T21:14:18Z")

</div>

I’m testing the following erc20 token based on the OpenZeppelin ERC20 preset:

> <https://github.com/naszam/wfil/blob/master/contracts/WFIL.sol>

I’m using the OpenZeppelin Test Environment, Test Helpers and Jest as test runner, following the docs:  
[https://docs.openzeppelin.com/test-environment/0.1/](https://docs.openzeppelin.com/test-environment/0.1/)

I wrote some tests based on the erc20 preset tests:

> <https://github.com/naszam/wfil/blob/master/test/WFIL.test.js>

When I try to test the contract with the following command:

```auto
npm test

```

I get the following Error:

```auto
    Error: Error: socket hang up
    ...
    Invalid JSON RPC response: ""

```

When trying to comment the specific test, I get the same error with the following error and so on.  
I’ve tried also to remove describe and set a time out for jest:

```auto
jest.setTimeout(60 * 5 * 1000);

```

I get the same error.

I think it could be something related to a specific dependency, maybe inside the open zeppelin test environment?

Could you help me with that?

Thanks!  
**💻 Environment**

openzeppelin/test-environment = v0.1.4  
openzeppelin/test-helpers = v0.5.6  
jest = v26.1.0  
jest-matcher-utils = v26.1.0  
openzeppelin/contracts v3.1.0  
truffle = v5.1.35

**📝Details**

**🔢 Code to reproduce**

> **[naszam/wfil](https://github.com/naszam/wfil)**
>
> Wrapped Filecoin, Team WrapFS at HackFS @ETHGlobal - naszam/wfil

---

<div class="post-metadata">

### Author: ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)
#### Post date: [July 23, 2020, 4:53am UTC](https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373/2 "2020-07-23T04:53:56Z")

</div>

Hi @naszam,

I’m sorry that you are having this issue.

I had exactly the same experience using your repository with Jest with `Invalid JSON RPC response: ""`.

I didn’t see anything obvious with your tests (though I am not familiar with Jest).

I converted the tests to use Mocha as the test runner and didn’t have any issues.

I even ran in parallel.

```auto
$ npx mocha --exit --recursive --parallel

  WFIL
    ✓ the deployer is the owner
    ✓ owner has the default admin role (68ms)
    ✓ owner has the minter role (42ms)
    ✓ owner has the pauser role (43ms)
    ✓ minter and pauser role admin is the default admin
    minting
      ✓ owner can mint tokens (57ms)
      ✓ other accounts cannot mint tokens (93ms)
    pausing
      ✓ owner can pause (65ms)
      ✓ owner can unpause (105ms)
      ✓ cannot mint while paused (82ms)
      ✓ other accounts cannot pause (43ms)
    burning
      ✓ holders can burn their tokens (112ms)

  12 passing (3s)

```

Test converted to be used with mocha

```auto
// based on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/presets/ERC20PresetMinterPauser.test.js

// test/WFIL.test.js

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

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

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

const WFIL = contract.fromArtifact('WFIL');

let wfil;

describe('WFIL', function () {
const [owner, other] = accounts;

const name = 'Wrapped Filecoin';
const symbol = 'WFIL';

const amount = new BN('5000');

const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
const MINTER_ROLE = web3.utils.soliditySha3('MINTER_ROLE');
const PAUSER_ROLE = web3.utils.soliditySha3('PAUSER_ROLE');

  beforeEach(async function () {
    wfil = await WFIL.new({ from: owner })
  });

  it('the deployer is the owner', async function () {
    expect(await wfil.owner()).to.equal(owner);
  });

  it('owner has the default admin role', async function () {
    expect(await wfil.getRoleMemberCount(DEFAULT_ADMIN_ROLE)).to.be.bignumber.equal(new BN(1));
    expect(await wfil.getRoleMember(DEFAULT_ADMIN_ROLE, 0)).to.equal(owner);
  });

  it('owner has the minter role', async function () {
    expect(await wfil.getRoleMemberCount(MINTER_ROLE)).to.be.bignumber.equal(new BN(1));
    expect(await wfil.getRoleMember(MINTER_ROLE, 0)).to.equal(owner);
  });

  it('owner has the pauser role', async function () {
    expect(await wfil.getRoleMemberCount(PAUSER_ROLE)).to.be.bignumber.equal(new BN(1));
    expect(await wfil.getRoleMember(PAUSER_ROLE, 0)).to.equal(owner);
  });

  it('minter and pauser role admin is the default admin', async function () {
    expect(await wfil.getRoleAdmin(MINTER_ROLE)).to.equal(DEFAULT_ADMIN_ROLE);
    expect(await wfil.getRoleAdmin(PAUSER_ROLE)).to.equal(DEFAULT_ADMIN_ROLE);
  });

  describe('minting', function () {
    it('owner can mint tokens', async function () {
      const receipt = await wfil.mint(other, amount, { from: owner });
      expectEvent(receipt, 'Transfer', { from: ZERO_ADDRESS, to: other, value: amount });

      expect(await wfil.balanceOf(other)).to.be.bignumber.equal(amount);
    });

    it('other accounts cannot mint tokens', async function () {
      await expectRevert(wfil.mint(other, amount, { from: other }),'WFIL: must have minter role to mint');
    });
  });

  describe('pausing', function () {
      it('owner can pause', async function () {
        const receipt = await wfil.pause({ from: owner });
        expectEvent(receipt, 'Paused', { account: owner });

        expect(await wfil.paused()).to.equal(true);
      });

      it('owner can unpause', async function () {
        await wfil.pause({ from: owner });

        const receipt = await wfil.unpause({ from: owner });
        expectEvent(receipt, 'Unpaused', { account: owner });

        expect(await wfil.paused()).to.equal(false);
      });

      it('cannot mint while paused', async function () {
        await wfil.pause({ from: owner });

        await expectRevert(
          wfil.mint(other, amount, { from: owner }),
          'ERC20Pausable: token transfer while paused'
        );
      });

      it('other accounts cannot pause', async function () {
        await expectRevert(wfil.pause({ from: other }), 'WFIL: must have pauser role to pause');
      });
  });

    describe('burning', function () {
      it('holders can burn their tokens', async function () {
        await wfil.mint(other, amount, { from: owner });

        const receipt = await wfil.burn(amount.subn(1), { from: other });
        expectEvent(receipt, 'Transfer', { from: other, to: ZERO_ADDRESS, value: amount.subn(1) });

        expect(await wfil.balanceOf(other)).to.be.bignumber.equal(new BN(1));
      });
    });

});

```

I reproduced using a test cloned from OpenZeppelin Contracts and created an Issue: [https://github.com/OpenZeppelin/openzeppelin-test-environment/issues/130](https://github.com/OpenZeppelin/openzeppelin-test-environment/issues/130)

As a work around I suggest using Mocha as your test runner.

---

<div class="post-metadata">

### Author: ![naszam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/naszam/32/19397_2.png) [@naszam](https://forum.openzeppelin.com/u/naszam)
#### Post date: [July 23, 2020, 9:55am UTC](https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373/3 "2020-07-23T09:55:23Z")

</div>

I will migrate to mocha for now.

Anyway, I’m curious to see what is causing the issue.

Thanks!

---

<div class="post-metadata">

### Author: ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)
#### Post date: [July 24, 2020, 6:11am UTC](https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373/4 "2020-07-24T06:11:06Z")

</div>

Hi @naszam,

I tested using an integration test and `jest@24.9.0` works but `jest@25.0.0` fails

> <https://github.com/OpenZeppelin/openzeppelin-test-environment/issues/130#issuecomment-663362303>
>
> Using Jest as the test runner, test fails with Error: socket hang up
> Reported in the community forum: https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-when-testing-erc20-token-based-on-preset-with-jest-and-openzeppelin-test-environment/3373
> I can reproduce with...

As a work around you could try using `jest@24.9.0` otherwise use mocha.

---

<div class="post-metadata">

### Author: ![naszam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/naszam/32/19397_2.png) [@naszam](https://forum.openzeppelin.com/u/naszam)
#### Post date: [July 24, 2020, 11:46am UTC](https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373/5 "2020-07-24T11:46:05Z")

</div>

Oh! Ok. Thanks!

I’ll stick with mocha (in parallel) for now.

Thanks!

---

<div class="post-metadata">

### Author: ![PradhumnaPancholi](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/pradhumnapancholi/32/2809_2.png) [@PradhumnaPancholi](https://forum.openzeppelin.com/u/PradhumnaPancholi)
#### Post date: [March 14, 2022, 8:45pm UTC](https://forum.openzeppelin.com/t/error-invalid-json-rpc-response-with-jest-and-openzeppelin-test-environment/3373/6 "2022-03-14T20:45:09Z")

</div>

Got bumped into the same error. I am using Mocha though

```auto

  it("General user can not pause the contract", async function () {
    await expectRevert(
      contract.connect(addr1).pause(),
      "Ownable: caller is not the owner"
    );
    expect(await contract.paused()).to.equal(false);
  });

```

I don't see anything obvious here.
