defi-wonderland / smock

The Solidity mocking library
MIT License
321 stars 39 forks source link

Hardhat console may be disrupting mocked answers #149

Open wei3erHase opened 1 year ago

wei3erHase commented 1 year ago
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "hardhat/console.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract Example is Ownable {

    address private _someAddress;

    constructor(address someAddress) {
        _someAddress = someAddress;
    }

    function getAddress() public view returns (address _theAddress) {
        console.log(_someAddress);
        return _someAddress;
    }

}

test: should log the mocked address

import { ethers } from "hardhat";
import { smock } from "@defi-wonderland/smock";

describe.only("Example", function () {
    it('should test if getAddress can be mocked', async () => {
        const [owner, addr1] = await ethers.getSigners();

        const exampleFactory = await smock.mock('Example');
        console.log(exampleFactory);
        const example = await exampleFactory.deploy(owner.address);

        await example.getAddress.returns(addr1.address);

        const address = await example.getAddress();

        console.log(address);
        console.log(addr1.address);
        console.log(owner.address);
    });
});

when removing the console.log line in solidity, test work as expected