4

I'm trying to run some test cases in Travis CI using truffle but I want some of them not to run if the test environment(localhost:8545) is running via "testrpc" because some of my test cases only work with geth, not with testrpc.

If somehow I know the test environment while running test cases, I can skip test cases using "if condition in code" as per Mocha JS documentation -

it('should only test in the correct environment', function() {
  if (/* check test environment */) {
    // make assertions
  } else {
    this.skip();
  }
});

my turffle.js looks like this -

networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*'   // Match any network id
    },
    geth: {             
      host: 'some ec2 url',
      port: 8545,
      network_id: '*',
      gasPrice: 20e9,
      gas: 0xfffffff,
    }
  }

development environment is running on testrpc(localhost) and geth environment is talking to a geth node on an EC2 instance.

In test case, if detected environment is development then only my test cases should run, otherwise not. So can someone help me that how do I find the truffle environment while running testcases?

1

I am not sure that this would work, but you might try to use the network-id, which you can get in your tests from the JSON-RPC API by querying for the net_version. On public Ethereum chains these are well-defined numbers, and on testrpc you should be able to define your own by using the -i flag.

I suspect there is a way of getting this information directly from Truffle (after all it must know which of the network configurations you are using for deployment purposes) but I could not find any reference to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.