0

I think @nomiclabs/hardhat-ethers fails to manage Enum type of output of a contract when testing it locally.

solidity version 0.8.7
hardhat version 2.6.4

Contract.sol

contract Contract {
    enum E {
        A,
        B
    }

    E internal _state;

    constructor () {
        _state = E.A;
    }

    function getState() external view returns (E) {
        return _state;
    }
}

Contract.test.js

describe("...", function() {

  const A = 0;
  const B = 1;
  // deploy Contract.sol

  it("Should return correct state", async function() {
    console.log(JSON.stringify(await contract.getState())); // wired output here
    expect(await contract.getState()).to.equals(A); // assertion fails
  });
});

output:

{
  "hash": "0xb79774c7f62021a2c5111248739d4112b056f13dfb50df2a6d64bd520eeb2154",
  "type": 2,
  "accessList": [],
  "blockHash": "0x8dfaed4f9a749de3f63b8372a4c19e0f647e375ae55ff37d9b461a7e8d12a01e",
  "blockNumber": 4,
  "transactionIndex": 0,
  "confirmations": 1,
  "from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
  "gasPrice": {
    "type": "BigNumber",
    "hex": "0x5fb1bf53"
  },
  "maxPriorityFeePerGas": {
    "type": "BigNumber",
    "hex": "0x3b9aca00"
  },
  "maxFeePerGas": {
    "type": "BigNumber",
    "hex": "0x83c8b4a6"
  },
  "gasLimit": {
    "type": "BigNumber",
    "hex": "0x01bad458"
  },
  "to": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
  "value": {
    "type": "BigNumber",
    "hex": "0x00"
  },
  "nonce": 3,
  "data": "0xfcaa7664",
  "r": "0xe945c6b8f0a1074a39bcb74616496e59bd249a2ae850dbad8ec11c629e9fd764",
  "s": "0x72cf22e0f2984b6070dd3a66b7e0fda85b7ba214978658eae270d6477fc09888",
  "v": 1,
  "creates": null,
  "chainId": 31337
}

Your Answer

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

Browse other questions tagged or ask your own question.