How to use ganache-core - 10 common examples

To help you get started, we’ve selected a few ganache-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brave / ethereum-remote-client / test / helper.js View on Github external
const Ganache = require('ganache-core')
const nock = require('nock')
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-15'

nock.disableNetConnect()
nock.enableNetConnect('localhost')

Enzyme.configure({ adapter: new Adapter() })
// disallow promises from swallowing errors
enableFailureOnUnhandledPromiseRejection()

// ganache server
const server = Ganache.server()
server.listen(8545, () => {
  console.log('Ganache Testrpc is running on "http://localhost:8545"')
})

// logging util
const log = require('loglevel')
log.setDefaultLevel(5)
global.log = log

//
// polyfills
//

// fetch
global.fetch = require('isomorphic-fetch')
require('abortcontroller-polyfill/dist/polyfill-patch-fetch')
github embark-framework / subspace / test / test6.js View on Github external
const Web3Eth = require('web3-eth');
const {deployRatingContract, mine} = require('./utils-web3');
const Subspace = require('../dist/node.js');
const ganache = require("ganache-core");

console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
let eth = new Web3Eth(ganache.provider());

async function run() {
  let accounts = await eth.getAccounts();
  var RatingContract = await deployRatingContract(eth)

  // Events are generated in these blocks:
  //             x           x   x   x   x         x              x    x                       x
  // 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
  await mine(eth);
  await RatingContract.methods.doRating(1, 5).send({from: accounts[0]})
  await mine(eth);
  await mine(eth);
  await RatingContract.methods.doRating(2, 3).send({from: accounts[0]})
  await RatingContract.methods.doRating(3, 1).send({from: accounts[0]})
  await RatingContract.methods.doRating(4, 5).send({from: accounts[0]})
  await RatingContract.methods.doRating(5, 5).send({from: accounts[0]})
github o2oprotocol / digital-identity / test / _helper.js View on Github external
async function server(web3, provider) {
  try {
    // Hack to prevent "connection not open on send" error when using websockets
    web3.setProvider(provider.replace(/^ws/, 'http'))
    await web3.eth.net.getId()
    web3.setProvider(provider)
    return
  } catch (e) {
    /* Ignore */
  }

  var port = '7545'
  if (String(provider).match(/:([0-9]+)$/)) {
    port = provider.match(/:([0-9]+)$/)[1]
  }
  var server = Ganache.server()
  await server.listen(port)
  return server
}
github OriginProtocol / origin / origin-contracts / test-alt / _helper.js View on Github external
async function server(web3, provider) {
  try {
    // Hack to prevent "connection not open on send" error when using websockets
    web3.setProvider(provider.replace(/^ws/, 'http'))
    await web3.eth.net.getId()
    web3.setProvider(provider)
    return
  } catch (e) {
    /* Ignore */
  }

  let port = '7545'
  if (String(provider).match(/:([0-9]+)$/)) {
    port = provider.match(/:([0-9]+)$/)[1]
  }
  const server = Ganache.server()
  await server.listen(port)
  return server
}
github MetaMask / eth-json-rpc-middleware / test / block-ref.js View on Github external
function createTestSetup () {
  // raw data source
  const dataProvider = GanacheCore.provider()
  // create block tracker
  const blockTracker = new BlockTracker({
    provider: dataProvider,
    pollingInterval: 100,
  })
  // create higher level
  const engine = new JsonRpcEngine()
  const provider = providerFromEngine(engine)
  // add block ref middleware
  engine.push(createBlockRefMiddleware({ provider, blockTracker }))
  // hit tracker
  const hitTracker = createHitTrackerMiddleware()
  engine.push(hitTracker)
  // add data source
  engine.push(providerAsMiddleware(dataProvider))
  const query = new EthQuery(provider)
github trufflesuite / drizzle-utils / packages / test-chain / index.js View on Github external
const initProviderWeb3 = async ganacheOptions => {
  // Spawn Ganache test blockchain

  const provider = Ganache.provider(ganacheOptions || defaultGanacheOptions);
  const web3 = new Web3(provider);
  const accounts = await web3.eth.getAccounts();

  return { provider, web3, accounts };
};
github MetaMask / eth-json-rpc-middleware / test / wallet.js View on Github external
function createTestSetup () {
  // raw data source
  const ganacheProvider = GanacheCore.provider()
  // create higher level
  const engine = new JsonRpcEngine()
  const provider = providerFromEngine(engine)
  const query = new EthQuery(provider)
  const ganacheQuery = new EthQuery(ganacheProvider)

  return { engine, provider, ganacheProvider, query, ganacheQuery }
}
github JoinColony / colonyNetwork / packages / reputation-miner / ReputationMiner.js View on Github external
constructor({ loader, minerAddress, privateKey, provider, realProviderPort = 8545, useJsTree = false, dbPath = "./reputationStates.sqlite" }) {
    this.loader = loader;
    this.minerAddress = minerAddress;
    this.dbPath = dbPath;

    this.useJsTree = useJsTree;
    if (!this.useJsTree) {
      const ganacheProvider = ganache.provider({
        network_id: 515,
        vmErrorsOnRPCResponse: false,
        locked: false,
        verbose: true,
        accounts: [
          {
            balance: "0x10000000000000000000000000",
            secretKey
          }
        ]
      });
      this.ganacheProvider = new ethers.providers.Web3Provider(ganacheProvider);
      this.ganacheWallet = new ethers.Wallet(secretKey, this.ganacheProvider);
    }

    // This will have to support provider.getSigner https://docs.ethers.io/ethers.js/html/api-providers.html#jsonrpcprovider
github embark-framework / subspace / test / test4.js View on Github external
const ganache = require("ganache-core");
const Web3Eth = require('web3-eth');
const Subspace = require('../dist/node.js');

console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
let eth = new Web3Eth(ganache.provider());

async function run() {
  let accounts = await eth.getAccounts();
  
  setTimeout(async () => {
    await eth.sendTransaction({from: accounts[0], to: accounts[1], value: "100000000"});
    await eth.sendTransaction({from: accounts[2], to: accounts[0], value: "999999999"});
    await eth.sendTransaction({from: accounts[2], to: accounts[0], value: "232433434"});
  }, 2000);

  const subspace = new Subspace(eth.currentProvider);

  await subspace.init();

  subspace.trackBalance(accounts[0]).subscribe((balance) => {
    console.log("accounts[0] balance is ", balance);
github trufflesuite / truffle-core / test / scenarios / debugging / debugging.js View on Github external
before("set up Ganache server", function(done) {
    var logger = {
      log: function(message) {
        //console.log(message);
      }
    };

    server = TestRPC.server({
      logger: logger
    });

    server.listen(port, function(err) {
      provider = new Web3.providers.HttpProvider("http://localhost:" + port);
      done();
    });
  });

ganache-core

[![npm Version](https://img.shields.io/npm/v/ganache-core.svg)](https://www.npmjs.com/package/ganache-core) [![npm Downloads](https://img.shields.io/npm/dm/ganache-core.svg)](https://www.npmjs.com/package/ganache-core) [![Build Status](https://travis-ci.o

MIT
Latest version published 3 years ago

Package Health Score

55 / 100
Full package analysis