33
44var assert = require ( 'assert' )
55var ecdsa = require ( '../src/ecdsa' )
6- var sinon = require ( 'sinon' )
7- var sinonTest = require ( 'sinon-test' )
8- var setupTest = sinonTest ( sinon )
6+ var hoodwink = require ( 'hoodwink' )
97
108var BigInteger = require ( 'bigi' )
119var ECPair = require ( '../src/ecpair' )
@@ -81,18 +79,20 @@ describe('HDNode', function () {
8179 } )
8280 } )
8381
84- it ( 'throws if IL is not within interval [1, n - 1] | IL === 0' , setupTest ( function ( ) {
85- this . mock ( BigInteger ) . expects ( 'fromBuffer' )
86- . once ( ) . returns ( BigInteger . ZERO )
82+ it ( 'throws if IL is not within interval [1, n - 1] | IL === 0' , hoodwink ( function ( ) {
83+ this . mock ( BigInteger , 'fromBuffer' , function ( ) {
84+ return BigInteger . ZERO
85+ } , 1 )
8786
8887 assert . throws ( function ( ) {
8988 HDNode . fromSeedHex ( 'ffffffffffffffffffffffffffffffff' )
9089 } , / P r i v a t e k e y m u s t b e g r e a t e r t h a n 0 / )
9190 } ) )
9291
93- it ( 'throws if IL is not within interval [1, n - 1] | IL === n' , setupTest ( function ( ) {
94- this . mock ( BigInteger ) . expects ( 'fromBuffer' )
95- . once ( ) . returns ( curve . n )
92+ it ( 'throws if IL is not within interval [1, n - 1] | IL === n' , hoodwink ( function ( ) {
93+ this . mock ( BigInteger , 'fromBuffer' , function ( ) {
94+ return curve . n
95+ } , 1 )
9696
9797 assert . throws ( function ( ) {
9898 HDNode . fromSeedHex ( 'ffffffffffffffffffffffffffffffff' )
@@ -124,38 +124,43 @@ describe('HDNode', function () {
124124 } )
125125
126126 describe ( 'getAddress' , function ( ) {
127- it ( 'wraps keyPair.getAddress' , setupTest ( function ( ) {
128- this . mock ( keyPair ) . expects ( 'getAddress' )
129- . once ( ) . withArgs ( ) . returns ( 'foobar' )
127+ it ( 'wraps keyPair.getAddress' , hoodwink ( function ( ) {
128+ this . mock ( hd . keyPair , 'getAddress' , function ( ) {
129+ return 'foo'
130+ } , 1 )
130131
131- assert . strictEqual ( hd . getAddress ( ) , 'foobar ' )
132+ assert . strictEqual ( hd . getAddress ( ) , 'foo ' )
132133 } ) )
133134 } )
134135
135136 describe ( 'getNetwork' , function ( ) {
136- it ( 'wraps keyPair.getNetwork' , setupTest ( function ( ) {
137- this . mock ( keyPair ) . expects ( 'getNetwork' )
138- . once ( ) . withArgs ( ) . returns ( 'network' )
137+ it ( 'wraps keyPair.getNetwork' , hoodwink ( function ( ) {
138+ this . mock ( hd . keyPair , 'getNetwork' , function ( ) {
139+ return 'foo'
140+ } , 1 )
139141
140- assert . strictEqual ( hd . getNetwork ( ) , 'network ' )
142+ assert . strictEqual ( hd . getNetwork ( ) , 'foo ' )
141143 } ) )
142144 } )
143145
144146 describe ( 'getPublicKeyBuffer' , function ( ) {
145- it ( 'wraps keyPair.getPublicKeyBuffer' , setupTest ( function ( ) {
146- this . mock ( keyPair ) . expects ( 'getPublicKeyBuffer' )
147- . once ( ) . withArgs ( ) . returns ( 'pubKeyBuffer' )
147+ it ( 'wraps keyPair.getPublicKeyBuffer' , hoodwink ( function ( ) {
148+ this . mock ( hd . keyPair , 'getPublicKeyBuffer' , function ( ) {
149+ return 'foo'
150+ } , 1 )
148151
149- assert . strictEqual ( hd . getPublicKeyBuffer ( ) , 'pubKeyBuffer ' )
152+ assert . strictEqual ( hd . getPublicKeyBuffer ( ) , 'foo ' )
150153 } ) )
151154 } )
152155
153156 describe ( 'sign' , function ( ) {
154- it ( 'wraps keyPair.sign' , setupTest ( function ( ) {
155- this . mock ( keyPair ) . expects ( 'sign' )
156- . once ( ) . withArgs ( hash ) . returns ( 'signed' )
157+ it ( 'wraps keyPair.sign' , hoodwink ( function ( ) {
158+ this . mock ( hd . keyPair , 'sign' , function ( h ) {
159+ assert . strictEqual ( hash , h )
160+ return 'foo'
161+ } , 1 )
157162
158- assert . strictEqual ( hd . sign ( hash ) , 'signed ' )
163+ assert . strictEqual ( hd . sign ( hash ) , 'foo ' )
159164 } ) )
160165 } )
161166
@@ -166,11 +171,14 @@ describe('HDNode', function () {
166171 signature = hd . sign ( hash )
167172 } )
168173
169- it ( 'wraps keyPair.verify' , setupTest ( function ( ) {
170- this . mock ( keyPair ) . expects ( 'verify' )
171- . once ( ) . withArgs ( hash , signature ) . returns ( 'verified' )
174+ it ( 'wraps keyPair.verify' , hoodwink ( function ( ) {
175+ this . mock ( hd . keyPair , 'verify' , function ( h , s ) {
176+ assert . strictEqual ( hash , h )
177+ assert . strictEqual ( signature , s )
178+ return 'foo'
179+ } , 1 )
172180
173- assert . strictEqual ( hd . verify ( hash , signature ) , 'verified ' )
181+ assert . strictEqual ( hd . verify ( hash , signature ) , 'foo ' )
174182 } ) )
175183 } )
176184 } )
0 commit comments