ethers-jest-environment
v0.0.3
Published
Ethers JS and Ganache ready to use with Jest
Downloads
2
Maintainers
Readme
ethers-jest-environment ·
Jest environment with Ganache instance and EthersJS ready.
Install
Install dependencies.
yarn add ethers-jest-environment --dev
Add to your Jest config.
{
"testEnvironment": "ethereum",
"testEnvironmentOptions": {
"port": "8545",
"mnemonic": ""
...moreOptions // view options section
}
}
Options
You can specify options for the ganache instance by following the interface:
export interface IProviderOptions {
account_keys_path?: string;
accounts?: object[];
allowUnlimitedContractSize?: boolean;
blockTime?: number;
db_path?: string;
debug?: boolean;
default_balance_ether?: number;
fork?: string | object;
fork_block_number?: string | number;
forkCacheSize?: number;
gasLimit?: string | number;
gasPrice?: string;
hardfork?: "byzantium" | "constantinople" | "petersburg" | "istanbul" | "muirGlacier";
hd_path?: string;
locked?: boolean;
logger?: {
log(msg: string): void;
};
mnemonic?: string;
network_id?: number;
networkId?: number;
port?: number;
seed?: any;
time?: Date;
total_accounts?: number;
unlocked_accounts?: string[];
verbose?: boolean;
vmErrorsOnRPCResponse?: boolean;
ws?: boolean;
}
Usage
Use Ethereum blockchain with the injected EthersJS provider in your tests:
test('accounts', async () => {
const unlockedAccounts = ethersProvider.getAccounts();
expect(unlockedAccounts.length).toBe(10);
});