@@ -2,23 +2,44 @@ const tape = require('tape')
2
2
const promisify = require ( 'util.promisify' )
3
3
const rlp = require ( 'rlp' )
4
4
const { keccak256 } = require ( 'ethereumjs-util' )
5
- const { decodeMultiproof, rawMultiproof, encodeMultiproof, decodeInstructions, verifyMultiproof, makeMultiproof, Instruction, Opcode } = require ( '../dist/multiproof' )
6
5
const { Trie } = require ( '../dist/baseTrie' )
7
6
const { SecureTrie } = require ( '../dist/secure' )
8
7
const { LeafNode } = require ( '../dist/trieNode' )
9
8
const { stringToNibbles } = require ( '../dist/util/nibbles' )
9
+ const {
10
+ decodeMultiproof, rawMultiproof, encodeMultiproof,
11
+ decodeInstructions, flatEncodeInstructions, flatDecodeInstructions,
12
+ verifyMultiproof, makeMultiproof, Instruction, Opcode
13
+ } = require ( '../dist/multiproof' )
10
14
11
- tape ( 'decode instructions' , ( t ) => {
12
- const raw = Buffer . from ( 'd0c20201c20405c603c403030303c28006' , 'hex' )
13
- const expected = [
14
- { kind : Opcode . Leaf } ,
15
- { kind : Opcode . Add , value : 5 } ,
16
- { kind : Opcode . Extension , value : [ 3 , 3 , 3 , 3 ] } ,
17
- { kind : Opcode . Branch , value : 6 }
18
- ]
19
- const res = decodeInstructions ( rlp . decode ( raw ) )
20
- t . deepEqual ( expected , res )
21
- t . end ( )
15
+ tape ( 'decode and encode instructions' , ( t ) => {
16
+ t . test ( 'rlp encoding' , ( st ) => {
17
+ const raw = Buffer . from ( 'd0c20201c20405c603c403030303c28006' , 'hex' )
18
+ const expected = [
19
+ { kind : Opcode . Leaf } ,
20
+ { kind : Opcode . Add , value : 5 } ,
21
+ { kind : Opcode . Extension , value : [ 3 , 3 , 3 , 3 ] } ,
22
+ { kind : Opcode . Branch , value : 6 }
23
+ ]
24
+ const res = decodeInstructions ( rlp . decode ( raw ) )
25
+ st . deepEqual ( expected , res )
26
+ st . end ( )
27
+ } )
28
+
29
+ t . test ( 'flat encoding' , ( st ) => {
30
+ const raw = Buffer . from ( '0204050304030303030006' , 'hex' )
31
+ const instructions = [
32
+ { kind : Opcode . Leaf } ,
33
+ { kind : Opcode . Add , value : 5 } ,
34
+ { kind : Opcode . Extension , value : [ 3 , 3 , 3 , 3 ] } ,
35
+ { kind : Opcode . Branch , value : 6 }
36
+ ]
37
+ const encoded = flatEncodeInstructions ( instructions )
38
+ st . assert ( raw . equals ( encoded ) )
39
+ const decoded = flatDecodeInstructions ( raw )
40
+ st . deepEqual ( instructions , decoded )
41
+ st . end ( )
42
+ } )
22
43
} )
23
44
24
45
tape ( 'decode and encode multiproof' , ( t ) => {
0 commit comments