@@ -213,6 +213,29 @@ describe('Transaction', function () {
213213  } ) 
214214
215215  describe ( 'hashForSignature' ,  function  ( )  { 
216+     it ( 'only uses V0 serialization' ,  function  ( )  { 
217+       var  randScript  =  new  Buffer ( '6a' ,  'hex' ) 
218+ 
219+       var  tmp  =  new  Transaction ( ) 
220+       tmp . addInput ( new  Buffer ( '0000000000000000000000000000000000000000000000000000000000000000' ,  'hex' ) ,  0 ) 
221+       tmp . addOutput ( randScript ,  5000000000 ) 
222+       tmp . ___toBuffer  =  tmp . __toBuffer 
223+       tmp . __toBuffer  =  function  ( a ,  b ,  c )  { 
224+         if  ( c  !==  false )  { 
225+           throw  new  Error ( 'Not meant to pass true to __toBuffer in hashForSignature' ) 
226+         } 
227+         return  this . ___toBuffer ( a ,  b ,  c ) 
228+       } 
229+ 
230+       assert . throws ( function  ( )  { 
231+         tmp . __toBuffer ( undefined ,  undefined ,  true ) 
232+       } ,  'Verify our replacement of __toBuffer can lead to an error if using witness' ) 
233+ 
234+       assert . doesNotThrow ( function  ( )  { 
235+         tmp . hashForSignature ( 0 ,  randScript ,  1 ) 
236+       } ,  "check that this situation doesn't occur normally" ) 
237+     } ) 
238+ 
216239    fixtures . hashForSignature . forEach ( function  ( f )  { 
217240      it ( 'should return '  +  f . hash  +  ' for '  +  ( f . description  ? ( 'case "'  +  f . description  +  '"' )  : f . script ) ,  function  ( )  { 
218241        var  tx  =  Transaction . fromHex ( f . txHex ) 
0 commit comments