defi-wonderland / smock

The Solidity mocking library
MIT License
319 stars 40 forks source link

Hardhat 2.11.0 vm.on listener not present #153

Closed derekbar90 closed 2 years ago

derekbar90 commented 2 years ago

Describe the bug

When uses smock.fake the following error is thrown when running test suites under hardhat 2.11.0


TypeError: vm.on is not a function
      at Function.fromEvent (node_modules/@defi-wonderland/smock/src/observable-vm.ts:42:8)
      at new ObservableVM (node_modules/@defi-wonderland/smock/src/observable-vm.ts:19:35)
      at new Sandbox (node_modules/@defi-wonderland/smock/src/sandbox.ts:36:15)
      at Function.create (node_modules/@defi-wonderland/smock/src/sandbox.ts:82:12)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:526:9)
      at processTimers (node:internal/timers:500:7)
      at init (node_modules/@defi-wonderland/smock/src/index.ts:27:13)
      at Object.fake (node_modules/@defi-wonderland/smock/src/index.ts:13:17)```

**Reproduction steps**

1. Use smock to fake a contract
2. Modify one response from a contract function 
3. Run test
4. See error

**Expected behavior**
vm.on or other methods of event listeners should allow users to use smock with the most recent versions of hardhat

**System Specs:**

- OS: Any
- Package Version (or commit hash): @defi-wonderland/smock@2.2.0
derekbar90 commented 2 years ago

Looks like this line is what provides the object which is missing an EventListener

https://github.com/defi-wonderland/smock/blob/91a7aadf0cfa14ba52edb98c15fa0d38562fef39/src/sandbox.ts#L82

derekbar90 commented 2 years ago

Upon further investigation it looks like the _vm object missing .on which would confirm that the event listener has moved. There is now an events property which holds the event listener. I'll provide an MR shortly to resolve this.

alcuadrado commented 2 years ago

Hey, sorry about this! We didn't realize that upgrading ethereumjs would break Smock. I promise we'll keep it in mind if we have to upgrade it in the future.