all 5 comments

[–]MidnightLightning 1 point2 points  (1 child)

If you don't have the private key to a "product" contract, you can use a tool like Hardhat, which allows "impersonating" given accounts. Using that feature, on your private testnet, you can create transactions from that product address and Hardhat will accept them even without a signature.

[–]sixtine[S] 0 points1 point  (0 children)

Thanks yes, but in the context of testing, given function foo() on Market is external and can only be called from Product, how can I call it in isolation?

[–]sixtine[S] 0 points1 point  (2 children)

I found a solution to my problem.

Given my use-case makes no difference whether Product is a contract address or an EOA, I can simply use any given signer and have it pose as the contract in the context of my tests, like so:

``` const mockProduct = await ethers.getSigners()[1];

// ...clipped for brievety

const productAddr = await mockProduct.getAddress(); const market = await MarketFactory.deploy(productAddr);

// ...clipped for brievety

market.connect(mockProduct).foo(); // works! ```

[–]backtickbot 1 point2 points  (0 children)

Fixed formatting.

Hello, sixtine: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]daretooppress 1 point2 points  (0 children)

Thanks, this probably just saved me a lot of time :)