33 compareBytes ,
44 concatBytes ,
55 hexToBytes ,
6+ intToBytes ,
67 randomBytes ,
78 setLengthLeft ,
8- toBytes ,
99} from '@ethereumjs/util'
1010import { assert , describe , it } from 'vitest'
1111
@@ -28,8 +28,9 @@ async function randomTrie(db: DB<string, string>, addKey: boolean = true) {
2828
2929 if ( addKey ) {
3030 for ( let i = 0 ; i < 100 ; i ++ ) {
31- const key = setLengthLeft ( toBytes ( i ) , 32 )
32- const val = toBytes ( i )
31+ const indexBytes = intToBytes ( i )
32+ const key = setLengthLeft ( indexBytes , 32 )
33+ const val = indexBytes
3334 await trie . put ( key , val )
3435 entries . push ( [ key , val ] )
3536 }
@@ -62,15 +63,15 @@ function getRandomIntInclusive(min: number, max: number): number {
6263function decreaseKey ( key : Uint8Array ) {
6364 for ( let i = key . length - 1 ; i >= 0 ; i -- ) {
6465 if ( key [ i ] > 0 ) {
65- return concatBytes ( key . slice ( 0 , i ) , toBytes ( key [ i ] - 1 ) , key . slice ( i + 1 ) )
66+ return concatBytes ( key . slice ( 0 , i ) , intToBytes ( key [ i ] - 1 ) , key . slice ( i + 1 ) )
6667 }
6768 }
6869}
6970
7071function increaseKey ( key : Uint8Array ) {
7172 for ( let i = key . length - 1 ; i >= 0 ; i -- ) {
7273 if ( key [ i ] < 255 ) {
73- return concatBytes ( key . slice ( 0 , i ) , toBytes ( key [ i ] + 1 ) , key . slice ( i + 1 ) )
74+ return concatBytes ( key . slice ( 0 , i ) , intToBytes ( key [ i ] + 1 ) , key . slice ( i + 1 ) )
7475 }
7576 }
7677}
@@ -323,8 +324,9 @@ describe('simple merkle range proofs generation and verification', () => {
323324 const trie = new MerklePatriciaTrie ( )
324325 const entries : [ Uint8Array , Uint8Array ] [ ] = [ ]
325326 for ( let i = 0 ; i < 10 ; i ++ ) {
326- const key = setLengthLeft ( toBytes ( i ) , 32 )
327- const val = toBytes ( i )
327+ const indexBytes = intToBytes ( i )
328+ const key = setLengthLeft ( indexBytes , 32 )
329+ const val = indexBytes
328330 await trie . put ( key , val )
329331 entries . push ( [ key , val ] )
330332 }
0 commit comments