0

I saw this in Zombienet's Testing DSL page: https://github.com/paritytech/zombienet/blob/main/docs/src/test-dsl-definition-spec.md

Under Available Assertions

Custom js scripts: Allow to run a defined script and assert on the completeness or return value.

    node-name: js-script script_relative_path [ return is comparator target_value] [within x seconds]
        alice: js-script ./0008-custom.js return is greater than 1 within 200 seconds

How can I do that? My network file, z05-small-network.toml :

[relaychain]
default_image = "docker.io/parity/polkadot:{{POLKADOT_VERSION}}"
default_command = "polkadot"
default_args = [ "-lparachain=debug" ]
chain = "rococo-local"

  [[relaychain.nodes]]
  name = "alice"
  validator = true

  [[relaychain.nodes]]
  name = "bob"
  validator = true

[[parachains]]
id = 2000
cumulus_based = true

  [parachains.collator]
  name = "collator01"
  image = "{{COLLATOR_URL}}"
  command = "hero-collator"
  args = ["-lparachain=debug"]
  
[types.Header]
number = "u64"
parent_hash = "Hash"
post_state = "Hash"

My feature file:

Description: Small Network test
Network: ./z05-small-network.toml
Creds: config

# well know functions
alice: is up
bob: is up
alice: parachain 2000 is registered within 225 seconds

alice: js-script ./01-custom.js return is greater than 1 within 200 seconds

My Js file... 01-custom.js:

console.log("hello!!!");
return 2;

Then I got this error:

    ✔ alice: is up (147ms)
    ✔ bob: is up (88ms)
2022-08-24 18:46:43        API/INIT: Not decorating unknown runtime apis: 0xe5bdc752b8ec2ba1/1, 0x91a3c6922fd0a608/1, 0xb69782c4499462e5/1
    ✔ alice: parachain 2000 is registered within 225 seconds (2734ms)
hello!!!

     Error running script: ./01-custom.js
         undefined is not a function

    1) alice: js-script ./01-custom.js return is greater than 1 within 200 seconds

How can I assert on the completeness or return value?

1 Answer 1

1

thanks for your feedback! The custom js script must export a function call run that zombienet will call as part of the assertion.

You can check as example https://github.com/paritytech/zombienet/blob/main/tests/0008-custom.js

async function run(nodeName, networkInfo, args) {
    const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName];
    const api = await zombie.connect(wsUri, userDefinedTypes);
    const validator = await api.query.session.validators();
    return validator.length;
}

module.exports = { run }

I will also update the documentation to make notice of this requirement.

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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