I have a function that creates hash from AccountId
's.
#[pallet::call_index(2)]
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
pub fn connection_request(origin: OriginFor<T>, to: T::AccountId) -> DispatchResult {
let who = ensure_signed(origin)?;
let xor = Self::create_xor(&who, &to);
...
impl<T: Config> Pallet<T> {
fn create_xor<Input: Encode>(a: &Input, b: &Input) -> T::Hash {
let mut bytes_who = a.encode();
let bytes_to = b.encode();
bytes_who.iter_mut().zip(bytes_to.iter()).for_each(|(x1, x2)| *x1 ^= *x2);
T::Hash::decode(&mut bytes_who.as_slice()).expect("all bytes are valid accounts, and the source of these bytes is the xor of two other accounts, thus this must also be a valid account/hash. qed",)
}
}
And in my tests, create_xor
fails with Error { cause: None, desc: "Not enough data to fill buffer" }
#[test]
fn connection_request_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
assert_ok!(MyPallet::connection_request(RuntimeOrigin::signed(1), 2));
...
});
}
What is the reason I get this error and how do I solve it?