Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

IProviderOptions['accounts'] should have a narrower type. #645

Closed
geoknee opened this issue Oct 6, 2020 · 2 comments
Closed

IProviderOptions['accounts'] should have a narrower type. #645

geoknee opened this issue Oct 6, 2020 · 2 comments
Milestone

Comments

@geoknee
Copy link

geoknee commented Oct 6, 2020

IProviderOptions['accounts'] should have a narrower type.

Expected Behavior

Passing in the wrong type of object to ganache.server() should raise a Typescript error, for example using an ethers BigNumber:

import {ethers} from 'ethers';
import ganache from 'ganache-core';

const serverOptions: ganache.IServerOptions = {
  accounts: [{balance: ethers.utils.parseEther('1000000'), secretKey: 'secret'}]
};

If warned that balance should be a string, I can easily use .toHexString() to fix the problem.

Current Behavior

No typescript error for the above example, but instead a runtime error:

(node:210) UnhandledPromiseRejectionWarning: Error: bigNumber.toString does not accept parameters (code=UNEXPECTED_ARGUMENT, version=bignumber/5.0.6)
    at Logger.makeError (/home/circleci/project/node_modules/@ethersproject/logger/src.ts/index.ts:205:28)
    at Logger.throwError (/home/circleci/project/node_modules/@ethersproject/logger/src.ts/index.ts:217:20)
    at BigNumber.toString (/home/circleci/project/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:192:20)
    at Object.hex (/home/circleci/project/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:66868)
    at S.createAccount (/home/circleci/project/node_modules/ganache-cli/build/ganache-core.node.cli.js:48:177548)
    at Array.map (<anonymous>)
    at S.initialize (/home/circleci/project/node_modules/ganache-cli/build/ganache-core.node.cli.js:48:175451)
    at new p (/home/circleci/project/node_modules/ganache-cli/build/ganache-core.node.cli.js:48:163787)
    at new l (/home/circleci/project/node_modules/ganache-cli/build/ganache-core.node.cli.js:19:90308)
    at Object.create (/home/circleci/project/node_modules/ganache-cli/build/ganache-core.node.cli.js:96:91251)
    at Object.server (/home/circleci/project/node_modules/ganache-cli/build/ganache-core.node.cli.js:48:7388)
    at new GanacheServer (/home/circleci/project/packages/devtools/src/ganache/server.ts:31:27)
    at /home/circleci/project/packages/devtools/src/ganache/index.ts:47:18
    at Generator.next (<anonymous>)
    at /home/circleci/project/packages/devtools/lib/src/ganache/index.js:8:71
    at new Promise (<anonymous>)

Possible Solution

https://github.com/trufflesuite/ganache-core/blob/53f653ea4356fa558ecb0c2d6338278d8d7285cc/typings/index.d.ts#L20

Should be instead
accounts?: { balance: string; secretKey: string }[];

Steps to Reproduce (for bugs)

Install ganache-core@2.12.1 and ethers@5.0.12. Call ganache.server(opts) with opts specified as above. Observe no TS error but a runtime error.

Context

Using ganache-core in our project alongside ethers.BigNumber (which we had previously had working with ganache-cli.

statechannels/statechannels#2648

Your Environment

@gnidan gnidan added this to the 7.0.0 milestone Mar 31, 2021
@gnidan
Copy link
Contributor

gnidan commented Mar 31, 2021

Thanks for raising this!

This is fixed in our upcoming Ganache v7.0.0 release. (There you will find type narrowness in excess, I bet!)

@davidmurdoch
Copy link
Member

Closing this one to track the broader issue in #1412

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants