OpenZeppelin / openzeppelin-test-helpers

Assertion library for Ethereum smart contract testing

Home Page:https://docs.openzeppelin.com/test-helpers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Returned error: Returned error: invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash

aress31 opened this issue · comments

I am working on unit tests and the following one is failing:

  it("assigns the initial total supply to the owner", async () => {
    const [owner] = accounts;
    const totalSupply = await this.token.totalSupply();
    const ownerBalance = await this.token.balanceOf(owner);

    expect(ownerBalance).to.be.bignumber.equal(totalSupply);

    await expectEvent.inConstruction(this.token, "Transfer", {
      from: ZERO_ADDRESS,
      to: owner,
      value: totalSupply,
    });
  });

Here is the associated stack trace:

 1) Contract: Initial State
       assigns the initial total supply to the owner:
     Error: Returned error: Returned error: invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash
      at Object.ErrorResponse (node_modules\web3-core-helpers\lib\errors.js:28:19)
      at C:\Users\ateyar\Documents\GitHub\erc20-deflationary\node_modules\web3-core-requestmanager\lib\index.js:303:36
      at C:\Users\ateyar\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:107:1
      at XMLHttpRequest.request.onreadystatechange (C:\Users\ateyar\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3\node_modules\web3-providers-http\lib\index.js:98:1)
      at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\ateyar\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (C:\Users\ateyar\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:208:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (C:\Users\ateyar\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:318:1)
      at IncomingMessage.<anonymous> (C:\Users\ateyar\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:289:47)
      at endReadableNT (internal/streams/readable.js:1327:12)
      at processTicksAndRejections (internal/process/task_queues.js:80:21)

Anyone who can please make sense of this issue?

Please share details about your environment. In particular, what node are you running against?

I hope this helps:

npx truffle version                  
Truffle v5.3.2 (core: 5.3.2)
Solidity - 0.8.4 (solc-js)
Node v14.16.0
Web3.js v1.3.5

How are you running your tests, is it just truffle test? What network are you running against? This is a weird error that I haven't seen before so as much data as you can provide to reproduce it, would help.

Yeah, just using npx truffle test --network development and in local I run npx ganache-cli --fork https://ropsten.infura.io/v3/10cc02d0eec842c99af1653c011badc9.

This is my constructor:

    constructor(
        string memory name_,
        string memory symbol_,
        uint8 decimals_,
        uint256 totalSupply_,
        address router_,
        --- SNIP ---
    ) ERC20(name_, symbol_) {
        _decimals = decimals_;
        _totalSupply = totalSupply_ * (10**decimals_);

        --- SNIP ---

        //  Set DEX platform up
        _uniswapV2Router = IUniswapV2Router02(address(router_));

        address pair =
            IUniswapV2Factory(_uniswapV2Router.factory()).getPair(
                _uniswapV2Router.WETH(),
                address(this)
            );

        // Pair not yet created
        if (pair == address(0)) {
            _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
                .createPair(_uniswapV2Router.WETH(), address(this));
        } else {
            _uniswapV2Pair = pair;
        }

        --- SNIP ---

        emit Transfer(address(0), _msgSender(), _totalSupply);
    }