function test() internal {
  stateVariable = 20;
  uint num = 20;
  assembly {
     mstore(0x00, num)
     return(0x00, 0x20)

How do I test the return ? I am using hardhat , but i don't think it changes anything.

Step 1: I should create another contract contractB which is a mock and which is the child of the contractA. This way, I can make this contractB's function public and it will include the internal function - test.

After this, I'd appreciate if I could hear your opinions what could be the best way to make sure to test this.

  • That's the only way to test internal function that I'm aware of.
    – Ismael
    Feb 26 at 3:56
  • yes, but how do I test contractB's public function ? when calling a transaction from javascript, it doesn't return the value.. Feb 26 at 9:27
  • You could make B's functions that calls test generate an event with the returned value. The tricky part is that return ends the whole call that invokes test so you need some kind of indirection like using .call or .delegatecall to invoke test.
    – Ismael
    Feb 26 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.