OpenZeppelin / openzeppelin-test-environment

[Not actively maintained] One-line setup for blazing-fast smart contracts tests
https://docs.openzeppelin.com/test-environment
MIT License
90 stars 39 forks source link

Support ganache option db: MemDOWN #145

Closed abcoathup closed 3 years ago

abcoathup commented 3 years ago

Ganache has the following option:

"db": Object - Specify an alternative database instance, for instance MemDOWN. From: https://github.com/trufflesuite/ganache-cli#options-1

Requested in the forum: https://forum.openzeppelin.com/t/test-environment-configuration-for-db-memdown/4736

can speed up the tests significantly by configuring Ganache to avoid disk I/O operations

frangio commented 3 years ago

It's possible to specify the Ganache configuration directly by including a node field in test-environment.config.js. See Configuration.

frangio commented 3 years ago

Actually, our node configuration isn't enough because the options are serialized when sent to the Ganache node, and an instance of memdown wouldn't be properly forwarded.

barakman commented 3 years ago

Simple fix:

In file ganache-server.ts:

  1. Add import { Config, getConfig } from './config';
  2. In function setupServer, change the type of input argument nodeOptions from NodeOptions to any
  3. Change const server = setupServer(options); to:
    const config: Config = getConfig();
    const server: Server = setupServer({...options, ...config.node});

In file ganache-server.ts, change this:

const gasPrice = typeof config.node.gasPrice === 'string' ? config.node.gasPrice : undefined;

const options: NodeOptions = {
  ...config.node,
  gasPrice,
  accounts: accountsConfig,
  coverage: config.coverage,
};

To this:

const options: NodeOptions = {
  accounts: accountsConfig,
  coverage: false,
};

Would be happy to submit a PR if you authorize me.

barakman commented 3 years ago

Solved on v0.1.7. Thank you @frangio !