trufflesuite / drizzle

Reactive Ethereum dapp UI suite
906 stars 238 forks source link

How can I inject a custom web3 provider into the drizzle app when using Nightwatch e2e tests? #91

Open jensendarren opened 4 years ago

jensendarren commented 4 years ago

I have setup a basic e2e test with a Drizzle VueJS app. It appears that when the tests run drizzle uses the fallback option for connecting to the blockchain using web sockets (ws://127.0.0.1:8545).

I want to use a custom PrivateKeyProvider for the tests so that the test run will commit transactions to the blockchain without running out of gas.

How can I tell drizzle to use this custom provider when I run the e2e Nightwatch tests? I've tried setting window.web3 using the following browser execute script but Drizzle continues to use the direct web sockets fallback option.

// In the Nightwatch JS tests/e2e folder:
browser.init();

browser.execute(function() {
  return window.web3;
}, [], function(result) {
  const provider = new PrivateKeyProvider(
    "ACCOUNT_PRIVATE_KEY",
    "http://localhost:8545"
  );
  result.value = new Web3(provider);
})

browser.waitForElementVisible('#app')

// Fill out a form and submit to blockchain
// Get out of gas error because drizzle is still using the fallback option
// and not the custom PrivateKeyProvider as needed

Any help would be greatly appreciated.