package Ġnet . cord a . core tests . flows Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġnet . cord a . core . contracts .* Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . identity . Abstract Party Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . node . States To Record Ċ import Ġnet . cord a . core . node . services . Vault Ċ import Ġnet . cord a . core . node . services . query By Ċ import Ġnet . cord a . core . node . services . vault . Query Criteria Ċ import Ġnet . cord a . core . transactions . Ledger Transaction Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . get OrThrow Ċ import Ġnet . cord a . node . VersionInfo Ċ import Ġnet . cord a . testing . common . internal . test Network Parameters Ċ import Ġnet . cord a . testing . node . internal .* Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠRefer enced States Flow Tests Ġ{ ĊĊĠĠĠ Ġvar Ġmock Net : ĠInternal Mock Network Ġ= ĠInternal Mock Network ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġc ord apps ForAll Nodes Ġ= ĠlistOf ( D UMMY _ CONTRACT S _ C ORD APP , Ġen closed C ord app ()), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthread Per Node Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinitial Network Parameters Ġ= Ġtest Network Parameters ( minimum Platform Version Ġ= Ġ 4 ) ĊĠĠĠ Ġ) ĊĠĠĠ Ġlateinit Ġvar Ġnodes : ĠList < Test Started Node > ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġnodes Ġ= Ġ( 0 .. 2 ). map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Net . createNode ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġparameters Ġ= ĠInternal Mock Node Parameters ( version Ġ= ĠVersion Info ( 4 , Ġ" Bl ah ", Ġ" Bl ah ", Ġ" Bl ah ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġstop () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Net . stop Nodes () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout = 3 0 0 _ 0 0 0 ) Ċ ĉ fun Ġ` with Ġreferenced Ġstates Ġflow Ġblocks Ġuntil Ġthe Ġreference Ġstate Ġupdate Ġis Ġreceived `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġ 1 . ĠCreate Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Create Ref State ()). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref State Ġ= Ġnew Ref Tx . tx . out Refs OfType < Ref State . State >(). single () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 2 . ĠShare Ġit Ġwith Ġothers . ĊĠĠĠĠĠĠĠ Ġnodes [ 0 ]. services . start Flow ( Init iator ( new Ref State )). result Future . get OrThrow () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 3 . ĠUpdate Ġthe Ġreference Ġstate Ġbut Ġdon 't Ġshare Ġthe Ġupdate . ĊĠĠĠĠĠĠĠ Ġval Ġupdated Ref Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Update Ref State ( new Ref State )). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġval Ġupdated Ref State Ġ= Ġupdated Ref Tx . tx . out Refs OfType < Ref State . State >(). single () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 4 . ĠTry Ġto Ġuse Ġthe Ġold Ġreference Ġstate . ĠThis Ġwill Ġthrow Ġa ĠNot ary Exception . ĊĠĠĠĠĠĠĠ Ġval Ġnode One Identity Ġ= Ġnodes [ 1 ]. info . legal Id entities . first () ĊĠĠĠĠĠĠĠ Ġval ĠuseRef Tx Ġ= Ġnodes [ 1 ]. services . start Flow ( With Referenced States Flow Ġ{ ĠUse Ref State ( node One Identity , Ġnew Ref State . state . data . linear Id ) Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. result Future ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 5 . ĠShare Ġthe Ġupdate Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġnodes [ 0 ]. services . start Flow ( Init iator ( updated Ref State )). result Future . get OrThrow () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 6 . ĠCheck Ġthat Ġwe Ġhave Ġa Ġvalid Ġsigned Ġtransaction Ġwith Ġthe Ġupdated Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠuseRef Tx . get OrThrow () ĊĠĠĠĠĠĠĠ ĠassertEquals ( updated Ref State . ref , Ġresult . tx . references . single ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout = 3 0 0 _ 0 0 0 ) Ċ ĉ fun Ġ` check Ġref Ġstate Ġis Ġpersisted Ġwhen Ġused Ġin Ġtx Ġwith Ġrelevant Ġstates `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġ 1 . ĠCreate Ġa Ġstate Ġto Ġbe Ġused Ġas Ġa Ġreference Ġstate . ĠDon 't Ġshare Ġit . ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Create Ref State ()). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref State Ġ= Ġnew Ref Tx . tx . out Refs OfType < Ref State . State >(). single () ĊĠĠĠĠĠĠĠ Ġ// Ġ 2 . ĠUse Ġthe Ġ" new Ref State " Ġa Ġtransaction Ġinvol ving Ġanother Ġparty Ġ( nodes [ 1 ]) Ġwhich Ġcreates Ġa Ġnew Ġstate . ĠThey Ġshould Ġstore Ġthe Ġnew Ġstate Ġand Ġthe Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġnew Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Use Ref State ( nodes [ 1 ]. info . legal Id entities . first (), Ġnew Ref State . state . data . linear Id )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠWait Ġuntil Ġnode Ġ 1 Ġstores Ġthe Ġnew Ġtx . ĊĠĠĠĠĠĠĠ Ġnodes [ 1 ]. services . validated Transactions . track Transaction ( new Tx . id ). get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġnodes [ 1 ] Ġhas Ġfinished Ġrecording Ġthe Ġtransaction Ġ( and Ġupdating Ġthe Ġvault .. Ġhopefully ! ). ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 1 ] Ġshould Ġhave Ġtwo Ġstates . ĠThe Ġnewly Ġcreated Ġoutput Ġof Ġtype Ġ" Regular . State " Ġand Ġthe Ġreference Ġstate Ġcreated Ġby Ġnodes [ 0 ]. ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġnodes [ 1 ]. services . vault Service . query By < Linear State >(). states . size ) ĊĠĠĠĠĠĠĠ Ġ// ĠNow Ġlet 's Ġfind Ġthe Ġspecific Ġreference Ġstate Ġon Ġnodes [ 1 ]. ĊĠĠĠĠĠĠĠ Ġval Ġref State Linear Id Ġ= Ġnew Ref State . state . data . linear Id ĊĠĠĠĠĠĠĠ Ġval Ġquery Ġ= ĠQuery Criteria . Linear State Query Criteria ( linear Id Ġ= ĠlistOf ( ref State Linear Id )) ĊĠĠĠĠĠĠĠ Ġval Ġthe Referenced State Ġ= Ġnodes [ 1 ]. services . vault Service . query By < Ref State . State >( query ) ĊĠĠĠĠĠĠĠ Ġ// ĠThere Ġshould Ġbe Ġone Ġresult Ġ- Ġthe Ġreference Ġstate . ĊĠĠĠĠĠĠĠ ĠassertEquals ( new Ref State , Ġthe Referenced State . states . single ()) ĊĠĠĠĠĠĠĠ Ġprintln ( the Referenced State . states Metadata . single ()) ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 0 ] Ġshould Ġalso Ġhave Ġthe Ġsame Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġnode Zero Query Ġ= ĠQuery Criteria . Linear State Query Criteria ( linear Id Ġ= ĠlistOf ( ref State Linear Id )) ĊĠĠĠĠĠĠĠ Ġval Ġthe Referenced State On Node Zero Ġ= Ġnodes [ 0 ]. services . vault Service . query By < Ref State . State >( node Zero Query ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( new Ref State , Ġthe Referenced State On Node Zero . states . single ()) ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 0 ] Ġsends Ġthe Ġtx Ġthat Ġcreated Ġthe Ġreference Ġstate Ġto Ġnodes [ 1 ]. ĊĠĠĠĠĠĠĠ Ġnodes [ 0 ]. services . start Flow ( Init iator ( new Ref State )). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠQuery Ġagain . ĊĠĠĠĠĠĠĠ Ġval Ġthe Referenced State Again Ġ= Ġnodes [ 1 ]. services . vault Service . query By < Ref State . State >( query ) ĊĠĠĠĠĠĠĠ Ġ// ĠThere Ġshould Ġbe Ġone Ġresult Ġ- Ġthe Ġreference Ġstate . ĊĠĠĠĠĠĠĠ ĠassertEquals ( new Ref State , Ġthe Referenced State Again . states . single ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout = 3 0 0 _ 0 0 0 ) Ċ ĉ fun Ġ` check Ġschema Ġmappings Ġare Ġupdated Ġfor Ġreference Ġstates `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġ 1 . ĠCreate Ġa Ġstate Ġto Ġbe Ġused Ġas Ġa Ġreference Ġstate . ĠDon 't Ġshare Ġit . ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Create Ref State ()). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref State Ġ= Ġnew Ref Tx . tx . out Refs OfType < Ref State . State >(). single () ĊĠĠĠĠĠĠĠ Ġ// Ġ 2 . ĠUse Ġthe Ġ" new Ref State " Ġa Ġtransaction Ġinvol ving Ġanother Ġparty Ġ( nodes [ 1 ]) Ġwhich Ġcreates Ġa Ġnew Ġstate . ĠThey Ġshould Ġstore Ġthe Ġnew Ġstate Ġand Ġthe Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġnew Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Use Ref State ( nodes [ 1 ]. info . legal Id entities . first (), Ġnew Ref State . state . data . linear Id )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠWait Ġuntil Ġnode Ġ 1 Ġstores Ġthe Ġnew Ġtx . ĊĠĠĠĠĠĠĠ Ġnodes [ 1 ]. services . validated Transactions . track Transaction ( new Tx . id ). get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġnodes [ 1 ] Ġhas Ġfinished Ġrecording Ġthe Ġtransaction Ġ( and Ġupdating Ġthe Ġvault .. Ġhopefully ! ). ĊĠĠĠĠĠĠĠ Ġval Ġall Ref States Ġ= Ġnodes [ 1 ]. services . vault Service . query By < Linear State >() ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 1 ] Ġshould Ġhave Ġtwo Ġstates . ĠThe Ġnewly Ġcreated Ġoutput Ġand Ġthe Ġreference Ġstate Ġcreated Ġby Ġnodes [ 0 ]. ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġall Ref States . states . size ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout = 3 0 0 _ 0 0 0 ) Ċ ĉ fun Ġ` check Ġold Ġref Ġstate Ġis Ġconsumed Ġwhen Ġupdate Ġused Ġin Ġtx Ġwith Ġrelevant Ġstates `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġ 1 . ĠCreate Ġa Ġstate Ġto Ġbe Ġused Ġas Ġa Ġreference Ġstate . ĠDon 't Ġshare Ġit . ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Create Ref State ()). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref State Ġ= Ġnew Ref Tx . tx . out Refs OfType < Ref State . State >(). single () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 2 . ĠUse Ġthe Ġ" new Ref State " Ġin Ġa Ġtransaction Ġinvol ving Ġanother Ġparty Ġ( nodes [ 1 ]) Ġwhich Ġcreates Ġa Ġnew Ġstate . ĠThey Ġshould Ġstore Ġthe Ġnew Ġstate Ġand Ġthe Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġnew Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Use Ref State ( nodes [ 1 ]. info . legal Id entities . first (), Ġnew Ref State . state . data . linear Id )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠWait Ġuntil Ġnode Ġ 1 Ġstores Ġthe Ġnew Ġtx . ĊĠĠĠĠĠĠĠ Ġnodes [ 1 ]. services . validated Transactions . track Transaction ( new Tx . id ). get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġnodes [ 1 ] Ġhas Ġfinished Ġrecording Ġthe Ġtransaction Ġ( and Ġupdating Ġthe Ġvault .. Ġhopefully ! ). ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 1 ] Ġshould Ġhave Ġtwo Ġstates . ĠThe Ġnewly Ġcreated Ġoutput Ġof Ġtype Ġ" Regular . State " Ġand Ġthe Ġreference Ġstate Ġcreated Ġby Ġnodes [ 0 ]. ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġnodes [ 1 ]. services . vault Service . query By < Linear State >(). states . size ) ĊĠĠĠĠĠĠĠ Ġ// ĠNow Ġlet 's Ġfind Ġthe Ġspecific Ġreference Ġstate Ġon Ġnodes [ 1 ]. ĊĠĠĠĠĠĠĠ Ġval Ġref State Linear Id Ġ= Ġnew Ref State . state . data . linear Id ĊĠĠĠĠĠĠĠ Ġval Ġquery Ġ= ĠQuery Criteria . Linear State Query Criteria ( linear Id Ġ= ĠlistOf ( ref State Linear Id )) ĊĠĠĠĠĠĠĠ Ġval Ġthe Referenced State Ġ= Ġnodes [ 1 ]. services . vault Service . query By < Ref State . State >( query ) ĊĠĠĠĠĠĠĠ Ġ// ĠThere Ġshould Ġbe Ġone Ġresult Ġ- Ġthe Ġreference Ġstate . ĊĠĠĠĠĠĠĠ ĠassertEquals ( new Ref State , Ġthe Referenced State . states . single ()) ĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġreference Ġstate Ġshould Ġnot Ġbe Ġconsumed . ĊĠĠĠĠĠĠĠ ĠassertEquals ( Vault . State Status . UN CON SU MED , Ġthe Referenced State . states Metadata . single (). status ) ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 0 ] Ġshould Ġalso Ġhave Ġthe Ġsame Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġnode Zero Query Ġ= ĠQuery Criteria . Linear State Query Criteria ( linear Id Ġ= ĠlistOf ( ref State Linear Id )) ĊĠĠĠĠĠĠĠ Ġval Ġthe Referenced State On Node Zero Ġ= Ġnodes [ 0 ]. services . vault Service . query By < Ref State . State >( node Zero Query ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( new Ref State , Ġthe Referenced State On Node Zero . states . single ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Vault . State Status . UN CON SU MED , Ġthe Referenced State On Node Zero . states Metadata . single (). status ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 3 . ĠUpdate Ġthe Ġreference Ġstate Ġbut Ġdon 't Ġshare Ġthe Ġupdate . ĊĠĠĠĠĠĠĠ Ġnodes [ 0 ]. services . start Flow ( Update Ref State ( new Ref State )). result Future . get OrThrow () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 4 . ĠUse Ġthe Ġe volved Ġstate Ġas Ġa Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġupdated Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Use Ref State ( nodes [ 1 ]. info . legal Id entities . first (), Ġnew Ref State . state . data . linear Id )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠWait Ġuntil Ġnode Ġ 1 Ġstores Ġthe Ġnew Ġtx . ĊĠĠĠĠĠĠĠ Ġnodes [ 1 ]. services . validated Transactions . track Transaction ( updated Tx . id ). get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġnodes [ 1 ] Ġhas Ġfinished Ġrecording Ġthe Ġtransaction Ġ( and Ġupdating Ġthe Ġvault .. Ġhopefully ! ). ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 1 ] Ġshould Ġhave Ġfour Ġstates . ĠThe Ġoriginal s , Ġplus Ġthe Ġnewly Ġcreated Ġoutput Ġof Ġtype Ġ" Regular . State " Ġand Ġthe Ġreference Ġstate Ġcreated Ġby Ġnodes [ 0 ]. ĊĠĠĠĠĠĠĠ ĠassertEquals ( 4 , Ġnodes [ 1 ]. services . vault Service . query By < Linear State >( Query Criteria . Vault Query Criteria ( status Ġ= ĠVault . State Status . ALL )). states . size ) ĊĠĠĠĠĠĠĠ Ġ// ĠNow Ġlet 's Ġfind Ġthe Ġoriginal Ġreference Ġstate Ġon Ġnodes [ 1 ]. ĊĠĠĠĠĠĠĠ Ġval Ġupdated Query Ġ= ĠQuery Criteria . Vault Query Criteria ( state Refs Ġ= ĠlistOf ( new Ref State . ref ), Ġstatus Ġ= ĠVault . State Status . ALL ) ĊĠĠĠĠĠĠĠ Ġval Ġthe Original Referenced State Ġ= Ġnodes [ 1 ]. services . vault Service . query By < Ref State . State >( updated Query ) ĊĠĠĠĠĠĠĠ Ġ// ĠThere Ġshould Ġbe Ġone Ġresult Ġ- Ġthe Ġoriginal Ġreference Ġstate . ĊĠĠĠĠĠĠĠ ĠassertEquals ( new Ref State , Ġthe Original Referenced State . states . single ()) ĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġreference Ġstate Ġshould Ġbe Ġconsumed . ĊĠĠĠĠĠĠĠ ĠassertEquals ( Vault . State Status . CON SU MED , Ġthe Original Referenced State . states Metadata . single (). status ) ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 0 ] Ġshould Ġalso Ġhave Ġthe Ġsame Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġthe Original Referenced State On Node Zero Ġ= Ġnodes [ 0 ]. services . vault Service . query By < Ref State . State >( updated Query ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( new Ref State , Ġthe Original Referenced State On Node Zero . states . single ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Vault . State Status . CON SU MED , Ġthe Original Referenced State On Node Zero . states Metadata . single (). status ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( timeout = 3 0 0 _ 0 0 0 ) Ċ ĉ fun Ġ` check Ġconsumed Ġreference Ġstate Ġis Ġfound Ġif Ġa Ġtransaction Ġrefers Ġto Ġit `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġ 1 . ĠCreate Ġa Ġstate Ġto Ġbe Ġused Ġas Ġa Ġreference Ġstate . ĠDon 't Ġshare Ġit . ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Create Ref State ()). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġval Ġnew Ref State Ġ= Ġnew Ref Tx . tx . out Refs OfType < Ref State . State >(). single () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 2 . ĠUse Ġthe Ġ" new Ref State " Ġin Ġa Ġtransaction Ġinvol ving Ġanother Ġparty Ġ( nodes [ 1 ]) Ġwhich Ġcreates Ġa Ġnew Ġstate . ĠThey Ġshould Ġstore Ġthe Ġnew Ġstate Ġand Ġthe Ġreference Ġstate . ĊĠĠĠĠĠĠĠ Ġval Ġnew Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Use Ref State ( nodes [ 1 ]. info . legal Id entities . first (), Ġnew Ref State . state . data . linear Id )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. result Future . get OrThrow () ĊĊĠĠĠĠĠĠĠ Ġ// ĠWait Ġuntil Ġnode Ġ 1 Ġstores Ġthe Ġnew Ġtx . ĊĠĠĠĠĠĠĠ Ġnodes [ 1 ]. services . validated Transactions . track Transaction ( new Tx . id ). get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġnodes [ 1 ] Ġhas Ġfinished Ġrecording Ġthe Ġtransaction Ġ( and Ġupdating Ġthe Ġvault .. Ġhopefully ! ). ĊĠĠĠĠĠĠĠ Ġ// Ġnodes [ 1 ] Ġshould Ġhave Ġtwo Ġstates . ĠThe Ġnewly Ġcreated Ġoutput Ġof Ġtype Ġ" Regular . State " Ġand Ġthe Ġreference Ġstate Ġcreated Ġby Ġnodes [ 0 ]. ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġnodes [ 1 ]. services . vault Service . query By < Linear State >(). states . size ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 3 . ĠUpdate Ġthe Ġreference Ġstate Ġbut Ġdon 't Ġshare Ġthe Ġupdate . ĊĠĠĠĠĠĠĠ Ġval Ġupdated Ref Tx Ġ= Ġnodes [ 0 ]. services . start Flow ( Update Ref State ( new Ref State )). result Future . get OrThrow () ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 4 . ĠNow Ġreport Ġthe Ġtransactions Ġthat Ġcreated Ġthe Ġtwo Ġreference Ġstates Ġto Ġa Ġthird Ġparty . ĊĠĠĠĠĠĠĠ Ġnodes [ 0 ]. services . start Flow ( Report Transaction Flow ( nodes [ 2 ]. info . legal Id entities . first (), Ġnew Ref Tx )). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġnodes [ 0 ]. services . start Flow ( Report Transaction Flow ( nodes [ 2 ]. info . legal Id entities . first (), Ġupdated Ref Tx )). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġthere Ġare Ġtwo Ġlinear Ġstates Ġin Ġthe Ġvault Ġ( note Ġthat Ġone Ġis Ġconsumed ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġnodes [ 2 ]. services . vault Service . query By < Linear State >( Query Criteria . Vault Query Criteria ( status Ġ= ĠVault . State Status . ALL )). states . size ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 5 . ĠReport Ġthe Ġtransaction Ġthat Ġuses Ġthe Ġconsumed Ġreference Ġstate ĊĠĠĠĠĠĠĠ Ġnodes [ 0 ]. services . start Flow ( Report Transaction Flow ( nodes [ 2 ]. info . legal Id entities . first (), Ġnew Tx )). result Future . get OrThrow () ĊĠĠĠĠĠĠĠ Ġ// ĠThere Ġshould Ġbe Ġ 3 Ġlinear Ġstates Ġin Ġthe Ġvault ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġnodes [ 2 ]. services . vault Service . query By < Linear State >( Query Criteria . Vault Query Criteria ( status Ġ= ĠVault . State Status . ALL )). states . size ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠA Ġdummy Ġreference Ġstate Ġcontract . ĊĠĠĠ Ġclass ĠRef State Ġ: ĠContract Ġ{ ĊĠĠĠĠĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval ĠCONTRACT _ ID : ĠString Ġ= ĠRef State :: class . java . name ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġverify ( tx : ĠLed ger Transaction ) Ġ= ĠUnit ĊĊĠĠĠĠĠĠĠ Ġdata Ġclass ĠState ( val Ġowner : ĠParty , Ġval Ġversion : ĠInt Ġ= Ġ 0 , Ġoverride Ġval Ġlinear Id : ĠUnique Identifier Ġ= ĠUnique Identifier ()) Ġ: ĠLinear State Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġval Ġparticipants : ĠList < Abstract Party > Ġget () Ġ= ĠlistOf ( owner ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfun Ġupdate () Ġ= Ġcopy ( version Ġ= Ġversion Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġclass ĠCreate Ġ: ĠCommand Data ĊĠĠĠĠĠĠĠ Ġclass ĠUpdate Ġ: ĠCommand Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġclass ĠRegular State Ġ: ĠContract Ġ{ ĊĠĠĠĠĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval ĠCONTRACT _ ID : ĠString Ġ= ĠRegular State :: class . java . name ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġverify ( tx : ĠLed ger Transaction ) Ġ= ĠUnit ĊĊĠĠĠĠĠĠĠ Ġdata Ġclass ĠState ( val Ġowner : ĠParty , Ġoverride Ġval Ġlinear Id : ĠUnique Identifier Ġ= ĠUnique Identifier ()) Ġ: ĠLinear State Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġval Ġparticipants : ĠList < Abstract Party > Ġget () Ġ= ĠlistOf ( owner ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġclass ĠCreate Ġ: ĠCommand Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠA Ġflow Ġto Ġcreate Ġa Ġreference Ġstate . ĊĠĠĠ Ġclass ĠCreate Ref State Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnot ary Ġ= Ġservice Hub . network Map Cache . not ary Id entities . first () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġservice Hub . sign Initial Transaction ( Transaction Builder ( not ary Ġ= Ġnot ary ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Output State ( Ref State . State ( our Identity ), ĠRef State . CONTRACT _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Command ( Ref State . Create (), ĠlistOf ( our Identity . own ing Key )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Final ity Flow ( st x , Ġempty List ())) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠA Ġflow Ġto Ġupdate Ġa Ġspecific Ġreference Ġstate . ĊĠĠĠ Ġclass ĠUpdate Ref State ( private Ġval Ġstate And Ref : ĠState And Ref < Ref State . State >) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnot ary Ġ= Ġservice Hub . network Map Cache . not ary Id entities . first () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġservice Hub . sign Initial Transaction ( Transaction Builder ( not ary Ġ= Ġnot ary ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Input State ( state And Ref ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Output State ( state And Ref . state . data . update (), ĠRef State . CONTRACT _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Command ( Ref State . Update (), ĠlistOf ( our Identity . own ing Key )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Final ity Flow ( st x , Ġempty List ())) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠA Ġset Ġof Ġflows Ġto Ġshare Ġa Ġstat eref Ġwith Ġall Ġother Ġnodes Ġin Ġthe Ġmock Ġnetwork . ĊĠĠĠ Ġ@ Initi ating Flow ĊĠĠĠ Ġclass ĠInit iator ( private Ġval Ġstate And Ref : ĠState And Ref < Contract State >) Ġ: ĠFlow Logic < Unit >() Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsessions Ġ= Ġservice Hub . network Map Cache . all Nodes . flatMap Ġ{ Ġit . legal Id entities Ġ}. map Ġ{ Ġinitiate Flow ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtransaction Id Ġ= Ġstate And Ref . ref . tx hash ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtransaction Ġ= Ġservice Hub . validated Transactions . getTransaction ( transaction Id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠFlow Exception (" Cannot Ġfind Ġ$ transaction Id .") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsessions . forEach Ġ{ Ġsub Flow ( Send Transaction Flow ( it , Ġtransaction )) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Initi ated By ( Init iator :: class ) ĊĠĠĠ Ġclass ĠRes pon der ( private Ġval Ġother Session : ĠFlow Session ) Ġ: ĠFlow Logic < Unit >() Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . info (" Re ceiving Ġdependencies .") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsub Flow ( Receive Transaction Flow ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġother Side Session Ġ= Ġother Session , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcheck S ufficient Signatures Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstates To Record Ġ= ĠStates To Record . ALL _ VISIBLE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠA Ġflow Ġto Ġuse Ġa Ġreference Ġstate Ġin Ġanother Ġtransaction . ĊĠĠĠ Ġ@ Initi ating Flow ĊĠĠĠ Ġclass ĠUse Ref State ( private Ġval Ġparticipant : ĠParty , Ġprivate Ġval Ġlinear Id : ĠUnique Identifier ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnot ary Ġ= Ġservice Hub . network Map Cache . not ary Id entities . first () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġquery Ġ= ĠQuery Criteria . Linear State Query Criteria ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlinear Id Ġ= ĠlistOf ( linear Id ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġre lev ancy Status Ġ= ĠVault . Re lev ancy Status . ALL ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġreference State Ġ= Ġservice Hub . vault Service . query By < Contract State >( query ). states . single () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġst x Ġ= Ġservice Hub . sign Initial Transaction ( Transaction Builder ( not ary Ġ= Ġnot ary ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Reference State ( reference State . referenced ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Output State ( Regular State . State ( participant ), ĠRef State . CONTRACT _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadd Command ( Ref State . Create (), ĠlistOf ( our Identity . own ing Key )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( participant Ġ!= Ġour Identity ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsub Flow ( Final ity Flow ( st x , ĠlistOf ( init iate Flow ( participant )))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsub Flow ( Final ity Flow ( st x , Ġempty List ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Initi ated By ( Use Ref State :: class ) ĊĠĠĠ Ġclass ĠUse Ref State Responder ( val Ġother Session : ĠFlow Session ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠThis Ġshould Ġalso Ġstore Ġthe Ġreference Ġstate Ġif Ġone Ġis Ġthere . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġsub Flow ( Receive Final ity Flow ( other Session , Ġstates To Record Ġ= ĠStates To Record . ONLY _ RE LE V ANT )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠA Ġflow Ġto Ġreport Ġa Ġtransaction Ġto Ġa Ġthird Ġparty . ĊĠĠĠ Ġ@ Initi ating Flow ĊĠĠĠ Ġ@ Start able By RPC ĊĠĠĠ Ġclass ĠReport Transaction Flow ( private Ġval Ġreport ee : ĠParty , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġsigned Tx : ĠSigned Transaction ) Ġ: ĠFlow Logic < Unit >() Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsession Ġ= Ġinitiate Flow ( report ee ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsub Flow ( Send Transaction Flow ( session , Ġsigned Tx )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsession . receive < Unit >() ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Initi ated By ( Report Transaction Flow :: class ) ĊĠĠĠ Ġclass ĠReceive Reported Transaction Flow ( private Ġval Ġother Side Session : ĠFlow Session ) Ġ: ĠFlow Logic < Unit >() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ@ Suspend able ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcall () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsub Flow ( Receive Transaction Flow ( other Side Session , Ġtrue , ĠStates To Record . ALL _ VISIBLE )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġother Side Session . send ( Unit ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ