Open aklenik opened 2 years ago
The above issues are fixed 👍
parameterList
? I guess it's a leftover variable. Also there is a trailing space linting error before this part:
https://github.com/bistaastha/caliper/blob/8128511f5ddbc144e574646e5c500f604984ec6a/packages/caliper-core/lib/worker/workload/declarative/contract-function-parameter.js#L29-L35this.valueProvider
, its intention is more clear that way:
https://github.com/bistaastha/caliper/blob/8128511f5ddbc144e574646e5c500f604984ec6a/packages/caliper-core/lib/worker/workload/declarative/contract-function-parameter.js#L37T1. The generateValue
call should return the value generated by the underlying value provider:
https://github.com/bistaastha/caliper/blob/8128511f5ddbc144e574646e5c500f604984ec6a/packages/caliper-core/lib/worker/workload/declarative/contract-function-parameter.js#L44-L47
T2. The generateCallArguments
call should return a value for every parameter of a function (by calling their generateValue
function). The new values should be returned in a key-value object style: { param1Name: value1; param2Name: value2; }
https://github.com/bistaastha/caliper/blob/8128511f5ddbc144e574646e5c500f604984ec6a/packages/caliper-core/lib/worker/workload/declarative/contract-function.js#L38-L40
T3. The DeclarativeWorkloadModuleBase class should have a "selector" variable, that can select a uniformly random contract name from the available contracts (reusing hardwired value provider objects that achieve exactly what we want).
T4. The Contract class should have a "selector" variable, that can select a uniformly random function name from the available functions (reusing hardwired value provider objects that achieve exactly what we want).
Next remarks:
new
operator from here:
https://github.com/bistaastha/caliper/blob/d6d81d40d40a3de2c47d45e0f710168a9001dc74/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L59floor([0,1) * 0) = floor(0) = 0
(correct)
For a 2 elements list: floor([0,1) * 1) = floor([0,1)) = 0
(always the first is selected)
For a 3 elements list: floor([0,1) * 2) = floor([0,2)) = [0,1]
(the last is never selected)
For a 4 elements list: floor([0,1) * 3) = floor([0,3)) = [0,2]
(the last is never selected)
... and so on. So the last element is never selected. You need to multiply with only this.referenceList.length
contractSelector
and functionSelector
, respectively. ContractFunctionParameter
instances here, you will also need them on the next generate call:
https://github.com/bistaastha/caliper/blob/d6d81d40d40a3de2c47d45e0f710168a9001dc74/packages/caliper-core/lib/worker/workload/declarative/contract-function.js#L39
Instead, create a new empty object (like callAruments
) and add the newly generated values to that.generatedValues
is a local variable, so don't need the this
https://github.com/bistaastha/caliper/blob/e5e18fabf34d6525c89353dc3ea894ad216c0988/packages/caliper-core/lib/worker/workload/declarative/contract-function.js#L40super
call to the same function of the base class, so it initializes the instance variables:
https://github.com/bistaastha/caliper/blob/e5e18fabf34d6525c89353dc3ea894ad216c0988/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L44-L45
So add this as first line in the function:
await super.initializeWorkloadModule(workerIndex, totalWorkers, roundIndex, roundArguments, sutAdapter, sutContext);
T1. Randomly select a contract function, and return its generated arguments:
https://github.com/bistaastha/caliper/blob/e5e18fabf34d6525c89353dc3ea894ad216c0988/packages/caliper-core/lib/worker/workload/declarative/contract.js#L38-L44
T2. Randomly select a contract and returns its (randomly selected function's) generated arguments:
https://github.com/bistaastha/caliper/blob/e5e18fabf34d6525c89353dc3ea894ad216c0988/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L71
T3. submitTransaction
should call a new submitWithArguments(generatedArguments)
function, that can be implemented by derived classes (it should throw an error in the DeclarativeWorkloadModuleBase class). So as for now, we leave the actual "custom args to connector args" transformation to be implemented in derived classes, and we won't automate it for now.
Awesome 👍 The only thing left is to expose the workload module class from the core package, so users can use it for their workload modules as a base class.
Just add a similar export to the end of this file: https://github.com/bistaastha/caliper/blob/361c03b8587245e2d12447c2d774c5bf3e289091/packages/caliper-core/index.js#L32
DeclarativeWorkloadModuleBase
should just simply extend theWorkloadModuleBase
class, which performs most of the initialization. Then theinitializeWorkloadModule
function can be overridden to perform the extra init step (after calling thesuper
init). https://github.com/bistaastha/caliper/blob/64f0a67a9264197c8288845d2d2ef17bf433425d/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L24this.something = {};
instead https://github.com/bistaastha/caliper/blob/64f0a67a9264197c8288845d2d2ef17bf433425d/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L88 https://github.com/bistaastha/caliper/blob/64f0a67a9264197c8288845d2d2ef17bf433425d/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L96for(const key of Object.keys(roundArguments)) { ... }
to iterate through the keys of an object. https://github.com/bistaastha/caliper/blob/64f0a67a9264197c8288845d2d2ef17bf433425d/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L89for(const contractObject of roundArguments.contracts) {...}
(instead ofin
) https://github.com/bistaastha/caliper/blob/64f0a67a9264197c8288845d2d2ef17bf433425d/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L97Instead of: https://github.com/bistaastha/caliper/blob/64f0a67a9264197c8288845d2d2ef17bf433425d/packages/caliper-core/lib/worker/workload/declarative/declarative-workload-module-base.js#L98