caliper icon indicating copy to clipboard operation
caliper copied to clipboard

Add tests for `rate-control/compositeRate.js`

Open Sweetdevil144 opened this issue 9 months ago • 6 comments

This PR aims to create unit-tests for compositeRate.js class within our caliper-core package.

However, the current tests are failing due to following reasons.

Within our packages/caliper-core/lib/worker/rate-control/compositeRate.js, we find the following line :

https://github.com/hyperledger/caliper/blob/21a98f496c850840c211a670c32fcfa9240612bb/packages/caliper-core/lib/worker/rate-control/compositeRate.js#L76

However, I tried logging out this.options and was returned with an empty Object as output.

console.log('Options: ', this.options);
let weights = this.options.weights;
let rateControllers = this.options.rateControllers;

I was returned with following logs :

Options:  {}
2024.05.12-00:43:27.856 error [caliper] [composite-rate-controller]     Weight and controller definitions must be arrays.
      2) should throw error when weights and rateControllers lengths are not the same
(Similar errors for other tests too)

Due to this our initial check at line 86, that is :

https://github.com/hyperledger/caliper/blob/21a98f496c850840c211a670c32fcfa9240612bb/packages/caliper-core/lib/worker/rate-control/compositeRate.js#L79

Always throws an error. However, if we replace the line 76 above with

let weights = this.testMessage.content.weights;

Then, our tests pass.

What would be the most optimum fix for such cases?

Checklist

  • [x] A link to the issue/user story that the pull request relates to
  • [ ] How to recreate the problem without the fix
  • [ ] Design of the fix
  • [ ] How to prove that the fix works
  • [ ] Automated tests that prove the fix keeps on working
  • [ ] Documentation - any JSDoc, website, or Stackoverflow answers?

Issue/User story

Steps to Reproduce

Existing issues

This issue is a small part of #1557 which aims to increase overall code-coverage for the caliper-core package.

Sweetdevil144 avatar May 11 '24 19:05 Sweetdevil144