package Ġnet . cord a . examples . attachments . tests . flow Ċ Ċ import Ġnet . cord a . core . contracts . Transaction Verification Exception Ċ import Ġnet . cord a . core . crypto . Secure Hash Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . node . services . query By Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . utilities . get OrThrow Ċ import Ġnet . cord a . examples . attachments . BLACK LIST _ JAR _ PATH Ċ import Ġnet . cord a . examples . attachments . flow . Ag ree Flow Ċ import Ġnet . cord a . examples . attachments . flow . Pro pose Flow Ċ import Ġnet . cord a . examples . attachments . state . Agreement State Ċ import Ġnet . cord a . examples . attachments . tests . IN CORRECT _ JAR _ PATH Ċ import Ġnet . cord a . testing . node . Mock Network Ċ import Ġnet . cord a . testing . node . Mock Network Parameters Ċ import Ġnet . cord a . testing . node . Started Mock Node Ċ import Ġnet . cord a . testing . node . Test C ord app Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġjava . io . File Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assert Fails With Ċ import Ġkotlin . test . assertNotNull Ċ Ċ class ĠFlow Tests Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġnetwork : ĠMock Network ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġa : ĠStarted Mock Node ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġb : ĠStarted Mock Node ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġa Identity : ĠParty ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġb Identity : ĠParty ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġagreement Txt : ĠString ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġblacklist Attachment : ĠSecure Hash ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġincorrect Attachment : ĠSecure Hash ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġnetwork Ġ= ĠMock Network ( Mock Network Parameters ( cord apps ForAll Nodes Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest C ord app . find C ord app (" net . cord a . examples . attachments . contract ")) )) ĊĠĠĠĠĠĠĠ Ġa Ġ= Ġnetwork . createNode () ĊĠĠĠĠĠĠĠ Ġb Ġ= Ġnetwork . createNode () ĊĠĠĠĠĠĠĠ Ġa Identity Ġ= Ġa . info . legal Id entities . first () ĊĠĠĠĠĠĠĠ Ġb Identity Ġ= Ġb . info . legal Id entities . first () ĊĊĠĠĠĠĠĠĠ Ġagreement Txt Ġ= Ġ"${ a Identity . name } Ġagre es Ġwith Ġ${ b Identity . name } Ġthat ..." ĊĊĠĠĠĠĠĠĠ Ġ// ĠWe Ġupload Ġthe Ġvalid Ġattachment Ġto Ġthe Ġfirst Ġnode , Ġwho Ġwill Ġpropagate Ġit Ġto Ġthe Ġother Ġnode Ġas Ġpart Ġof Ġthe ĊĠĠĠĠĠĠĠ Ġ// Ġflow . ĊĠĠĠĠĠĠĠ Ġval Ġattachment InputStream Ġ= ĠFile ( BLACK LIST _ JAR _ PATH ). inputStream () ĊĠĠĠĠĠĠĠ Ġa . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġblacklist Attachment Ġ= Ġa . services . attachments . import Attachment ( attachment InputStream , Ġ" user ", Ġ" blacklist ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// ĠWe Ġupload Ġthe Ġinvalid Ġattachment Ġto Ġthe Ġfirst Ġnode , Ġwho Ġwill Ġpropagate Ġit Ġto Ġthe Ġother Ġnode Ġas Ġpart Ġof Ġthe ĊĠĠĠĠĠĠĠ Ġ// Ġflow . ĊĠĠĠĠĠĠĠ Ġval Ġincorrect Attachment InputStream Ġ= ĠFile ( IN CORRECT _ JAR _ PATH ). inputStream () ĊĠĠĠĠĠĠĠ Ġa . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġincorrect Attachment Ġ= Ġa . services . attachments . import Attachment ( incorrect Attachment InputStream , Ġ" user ", Ġ" blacklist ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġb . register Initi ated Flow ( Ag ree Flow :: class . java ) ĊĊĠĠĠĠĠĠĠ Ġnetwork . run Network () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġnetwork . stop Nodes () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` flow Ġreject s Ġattachments Ġthat Ġdo Ġnot Ġmeet Ġthe Ġconstraints Ġof ĠAttachment Contract `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġflow Ġ= ĠPro pose Flow ( agreement Txt , Ġincorrect Attachment , Ġb Identity ) ĊĠĠĠĠĠĠĠ Ġval Ġfuture Ġ= Ġa . start Flow ( flow ) ĊĠĠĠĠĠĠĠ Ġnetwork . run Network () ĊĠĠĠĠĠĠĠ Ġassert Fails With < Transaction Verification Exception > Ġ{ Ġfuture . get OrThrow () Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` flow Ġrecords Ġthe Ġcorrect Ġtransaction Ġin Ġboth Ġparties ' Ġtransaction Ġstorage s `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsigned Tx Ġ= Ġreach Agreement () ĊĊĠĠĠĠĠĠĠ Ġ// ĠWe Ġcheck Ġthe Ġrecorded Ġtransaction Ġin Ġboth Ġtransaction Ġstorage s . ĊĠĠĠĠĠĠĠ ĠlistOf ( a , Ġb ). forEach Ġ{ Ġnode Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrecorded Tx Ġ= Ġnode . services . validated Transactions . getTransaction ( signed Tx . id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertNotNull ( re corded Tx ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠChecks Ġon Ġthe Ġsignatures . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrecorded Tx !!. verify Required Signatures () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠChecks Ġon Ġthe Ġinputs . ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġrecorded Tx . inputs . size ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠChecks Ġon Ġthe Ġoutputs . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġoutputs Ġ= Ġrecorded Tx . tx . outputs ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġoutputs . size ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrecorded State Ġ= Ġoutputs . single (). data Ġas ĠAgreement State ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( a Identity , Ġrecorded State . party A ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( b Identity , Ġrecorded State . party B ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( agreement Txt , Ġrecorded State . txt ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠChecks Ġon Ġthe Ġattachments . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġattachments Ġ= Ġrecorded Tx . tx . attachments ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġattachments . size ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġassert ( attachments . contains ( blacklist Attachment )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` flow Ġrecords Ġthe Ġcorrect Ġagreement Ġin Ġboth Ġparties ' Ġvault s `() Ġ{ ĊĠĠĠĠĠĠĠ Ġreach Agreement () ĊĊĠĠĠĠĠĠĠ Ġ// ĠWe Ġcheck Ġthe Ġrecorded Ġagreement Ġin Ġboth Ġvault s . ĊĠĠĠĠĠĠĠ ĠlistOf ( a , Ġb ). forEach Ġ{ Ġnode Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnode . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġagreements Ġ= Ġnode . services . vault Service . query By < Agreement State >(). states ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġagreements . size ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrecorded State Ġ= Ġagreements . single (). state . data ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( a Identity , Ġrecorded State . party A ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( b Identity , Ġrecorded State . party B ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( agreement Txt , Ġrecorded State . txt ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` flow Ġpropag ates Ġthe Ġattachment Ġto ĠB 's Ġattachment Ġstorage `() Ġ{ ĊĠĠĠĠĠĠĠ Ġreach Agreement () ĊĊĠĠĠĠĠĠĠ Ġ// ĠWe Ġcheck Ġthe Ġrecorded Ġagreement Ġin Ġboth Ġattachment Ġstorage s . ĊĠĠĠĠĠĠĠ Ġb . transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġblacklist Ġ= Ġb . services . attachments . open Attachment ( blacklist Attachment ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertNotNull ( blacklist ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠUses Ġthe Ġpropose Ġflow Ġto Ġrecord Ġan Ġagreement Ġon Ġthe Ġledger . ĊĠĠĠ Ġprivate Ġfun Ġreach Agreement (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġflow Ġ= ĠPro pose Flow ( agreement Txt , Ġblacklist Attachment , Ġb Identity ) ĊĠĠĠĠĠĠĠ Ġval Ġfuture Ġ= Ġa . start Flow ( flow ) ĊĠĠĠĠĠĠĠ Ġnetwork . run Network () ĊĠĠĠĠĠĠĠ Ġreturn Ġfuture . get OrThrow () ĊĠĠĠ Ġ} Ċ } Ċ