@@ -546,7 +546,7 @@ impl<T: Config> Pallet<T> {
546546 }
547547
548548 pub fn create_seal_hash ( block_number_u64 : u64 , nonce_u64 : u64 , hotkey : & T :: AccountId ) -> H256 {
549- let nonce = U256 :: from ( nonce_u64) ;
549+ let nonce = nonce_u64. to_le_bytes ( ) ;
550550 let block_hash_at_number: H256 = Self :: get_block_hash_from_u64 ( block_number_u64) ;
551551 let block_hash_bytes: & [ u8 ; 32 ] = block_hash_at_number. as_fixed_bytes ( ) ;
552552 let binding = Self :: hash_block_and_hotkey ( block_hash_bytes, hotkey) ;
@@ -728,3 +728,63 @@ impl<T: Config> Pallet<T> {
728728 Ok ( Some ( weight) . into ( ) )
729729 }
730730}
731+
732+ #[ test]
733+ fn test_seal_hash ( ) {
734+ use sp_core:: { Get , H256 , U256 } ;
735+ let nonce_u64 = 123456_u64 ;
736+ let nonce = nonce_u64. to_le_bytes ( ) ;
737+ let block_and_hotkey_hash_bytes: & [ u8 ; 32 ] = & [ 1u8 ; 32 ] ;
738+
739+ let mut full_bytes = [ 0u8 ; 40 ] ;
740+ let ( first_chunk, second_chunk) = full_bytes. split_at_mut ( 8 ) ;
741+ first_chunk. copy_from_slice ( & nonce) ;
742+ second_chunk. copy_from_slice ( block_and_hotkey_hash_bytes) ;
743+
744+ let nonce = U256 :: from ( nonce_u64) ;
745+
746+ let second_full_bytes: & [ u8 ; 40 ] = & [
747+ nonce. byte ( 0 ) ,
748+ nonce. byte ( 1 ) ,
749+ nonce. byte ( 2 ) ,
750+ nonce. byte ( 3 ) ,
751+ nonce. byte ( 4 ) ,
752+ nonce. byte ( 5 ) ,
753+ nonce. byte ( 6 ) ,
754+ nonce. byte ( 7 ) ,
755+ block_and_hotkey_hash_bytes[ 0 ] ,
756+ block_and_hotkey_hash_bytes[ 1 ] ,
757+ block_and_hotkey_hash_bytes[ 2 ] ,
758+ block_and_hotkey_hash_bytes[ 3 ] ,
759+ block_and_hotkey_hash_bytes[ 4 ] ,
760+ block_and_hotkey_hash_bytes[ 5 ] ,
761+ block_and_hotkey_hash_bytes[ 6 ] ,
762+ block_and_hotkey_hash_bytes[ 7 ] ,
763+ block_and_hotkey_hash_bytes[ 8 ] ,
764+ block_and_hotkey_hash_bytes[ 9 ] ,
765+ block_and_hotkey_hash_bytes[ 10 ] ,
766+ block_and_hotkey_hash_bytes[ 11 ] ,
767+ block_and_hotkey_hash_bytes[ 12 ] ,
768+ block_and_hotkey_hash_bytes[ 13 ] ,
769+ block_and_hotkey_hash_bytes[ 14 ] ,
770+ block_and_hotkey_hash_bytes[ 15 ] ,
771+ block_and_hotkey_hash_bytes[ 16 ] ,
772+ block_and_hotkey_hash_bytes[ 17 ] ,
773+ block_and_hotkey_hash_bytes[ 18 ] ,
774+ block_and_hotkey_hash_bytes[ 19 ] ,
775+ block_and_hotkey_hash_bytes[ 20 ] ,
776+ block_and_hotkey_hash_bytes[ 21 ] ,
777+ block_and_hotkey_hash_bytes[ 22 ] ,
778+ block_and_hotkey_hash_bytes[ 23 ] ,
779+ block_and_hotkey_hash_bytes[ 24 ] ,
780+ block_and_hotkey_hash_bytes[ 25 ] ,
781+ block_and_hotkey_hash_bytes[ 26 ] ,
782+ block_and_hotkey_hash_bytes[ 27 ] ,
783+ block_and_hotkey_hash_bytes[ 28 ] ,
784+ block_and_hotkey_hash_bytes[ 29 ] ,
785+ block_and_hotkey_hash_bytes[ 30 ] ,
786+ block_and_hotkey_hash_bytes[ 31 ] ,
787+ ] ;
788+
789+ assert_eq ! ( full_bytes, * second_full_bytes) ;
790+ }
0 commit comments