Open wei3erHase opened 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
console.log
test: should log the mocked address
when removing the
console.log
line in solidity, test work as expected