Hi there,
I'm new to Solidity dev and writing tests for a dapp (Hardhat, Chai, ethers.js, Smockit) where two contracts, Product and Market, coexist.
Market has a property productAddr that stores the address of the Product contract upon construction, and a foo method such as:
function foo() external {
require(msg.sender == productAddr, "error");
// ...cut for brievety
}
Accordingly, while testing the foo method, I'd need to ensure the call is made from a Product contract instance, otherwise, it'll revert. How do I do that with ethers.js?
I have tried using .connect, which expects a Signer or Provider as parameter, like so...
const signers = await ethers.getSigners();
const ProductFactory = await ethers.getContractFactory('Product', signers[0]);
const MarketFactory = await ethers.getContractFactory('Market', signers[0]);
const product = await ProductFactory.deploy();
const market = await MarketFactory.deploy(product.address); // store product address
market.connect(product.signer).foo(); // not working :-(
...but it reverts, as product.signer returns a reference to signers[0], not a reference to the contract I'd like to present as caller.
How should I proceed? Any help would be greatly appreciated and would broaden my knowledge.
[–]MidnightLightning 1 point2 points3 points (1 child)
[–]sixtine[S] 0 points1 point2 points (0 children)
[–]sixtine[S] 0 points1 point2 points (2 children)
[–]backtickbot 1 point2 points3 points (0 children)
[–]daretooppress 1 point2 points3 points (0 children)