Simulate OpenGov Referenda in Chopsticks
This is a simplified explanation of how you can dry run your OpenGov referendum. This helps you avoid situations where a misconfigured proposal leads to failed execution.
It is based on Bryan Chen's explainer here.
Watch a video version of this guide here.
Overview
What we will do is
- create the extrinsic we typically submit as preimage to OpenGov and
- use its call data to execute with elevated permissions in a local copy of the chain.
In our example, we burn the Treasury (account 13UVJyLnbVp9RBZYFwFGyDvVd1y27Tt8tkntv6Q7JVPhFsTB
) by setting the balance to 0.
Run your local simulation
- Open the Developer portal - https://polkadot.js.org/apps/
- Open the chain selector on the top left and switch to the chain of your choice
- Open the chain selector again and select "Fork Locally"
You now have a forked version of the chain state in your browser. (It might take a minute to load)
In the "Network"->"Explorer" menu can notice that the chain has "halted" and no further blocks are produced.
You can now play around with your simulated chain.
Create call data from extrinsic
At "Developer"->"Extrinsics" we configure the call:
We will call balances.forceSetBalance
of the Treasury account 13UVJyLnbVp9RBZYFwFGyDvVd1y27Tt8tkntv6Q7JVPhFsTB
with a free balance of 0
.
We don't need to submit, we just need to copy the encoded call data
Execute the call data
Visit "Developer"->"Javascript" and paste replace the code in the textbox with this:
const number = (await api.rpc.chain.getHeader()).number.toNumber()
await api.rpc('dev_setStorage', {
scheduler: {
agenda: [
[
[number + 1], [
{
call: {
Inline: '0x0508006d6f646c70792f7472737279000000000000000000000000000000000000000000'
},
origin: {
origins: 'SmallSpender'
}
}
]
]
]
}
})
await api.rpc('dev_newBlock')
At the place that says Inline
insert your call data.
Change the origin
to the appropriate name. You can find the Polkadot-specific ones here.
Hit the "Play" button in the code box.
If the execution is successful, you see no error in the box to the right.
Check the block explorer events to see what happened and if it matches your expectations.
It will take some time (~30 seconds) for the first block to execute, so wait a bit on the explorer screen before getting nervous.
Submit the real ref
You can now put the call data in a preimage and are ready to go.