caliper icon indicating copy to clipboard operation
caliper copied to clipboard

Unit tests for caliper-ethereum

Open davidkel opened this issue 1 year ago • 5 comments

This package has no unit tests at all New tests should not assume that the code is actually correct. It's expected that if the tests finds bugs or relevant situations where unexpected behaviour occurs then the code should also be fixed.

davidkel avatar Apr 24 '24 08:04 davidkel

Hey @davidkel . I'd like to work on this issue if this is available !

Sweetdevil144 avatar Apr 29 '24 15:04 Sweetdevil144

@Sweetdevil144 I've assigned it to you

davidkel avatar Apr 29 '24 15:04 davidkel

Thanks @davidkel . Also, can you help me with a heads up for this step? What should be my network configurations when mocking connectorFactory.js?

Sweetdevil144 avatar Apr 29 '24 16:04 Sweetdevil144

@Sweetdevil144 all I can suggest is review how the caliper-fabric does it's tests. I'm not actually familiar with the ethereum package sorry. The caliper-fabric tests are the pattern to follow.

davidkel avatar Apr 29 '24 16:04 davidkel

Created tests for connector-Factory.js. I'm trying to create tests for ethereum-connector.js but it keeps throwing logs as below when I logged the info as follow :

let configPath = CaliperUtils.resolvePath(ConfigUtil.get(ConfigUtil.keys.NetworkConfig));
        console.log(`Config Path: ${JSON.stringify(configPath)}`);
        let ethereumConfig;
        try {
            ethereumConfig = require(configPath).ethereum;
        } catch (error) {
            console.error(`Error requiring configPath: ${error}`);
            throw error;
        }

Original code lines were as follow : https://github.com/hyperledger/caliper/blob/ae23774d7bba51b55980cdc9110b11729aab96f7/packages/caliper-ethereum/lib/ethereum-connector.js#L46

Error logs :

 TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received undefined
at Module.require (node:internal/modules/cjs/loader:1223:3)
      at require (node:internal/modules/helpers:179:18)
      at new EthereumConnector (lib/ethereum-connector.js:50:30)
      at Context.<anonymous> (test/ethereum-connector.js:100:27)
      at process.processImmediate (node:internal/timers:478:21)

Take a look at my current test file from : here to know how I'm mocking the data. (I found some test network configs for ethereum pre-created, utilising the same for now).

Sweetdevil144 avatar Apr 30 '24 18:04 Sweetdevil144

Closing as we have had to drop ethereum and besu support

davidkel avatar Apr 22 '25 21:04 davidkel

I almost forgot about this due to a busy schedule. Do you want me to close the 2 linked PRs as well? Should I focus on new testing mechanisms?

Sweetdevil144 avatar Apr 29 '25 06:04 Sweetdevil144