Closed carlomigueldy closed 1 year ago
yoo @carlomigueldy, code looks solid to me, have u tried a beforeAll
instead of before
?
blz submit full SavePakistanSmock.ts
to give a proper-er advice
yoo @carlomigueldy, code looks solid to me, have u tried a
beforeAll
instead ofbefore
? blz submit fullSavePakistanSmock.ts
to give a proper-er advice
gm bro, unfortunately there is not beforeAll
available only before
and beforeEach
and so I tried beforeEach
and still throwing the same exception
Here be the entire test suite as you ask:
import { MockContract, MockContractFactory, smock } from "@defi-wonderland/smock";
import { SavePakistan, SavePakistan__factory } from "../typechain-types";
import chai, { expect } from "chai";
import { TokenVariant } from "../utils";
import { BigNumber } from "ethers";
chai.should();
chai.use(smock.matchers);
describe("Smock: SavePakistan", () => {
let savePakistanFactory: MockContractFactory<SavePakistan__factory>;
let savePakistan: MockContract<SavePakistan>;
before(async () => {
savePakistanFactory = await smock.mock<SavePakistan__factory>("SavePakistan");
savePakistan = await savePakistanFactory.deploy();
console.log("savePakistanMock.address", savePakistan.address, "...");
});
it("should be cool", async () => {
console.log("COOL");
});
// it("should make it", async () => {
// console.log("savePakistanMock.address", savePakistan.address, "...");
// savePakistan.mintByPayingEth
// .whenCalledWith(TokenVariant.HygieneKit, BigNumber.from("1"))
// .returns(undefined);
// });
// it("should mock the shit out of it", async () => {
// savePakistanMock.USDC_ADDR.returns("carlo");
// const usdcAddr = await savePakistanMock.USDC_ADDR();
// console.log("usdcAddr", usdcAddr);
// });
// it("should call getters", async () => {
// expect(await mock.count()).to.equal(1);
// });
// it("should call methods", async () => {
// await mock.add(10);
// expect(await mock.count()).to.equal(11);
// });
// it("should be able to override returns", async () => {
// mock.count.returns(123);
// expect(await mock.count()).to.equal(123);
// });
// it("should be able to override a function that reverts", async () => {
// mock.doRevert.returns(true);
// expect(await mock.doRevert()).to.equal(true);
// });
// it("should be able to check function calls", async () => {
// await mock.add(10);
// expect(mock.add).to.be.calledOnceWith(10);
// });
});
Copied and run, it works cool.
Because of our repo structure, I had to change the import to:
import { SavePakistan, SavePakistan__factory } from "../../typechained";
Idk if it had something to do...
Copied and run, it works cool.
Because of our repo structure, I had to change the import to:
import { SavePakistan, SavePakistan__factory } from "../../typechained";
Idk if it had something to do...
damn, can you share me your repo + dependencies? lol
Sure fren, i'd recommend it to bootstrap and boost-up any project: https://github.com/defi-wonderland/solidity-hardhat-boilerplate
Sure fren, i'd recommend it to bootstrap and boost-up any project: https://github.com/defi-wonderland/solidity-hardhat-boilerplate
The suggested template/boilerplate for Hardhat works very well!
So I feel safe to close this issue as this template works the best :+1:
I'm having this issue as well - @carlomigueldy did you ever figure out why the repo structure caused this error?
Edit: I joined the smock discord, and some others have seen this issue. They resolved it by upgrading hardhat to 2.12.0. That got me past this error.
Describe the bug
After mock contract deployment, it just throws the exception.
Reproduction steps
Cannot read properties of undefined (reading 'events')
Expected behavior A clear and concise description of what you expected to happen.
It should throw exception after mock contract deployment in
before
orbeforeEach
hooks The exception to throw:Cannot read properties of undefined (reading 'events')
Screenshots If applicable, add screenshots to help explain your problem.
System Specs:
Additional context Add any other context about the problem here.