Skip to content

Conversation

@eugypalu
Copy link
Collaborator

Closes #38

This PR implements the chopsticks testing integration requested in issue #38, enabling automated testing of OpenGov referenda through network forking and simulation.

Enhanced submit-referendum command:
opengov-cli submit-referendum \ --proposal "./upgrade-kusama-1.4.1/kusama-1.4.1.call" \ --network "kusama" --track "whitelistedcaller" \ --test testfile.js

  • Added --test flag to accept .js or .ts test files
  • Automatically boots chopsticks instance and executes tests when test file is provided
  • Maintains backward compatibility - existing functionality unchanged when --test is not used

New scaffold-tests command
opengov-cli scaffold-tests --network polkadot

  • Generates test scaffolding for chopsticks testing: opengov-cli scaffold-tests --network polkadot
  • Creates self-contained test files with no external dependencies (uses only Node.js built-ins)
  • Includes pre-configured network setup, account funding utilities, and test examples

await injectWhitelistedCallerCall('{}', {}, '{}');
console.log('🧪 Running user-defined tests...');
{}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What sort of tests are you looking to have here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my idea was to validates that the WhitelistedCaller origin can successfully dispatch the preimage-lookup call and that the proposal executes without runtime errors once the Fellowship whitelist and public referendum phases are complete.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great; in open-web3-stack/polkadot-ecosystem-tests#335, something similar will be done.

In essence, the critical point is that it is not necessary to fully await for a referendum's time periods to fully elapse when testing:

  1. simply extract them from storage with chopsticks,
  2. modify data to make it look like they've been in decision/confirmation for a while, with the appropriate amount of votes, and
  3. then place them back into memory
    • don't forget the associated scheduler call

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, I should have fixed it with the last commits

// Inject fellowship call into scheduler
await rpcCall('dev_setStorage', [{{
scheduler: {{
agenda: [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I see you already know how to do this!

This isn't immediately relevant, but post-AHM, the manner in which you choose the target block will change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out! Is there anything you think I should adjust in the current implementation to better prepare for post-AHM changes?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the latency;

Here's a HackMD I wrote while working on PET; I wrote a section recently about what you just asked, since I had a scheduler E2E test suite that required a very large refactor.

https://hackmd.io/@yfK7sVBMSR6uxOlHlolMcQ/HJcRDi0I1x#AHM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I should have fixed it with the last commits

eugypalu and others added 3 commits September 9, 2025 10:35
Co-authored-by: Alexandre R. Baldé <alexandrer_b@outlook.com>
@eugypalu eugypalu requested a review from rockbmb November 24, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically boot a chopsticks instance on the given network after creating a referendum

3 participants