In a custom Substrate pallet unit test, I need to get a list of governance proposals using the chain state. I have used Polkadot JS to query state before but not from within a Substrate unit test in Rust.

Do I need to use a mock? I think I have to create to create the encoded key from the module and method names. This is probably way off but here's what I've come up with:

let key = twox_128("Collective") + twox_128("CouncilProposals");
let encoded_key = scale_encode(key);

let storage_key = blake2_128_concat(encoded_key);
let proposals = state_getStorage(storage_key);

What's the correct way to do it? I need an example.

  • "using the chain state" what kind of chain? Do you mean a live chain like Polkadot or just the state of your test? Feb 6, 2023 at 21:06
  • I found a better and different method for the unit test which was to call Council::function directly. Feb 7, 2023 at 22:04
  • Yea, that is the way its supposed to be done :P Feb 8, 2023 at 10:15

1 Answer 1


You could have a look at how it is done in the Nicks pallet.

In short, you are first filling the storage with existing runtime calls and then checking the storage whether these calls succeeded.

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.