First of all I am working on Polkadot-v0.9.29. I am struggling to understand the right way to format a pallet call before submitting it as a proposal to the democracy pallet. Let's the pallet call be the famous:
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
let who = ensure_signed(origin)?;
// Update storage.
<Something<T>>::put(something);
// Emit an event.
Self::deposit_event(Event::SomethingStored { something, who });
// Return a successful DispatchResultWithPostInfo
Ok(())
}
consider the following code:
I prepared a function that formats the call as follows:
pub fn create_proposal_hash_and_note(caller: T::AccountId,call:<T as Config>::Call) -> T::Hash {
let origin = RawOrigin::Signed(caller);
let call_wrap = Box::new(call);
let proposal_hash = T::Hashing::hash_of(&call_wrap);
let proposal_encoded: Vec<u8> = call_wrap.encode();
match Dem::Pallet::<T>::note_preimage(origin.into(), proposal_encoded){
Ok(_) => (),
Err(x) if x == Error::<T>::DuplicatePreimage.into() => (),
Err(x) => panic!("{:?}", x),
}
proposal_hash
}
Then I create the formated call, submit the proposal and start a referendum:
let call = Call::<T>::do_something{
something:32
};
//Create and add the proposal
let prop_hash = Self::create_proposal_hash_and_note(virtual_account.clone(),rep_call.into());
Dem::Pallet::<T>::propose(origin_v.into(),prop_hash,deposit.into()).ok();
....
I Already checked through testing, that:
- the referendum is correctly started
- the proposal hash is registered
- after voting, the referendum completes normally only problem is the proposal is not enacted. I think it's because the proposal is not correctly formated, but I really don't know Where/why. If you want to see the full code:
Help, please?
EDIT 1
Code sample of the test I'm using with the Real pallet call:
let b = match ref_infos{
pallet_democracy::ReferendumInfo::Finished{approved,end:_} => approved,
_=> false,
} ;
println!("\n\nReferendum status after vote is: {:?}\n present block is: {:?}\n\n",&ref_infos,System::block_number());
println!("\n\nvote result is:{:?}",b);
let prop0 = AssetManagement::proposals(0).unwrap().vote_result;
println!("\n\nVote results:{:?}\n\n",prop0);
//Proposal enactement should happen 2 blocks later
fast_forward_to(end_block_number
.saturating_add(<Test as crate::Config>::Delay::get()));
//The code line below fails as the pallet call is not executed as it should
assert_eq!(Roles::RepresentativeLog::<Test>::contains_key(FERDIE), true);
EDIT 2
In the event emitted after the vote, I get the following error message:
Invalid preimage
assert_eq!(Roles::RepresentativeLog::<Test>::contains_key(FERDIE), true);