@defi.org/ethereumjs-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

ethereumjs-hooks

Test utilities that hook into ethereumjs evm.

For testing purposes only, use at your own risk

Installation

in package.json:

"devDependencies": {
  "@defi.org/ethereumjs-hooks": "latest"
}
...
"scripts": {
  "postinstall": "ethereumjs-hooks"
}

evmJumpBlocks(number, fn)

Modifies EVM opcode 0x43 (block.number) to return block.number + n. Does not affect web3, only solidity/evm runtime.

Effect remains globally until evmJumpBlocks(0) is called.

Useful for testing contract states that depend on blocknumber far in the future (for example Compound.finance).

Usage example:

import { evmJumpBlocks } from "@defi.org/ethereumjs-hooks";

afterEach(() => evmJumpBlocks(0));

it(async () => {
  const currentBlockNumber = await someContract.methods.getBlockNumber().call(); // solidity 'block.number'

  evmJumpBlocks(100_000);

  await someContract.methods.getBlockNumber().call(); // currentBlockNumber + 100,000
});

Readme

Keywords

none

Package Sidebar

Install

npm i @defi.org/ethereumjs-hooks

Weekly Downloads

0

Version

0.1.6

License

MIT

Unpacked Size

4.49 kB

Total Files

7

Last publish

Collaborators

  • idana
  • doronaviguy
  • amihaz
  • uvorbs
  • talkol
  • zlotindaniel
  • rotemy
  • ronno