@@ -6,49 +6,10 @@ var bufferutils = require('../src/bufferutils')
66var fixtures = require ( './fixtures/bufferutils.json' )
77
88describe ( 'bufferutils' , function ( ) {
9- describe ( 'pushDataSize' , function ( ) {
10- fixtures . valid . forEach ( function ( f ) {
11- it ( 'determines the pushDataSize of ' + f . dec + ' correctly' , function ( ) {
12- if ( ! f . hexPD ) return
13-
14- var size = bufferutils . pushDataSize ( f . dec )
15-
16- assert . strictEqual ( size , f . hexPD . length / 2 )
17- } )
18- } )
19- } )
20-
21- describe ( 'readPushDataInt' , function ( ) {
22- fixtures . valid . forEach ( function ( f ) {
23- if ( ! f . hexPD ) return
24-
25- it ( 'decodes ' + f . hexPD + ' correctly' , function ( ) {
26- var buffer = Buffer . from ( f . hexPD , 'hex' )
27- var d = bufferutils . readPushDataInt ( buffer , 0 )
28- var fopcode = parseInt ( f . hexPD . substr ( 0 , 2 ) , 16 )
29-
30- assert . strictEqual ( d . opcode , fopcode )
31- assert . strictEqual ( d . number , f . dec )
32- assert . strictEqual ( d . size , buffer . length )
33- } )
34- } )
35-
36- fixtures . invalid . readPushDataInt . forEach ( function ( f ) {
37- if ( ! f . hexPD ) return
38-
39- it ( 'decodes ' + f . hexPD + ' as null' , function ( ) {
40- var buffer = Buffer . from ( f . hexPD , 'hex' )
41-
42- var n = bufferutils . readPushDataInt ( buffer , 0 )
43- assert . strictEqual ( n , null )
44- } )
45- } )
46- } )
47-
489 describe ( 'readUInt64LE' , function ( ) {
4910 fixtures . valid . forEach ( function ( f ) {
50- it ( 'decodes ' + f . hex64 + ' correctly' , function ( ) {
51- var buffer = Buffer . from ( f . hex64 , 'hex' )
11+ it ( 'decodes ' + f . hex , function ( ) {
12+ var buffer = Buffer . from ( f . hex , 'hex' )
5213 var number = bufferutils . readUInt64LE ( buffer , 0 )
5314
5415 assert . strictEqual ( number , f . dec )
@@ -57,7 +18,7 @@ describe('bufferutils', function () {
5718
5819 fixtures . invalid . readUInt64LE . forEach ( function ( f ) {
5920 it ( 'throws on ' + f . description , function ( ) {
60- var buffer = Buffer . from ( f . hex64 , 'hex' )
21+ var buffer = Buffer . from ( f . hex , 'hex' )
6122
6223 assert . throws ( function ( ) {
6324 bufferutils . readUInt64LE ( buffer , 0 )
@@ -66,68 +27,13 @@ describe('bufferutils', function () {
6627 } )
6728 } )
6829
69- describe ( 'readVarInt' , function ( ) {
70- fixtures . valid . forEach ( function ( f ) {
71- it ( 'decodes ' + f . hexVI + ' correctly' , function ( ) {
72- var buffer = Buffer . from ( f . hexVI , 'hex' )
73- var d = bufferutils . readVarInt ( buffer , 0 )
74-
75- assert . strictEqual ( d . number , f . dec )
76- assert . strictEqual ( d . size , buffer . length )
77- } )
78- } )
79-
80- fixtures . invalid . readUInt64LE . forEach ( function ( f ) {
81- it ( 'throws on ' + f . description , function ( ) {
82- var buffer = Buffer . from ( f . hexVI , 'hex' )
83-
84- assert . throws ( function ( ) {
85- bufferutils . readVarInt ( buffer , 0 )
86- } , new RegExp ( f . exception ) )
87- } )
88- } )
89- } )
90-
91- describe ( 'varIntBuffer' , function ( ) {
92- fixtures . valid . forEach ( function ( f ) {
93- it ( 'encodes ' + f . dec + ' correctly' , function ( ) {
94- var buffer = bufferutils . varIntBuffer ( f . dec )
95-
96- assert . strictEqual ( buffer . toString ( 'hex' ) , f . hexVI )
97- } )
98- } )
99- } )
100-
101- describe ( 'varIntSize' , function ( ) {
102- fixtures . valid . forEach ( function ( f ) {
103- it ( 'determines the varIntSize of ' + f . dec + ' correctly' , function ( ) {
104- var size = bufferutils . varIntSize ( f . dec )
105-
106- assert . strictEqual ( size , f . hexVI . length / 2 )
107- } )
108- } )
109- } )
110-
111- describe ( 'writePushDataInt' , function ( ) {
112- fixtures . valid . forEach ( function ( f ) {
113- if ( ! f . hexPD ) return
114-
115- it ( 'encodes ' + f . dec + ' correctly' , function ( ) {
116- var buffer = Buffer . alloc ( 5 , 0 )
117-
118- var n = bufferutils . writePushDataInt ( buffer , f . dec , 0 )
119- assert . strictEqual ( buffer . slice ( 0 , n ) . toString ( 'hex' ) , f . hexPD )
120- } )
121- } )
122- } )
123-
12430 describe ( 'writeUInt64LE' , function ( ) {
12531 fixtures . valid . forEach ( function ( f ) {
126- it ( 'encodes ' + f . dec + ' correctly' , function ( ) {
32+ it ( 'encodes ' + f . dec , function ( ) {
12733 var buffer = Buffer . alloc ( 8 , 0 )
12834
12935 bufferutils . writeUInt64LE ( buffer , f . dec , 0 )
130- assert . strictEqual ( buffer . toString ( 'hex' ) , f . hex64 )
36+ assert . strictEqual ( buffer . toString ( 'hex' ) , f . hex )
13137 } )
13238 } )
13339
@@ -141,25 +47,4 @@ describe('bufferutils', function () {
14147 } )
14248 } )
14349 } )
144-
145- describe ( 'writeVarInt' , function ( ) {
146- fixtures . valid . forEach ( function ( f ) {
147- it ( 'encodes ' + f . dec + ' correctly' , function ( ) {
148- var buffer = Buffer . alloc ( 9 , 0 )
149-
150- var n = bufferutils . writeVarInt ( buffer , f . dec , 0 )
151- assert . strictEqual ( buffer . slice ( 0 , n ) . toString ( 'hex' ) , f . hexVI )
152- } )
153- } )
154-
155- fixtures . invalid . readUInt64LE . forEach ( function ( f ) {
156- it ( 'throws on ' + f . description , function ( ) {
157- var buffer = Buffer . alloc ( 9 , 0 )
158-
159- assert . throws ( function ( ) {
160- bufferutils . writeVarInt ( buffer , f . dec , 0 )
161- } , new RegExp ( f . exception ) )
162- } )
163- } )
164- } )
16550} )
0 commit comments