@0x/dev-utils: Add total_accounts option to Web3Config.

This commit is contained in:
Lawrence Forman
2019-08-29 21:47:31 -04:00
committed by Lawrence Forman
parent af10f52acf
commit 2e357ffeab
2 changed files with 18 additions and 7 deletions

View File

@@ -13,6 +13,10 @@
{
"note": "Add `UNLIMITED_CONTRACT_SIZE` to `EnvVars`.",
"pr": 2075
},
{
"note": "Add `total_accounts` option to `Web3Config`.",
"pr": 2109
}
]
},

View File

@@ -13,6 +13,7 @@ import { constants } from './constants';
import { env, EnvVars } from './env';
export interface Web3Config {
total_accounts?: number; // default: 10
hasAddresses?: boolean; // default: true
shouldUseInProcessGanache?: boolean; // default: false
shouldThrowErrorsOnGanacheRPCResponse?: boolean; // default: true
@@ -25,16 +26,18 @@ export interface Web3Config {
export const web3Factory = {
getRpcProvider(config: Web3Config = {}): Web3ProviderEngine {
const provider = new Web3ProviderEngine();
const hasAddresses = config.hasAddresses === undefined || config.hasAddresses;
config.shouldUseFakeGasEstimate =
const shouldUseFakeGasEstimate =
config.shouldUseFakeGasEstimate === undefined || config.shouldUseFakeGasEstimate;
if (!hasAddresses) {
provider.addProvider(new EmptyWalletSubprovider());
}
if (config.shouldUseFakeGasEstimate) {
if (shouldUseFakeGasEstimate) {
provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_LIMIT));
}
const logger = {
log: (arg: any) => {
fs.appendFileSync('ganache.log', `${arg}\n`);
@@ -43,11 +46,9 @@ export const web3Factory = {
const shouldUseInProcessGanache = !!config.shouldUseInProcessGanache;
if (shouldUseInProcessGanache) {
if (config.rpcUrl !== undefined) {
throw new Error('Cannot use both GanacheSubrovider and RPCSubprovider');
throw new Error('Cannot use both GanacheSubprovider and RPCSubprovider');
}
const shouldThrowErrorsOnGanacheRPCResponse =
config.shouldThrowErrorsOnGanacheRPCResponse === undefined ||
config.shouldThrowErrorsOnGanacheRPCResponse;
if (config.ganacheDatabasePath !== undefined) {
const doesDatabaseAlreadyExist = fs.existsSync(config.ganacheDatabasePath);
if (!doesDatabaseAlreadyExist) {
@@ -55,8 +56,14 @@ export const web3Factory = {
fs.mkdirSync(config.ganacheDatabasePath);
}
}
const shouldThrowErrorsOnGanacheRPCResponse =
config.shouldThrowErrorsOnGanacheRPCResponse === undefined ||
config.shouldThrowErrorsOnGanacheRPCResponse;
provider.addProvider(
new GanacheSubprovider({
total_accounts: config.total_accounts,
vmErrorsOnRPCResponse: shouldThrowErrorsOnGanacheRPCResponse,
db_path: config.ganacheDatabasePath,
allowUnlimitedContractSize: config.shouldAllowUnlimitedContractSize,