package Ġio . space . bitcoin core . models Ċ Ċ import Ġio . space . bitcoin core . extensions . hex To ByteArray Ċ import Ġio . space . bitcoin core . extensions . to HexString Ċ import Ġio . space . bitcoin core . extensions . to Re versed Hex Ċ import Ġio . space . bitcoin core . io . Bitcoin Input Ċ import Ġio . space . bitcoin core . serializers . Transaction Serializer Ċ import Ġio . space . bitcoin core . storage . Full Transaction Ċ import Ġio . space . bitcoin core . utils . Hash Utils Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . spe k framework . spe k 2 . Spe k Ċ import Ġorg . spe k framework . spe k 2 . style . specification . describe Ċ Ċ object ĠTransaction Test Ġ: ĠSpe k ({ ĊĊĠĠĠ Ġlateinit Ġvar Ġtransaction : ĠTransaction ĊĠĠĠ Ġlateinit Ġvar Ġfull Transaction : ĠFull Transaction ĊĊĠĠĠ Ġval Ġtx Hash LE Ġ= Ġ" 1 6 9 e 1 e 8 3 e 9 3 0 8 5 3 3 9 1 bc 6 f 3 5 f 6 0 5 c 6 7 5 4 cfe ad 5 7 cf 8 3 8 7 6 3 9 d 3 b 4 0 9 6 c 5 4 f 1 8 f 4 " ĊĠĠĠ Ġvar Ġtx Raw Ġ= Ġ" 0 1 0 0 0 0 0 0 0 1 c 9 9 7 a 5 e 5 6 e 1 0 4 1 0 2 fa 2 0 9 c 6 a 8 5 2 dd 9 0 6 6 0 a 2 0 b 2 d 9 c 3 5 2 4 2 3 ed ce 2 5 8 5 7 fcd 3 7 0 4 0 0 0 0 0 0 0 0 4 8 4 7 3 0 4 4 0 2 2 0 4 e 4 5 e 1 6 9 3 2 b 8 af 5 1 4 9 6 1 a 1 d 3 a 1 a 2 5 fdf 3 f 4 f 7 7 3 2 e 9 d 6 2 4 c 6 c 6 1 5 4 8 ab 5 fb 8 cd 4 1 0 2 2 0 1 8 1 5 2 2 ec 8 eca 0 7 de 4 8 6 0 a 4 ac dd 1 2 9 0 9 d 8 3 1 cc 5 6 cb bac 4 6 2 2 0 8 2 2 2 1 a 8 7 6 8 d 1 d 0 9 0 1 ffffffff 0 2 0 0 ca 9 a 3 b 0 0 0 0 0 0 0 0 4 3 4 1 0 4 ae 1 a 6 2 fe 0 9 c 5 f 5 1 b 1 3 9 0 5 f 0 7 f 0 6 b 9 9 a 2 f 7 1 5 9 b 2 2 2 5 f 3 7 4 cd 3 7 8 d 7 1 3 0 2 fa 2 8 4 1 4 e 7 aab 3 7 3 9 7 f 5 5 4 a 7 df 5 f 1 4 2 c 2 1 c 1 b 7 3 0 3 b 8 a 0 6 2 6 f 1 b aded 5 c 7 2 a 7 0 4 f 7 e 6 cd 8 4 cac 0 0 2 8 6 bee 0 0 0 0 0 0 0 0 4 3 4 1 0 4 1 1 db 9 3 e 1 dc db 8 a 0 1 6 b 4 9 8 4 0 f 8 c 5 3 bc 1 eb 6 8 a 3 8 2 e 9 7 b 1 4 8 2 ec ad 7 b 1 4 8 a 6 9 0 9 a 5 cb 2 e 0 e add fb 8 4 ccf 9 7 4 4 4 6 4 f 8 2 e 1 6 0 bfa 9 b 8 b 6 4 f 9 d 4 c 0 3 f 9 9 9 b 8 6 4 3 f 6 5 6 b 4 1 2 a 3 ac 0 0 0 0 0 0 0 0 " ĊĊĠĠĠ Ġdescribe (" constructor ") Ġ{ ĊĊĠĠĠĠĠĠĠ Ġit (" init ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfull Transaction Ġ= ĠTransaction Serializer . deserialize ( Bitcoin Input ( tx Raw . hex To ByteArray ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Ġ= Ġfull Transaction . header ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( full Transaction . inputs . size , Ġ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( full Transaction . outputs . size , Ġ 2 ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( full Transaction . outputs [ 0 ]. index , Ġ 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals (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 8 ea ed 2 2 1 b 3 0 bd 9 a 0 b 9 2 8 8 8 ac 0 2 4 8 ${ w itness [ 0 ]} 2 1 ${ w itness [ 1 ]} 0 0 0 0 0 0 0 0 " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfull Transaction Ġ= ĠTransaction Serializer . deserialize ( Bitcoin Input ( tx Raw . hex To ByteArray ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Ġ= Ġfull Transaction . header ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġinputs Ġ= Ġfull Transaction . inputs ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( inputs . size , Ġ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( full Transaction . outputs . size , Ġ 1 ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( transaction . seg wit , Ġtrue ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( inputs [ 0 ]. w itness [ 0 ]. to HexString (), Ġw itness [ 0 ]) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( inputs [ 0 ]. w itness [ 1 ]. to HexString (), Ġw itness [ 1 ]) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" toByteArray _ w itness ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtx Raw Ġ= Ġ" 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 5 e 1 8 0 dc 2 8 a 2 3 2 7 e 6 8 7 f acc 3 3 f 1 0 f 2 a 2 0 da 7 1 7 e 5 5 4 8 4 0 6 f 7 ae 8 b 4 c 8 1 1 0 7 2 f 8 5 6 0 1 0 0 0 0 0 0 0 0 ffffffff 0 1 0 0 b 4 f 5 0 5 0 0 0 0 0 0 0 0 1 9 7 6 a 9 1 4 1 d 7 cd 6 c 7 5 c 2 e 8 6 f 4 cbf 9 8 ea ed 2 2 1 b 3 0 bd 9 a 0 b 9 2 8 8 8 ac 0 2 4 8 3 0 4 5 0 2 2 1 0 0 df 7 b 7 e 5 cda 1 4 ddf 9 1 2 9 0 e 0 2 ea 1 0 7 8 6 e 0 3 eb 1 1 ee 3 6 ec 0 2 dd 8 6 2 fe 9 a 3 2 6 bb cb 7 fd 0 2 2 0 3 f 5 b 4 4 9 6 b 6 6 7 e 6 e 2 8 1 cc 6 5 4 a 2 da 9 e 4 f 0 8 6 6 0 c 6 2 0 a 1 0 5 1 3 3 7 fa 8 9 6 5 f 7 2 7 eb 1 9 1 9 0 1 2 1 0 3 8 2 6 2 a 6 c 6 cec 9 3 c 2 d 3 ecd 6 c 6 0 7 2 e fea 8 6 d 0 2 ff 8 e 3 3 2 8 bbd 0 2 4 2 b 2 0 af 3 4 2 5 9 9 0 ac 0 0 0 0 0 0 0 0 " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfull Transaction Ġ= ĠTransaction Serializer . deserialize ( Bitcoin Input ( tx Raw . hex To ByteArray ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Ġ= Ġfull Transaction . header ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( full Transaction . inputs . size , Ġ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( full Transaction . outputs . size , Ġ 1 ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( transaction . seg wit , Ġtrue ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( tx Raw , ĠTransaction Serializer . serialize ( full Transaction ). to HexString ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" without W itness ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtx Hash Ġ= Ġ" 8 5 3 0 de 8 e 7 7 1 c 8 3 0 c 4 e 7 6 9 0 9 b 1 fdf 0 e 0 5 5 ee 8 8 7 2 fa 1 eb bf 7 c 4 2 7 9 3 7 5 5 9 1 0 6 1 a 6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 4 ed 6 9 9 e 5 1 1 f 8 0 0 0 0 0 0 0 0 " ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġfull Transaction Ġ= ĠTransaction Serializer . deserialize ( Bitcoin Input ( tx Raw . hex To ByteArray ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransaction Ġ= Ġfull Transaction . header ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( tx Hash , Ġtransaction . hash . to Re versed Hex ()) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġbytes Ġ= ĠHash Utils . double Sha 2 5 6 ( Transaction Serializer . serialize ( full Transaction , Ġwith W itness Ġ= Ġtrue )) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( tx W itness Hash , Ġbytes . to Re versed Hex ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġit (" without W it nes ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtx Hash Ġ= Ġ" 8 5 3 0 de 8 e 7 7 1 c 8 3 0 c 4 e 7 6 9 0 9 b 1 fdf 0 e 0 5 5 ee 8 8 7 2 fa 1 eb bf 7 c 4 2 7 9 3 7 5 5 9 1 0 6 1 a 6 2 " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtx W itness Hash Ġ= Ġ" f 5 b 5 c 6 fc 1 b 1 9 9 ec fa 0 4 d 1 9 2 a 9 f 8 1 a 9 cc 6 ec 7 8 bd 8 4 8 e 1 6 3 a 8 0 b 2 d 0 7 7 b 4 fe 1 d 0 9 7 " ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġtx Raw Ġ= Ġ" 0 1 0 0 0 0 0 0 0 0 0 1 0 1 dbf 1 9 8 5 1 5 ce bea 6 e 2 4 8 a 2 1 2 c 6 3 2 9 9 e 6 3 a 2 a 3 5 a 2 def 0 a 4 2 e 4 3 e 0 1 0 6 c 2 e fff 1 2 8 6 0 1 0 0 0 0 0 0 0 0 ffffffff 0 2 e 6 9 8 8 1 0 2 0 0 0 0 0 0 0 0 1 9 7 6 a 9 1 4 d 1 b 4 3 8 0 d 7 0 9 e 9 ea 5 4 9 4 3 a 0 8 3 b 1 2 0 8 d 6 d 9 9 1 8 9 3 d 9 8 8 ac 5 8 2 7 1 1 0 1 0 0 0 0 0 0 0 0 1 6 0 0 1 4 9 0 6 3 d 7 cc 1 cf 2 d 5 5 f 6 c 0 0 7 6 e 6 5 5 8 7 c 7 5 5 dbe 9 6 ed 7 0 2 4 8 3 0 4 5 0 2 2 1 0 0 fa 1 8 1 4 5 8 5 5 d 5 5 b 2 2 1 c 0 df 4 cd 7 2 b 1 2 dcb 2 6 f 4 5 1 aa 4 b 8 ca 2 1 4 8 ef 5 3 5 d 3 e 3 7 4 ba ff 0 2 2 0 5 b 1 3 c 1 4 fbd 8 6 6 5 be 6 a 6 da 4 fb 6 5 b 4 6 a 7 3 7 6 7 9 e 9 8 8 9 5 6 ec 3 5 3 a 7 c 7 e 4 0 cbe 4 3 f 7 a 4 0 1 2 1 0 3 8 d 0 7 0 5 f 4 5 1 1 adf 8 5 0 b 1 6 baf 4 f 6 8 9 d 3 d 9 2 fe 6 3 cc 9 a 5 f 6 d 5 d 0 0 d 2 e 4 ed 6 9 9 e 5 1 1 f 8 0 0 0 0 0 0 0 0 " ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġfull Transaction Ġ= ĠTransaction Serializer . deserialize ( Bitcoin Input ( tx Raw . hex To ByteArray ())) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġbytes Ġ= ĠHash Utils . double Sha 2 5 6 ( Transaction Serializer . serialize ( full Transaction , Ġtrue )) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( tx W itness Hash , Ġbytes . to Re versed Hex ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} Ċ }) Ċ