Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardhat console may be disrupting mocked answers #149

Open
wei3erHase opened this issue Aug 19, 2022 · 0 comments
Open

Hardhat console may be disrupting mocked answers #149

wei3erHase opened this issue Aug 19, 2022 · 0 comments

Comments

@wei3erHase
Copy link
Member

//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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant