defi-wonderland / smock

The Solidity mocking library
MIT License
321 stars 39 forks source link

When a fake returns a function, we cannot have async data #197

Open jptusername opened 3 months ago

jptusername commented 3 months ago

Describe the bug Returning from a fake function reverts with Error: Transaction reverted: function returned an unexpected amount of data.

If the sendTransaction is left out, it works as expected

Reproduction steps

// test  for userWithdraw method
await fakeStrategy.withdraw.returns(async() => {
                await owner.sendTransaction({
                     to: yieldFarm.address,
                     value: TEN_ETH,
                 });
                return TEN_ETH;
            })

// contract
contract YieldFarm{
  function userWithdraw() {
    /// ... custom logic
    amountReceived = strategy.withdraw(); // this function moves funds from strategy to yieldFarm, ETH in this case
  }
}

Expected behavior TEN_ETH value should be transferred to the yieldFarm contract. and this function withdraw should return the value TEN_ETH as well