{"size": 1158, "ext": "js", "max_stars_repo_path": "hardhat-core/packages/hardhat-ganache/test/fixture-projects/hardhat-project-with-configs/scripts/custom-accounts-sample.js", "max_stars_repo_name": "contractshark/hhci", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hardhat-core/packages/hardhat-ganache/test/fixture-projects/hardhat-project-with-configs/scripts/custom-accounts-sample.js", "max_issues_repo_name": "contractshark/hhci", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hardhat-core/packages/hardhat-ganache/test/fixture-projects/hardhat-project-with-configs/scripts/custom-accounts-sample.js", "max_forks_repo_name": "contractshark/hhci", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.3181818182, "max_line_length": 80, "alphanum_fraction": 0.6735751295}
// We require the Hardhat Runtime Environment explicitly here. This is optional.
const env = require("hardhat");

async function main() {
  const customConfigs = require("../hardhat.config.ts").default;
  const customOptions = customConfigs.networks.ganache;

  const accounts = await env.network.provider.send("eth_accounts");

  // Test for existence
  if (!accounts) {
    throw new Error("Accounts not detected");
  }

  // Test for validity of all data

  // Test for: totalAccounts
  if (accounts.length !== customOptions.totalAccounts) {
    throw new Error("Invalid: total accounts");
  }

  // Test for: defaultBalanceEther
  for (let account of accounts) {
    let accParams = [account, "latest"];
    const balance = await env.network.provider.send(
      "eth_getBalance",
      accParams
    );
    const defaultBalanceWei = customOptions.defaultBalanceEther * 10 ** 18;
    const accBalanceWei = parseInt(balance, 16);

    if (accBalanceWei !== defaultBalanceWei) {
      throw new Error("Invalid: default balance");
    }
  }
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
