package Ġcom . cd lex ample . contracts Ċ Ċ import Ġnet . cord a . core . contracts . Bel ongsTo Contract Ċ import Ġnet . cord a . core . contracts . Command Data Ċ import Ġnet . cord a . core . contracts . Contract Ċ import Ġnet . cord a . core . contracts . Contract State Ċ import Ġnet . cord a . core . identity . Abstract Party Ċ import Ġnet . cord a . core . transactions . Ledger Transaction Ċ import Ġorg . junit . Test Ċ Ċ class ĠContract Utils Tests () Ġ{ ĊĊĠĠĠ Ġ@ Bel ongsTo Contract ( Test Contract :: class ) ĊĠĠĠ Ġclass ĠTest State A ( override Ġval Ġstatus : ĠStatus ?, Ġoverride Ġval Ġparticipants : ĠList < Abstract Party > Ġ= ĠlistOf ()) Ġ: ĠStatus State Ġ{ ĊĊĠĠĠĠĠĠĠ Ġenum Ġclass ĠTest Status Ġ: ĠStatus Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSTATUS A 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSTATUS A 2 ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bel ongsTo Contract ( Test Contract :: class ) ĊĠĠĠ Ġclass ĠTest State B ( override Ġval Ġparticipants : ĠList < Abstract Party > Ġ= ĠlistOf ()) Ġ: ĠContract State ĊĊĠĠĠ Ġ@ Bel ongsTo Contract ( Test Contract :: class ) ĊĠĠĠ Ġclass ĠTest State C ( override Ġval Ġparticipants : ĠList < Abstract Party > Ġ= ĠlistOf ()) Ġ: ĠContract State ĊĊĠĠĠ Ġ@ Bel ongsTo Contract ( Test Contract :: class ) ĊĠĠĠ Ġclass ĠTest State D ( override Ġval Ġparticipants : ĠList < Abstract Party > Ġ= ĠlistOf ()) Ġ: ĠContract State ĊĊĊĠĠĠ Ġclass ĠTest Contract Ġ: ĠContract Ġ{ ĊĠĠĠĠĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠUsed Ġto Ġidentify Ġour Ġcontract Ġwhen Ġbuilding Ġa Ġtransaction . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconst Ġval ĠID Ġ= Ġ" com . cd lex ample . contracts . Test Contract " ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġverify ( tx : ĠLed ger Transaction ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġinterface ĠCommands Ġ: ĠCommand Data Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġclass ĠCommand 1 Ġ: ĠCommands ĊĠĠĠĠĠĠĠĠĠĠĠ Ġclass ĠCommand 2 Ġ: ĠCommands ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check ĠPath Constraint Ġwith Ġdefault Ġinput Ġand Ġoutput Ġmultip lic ities `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġpath Constraint Ġ= ĠPath Constraint < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , ĠMultip licity Constraint (), ĠMultip licity Constraint ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 1 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint Ġallows Ġpath 1 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDifferent Ġcommand ĊĠĠĠĠĠĠĠ Ġval Ġpath 2 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 2 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint Ġdoes Not Allow Ġpath 2 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDifferent ĠStatus ĊĠĠĠĠĠĠĠ Ġval Ġpath 3 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 2 , Ġ 1 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint Ġdoes Not Allow Ġpath 3 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠToo Ġmany Ġinputs ĊĠĠĠĠĠĠĠ Ġval Ġpath 4 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 2 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint Ġdoes Not Allow Ġpath 4 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠTo Ġfew Ġinputs ĊĠĠĠĠĠĠĠ Ġval Ġpath 5 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 0 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint Ġdoes Not Allow Ġpath 5 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠToo Ġmany Ġoutputs ĊĠĠĠĠĠĠĠ Ġval Ġpath 6 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint Ġdoes Not Allow Ġpath 6 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠToo Ġfew Ġoutput ĊĠĠĠĠĠĠĠ Ġval Ġpath 7 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint Ġdoes Not Allow Ġpath 7 ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check ĠMultip lic ities ` (){ ĊĊĠĠĠĠĠĠĠ Ġval Ġm 1 Ġ= ĠMultip licity Constraint () ĊĠĠĠĠĠĠĠ Ġassert ( m 1 Ġdoes Not Allow Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 1 Ġallows Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 1 Ġdoes Not Allow ĠĠ 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġm 2 Ġ= ĠMultip licity Constraint ( 0 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 2 Ġallows Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 2 Ġdoes Not Allow ĠĠ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 2 Ġdoes Not Allow ĠĠ 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġm 3 Ġ= ĠMultip licity Constraint ( 1 , Ġtrue , Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 3 Ġdoes Not Allow Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 3 Ġallows Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 3 Ġallows Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 3 Ġallows Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 3 Ġdoes Not Allow Ġ 4 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġm 4 Ġ= ĠMultip licity Constraint ( 1 , Ġfalse , Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 4 Ġdoes Not Allow Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 4 Ġallows Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 4 Ġallows Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 4 Ġallows Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġassert ( m 4 Ġallows Ġ 4 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check ĠPath Constraints Ġwith Ġinput Ġand Ġoutput ĠMultip lic ities ` (){ ĊĊĠĠĠĠĠĠĠ Ġ// Ġtest Ġbounded Ġinput ĠMultip licity Constraint ĊĠĠĠĠĠĠĠ Ġval Ġpath Constraint 1 Ġ= ĠPath Constraint < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , ĠMultip licity Constraint ( 1 , true , Ġ 2 ), ĠMultip licity Constraint ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 1 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 0 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 1 Ġdoes Not Allow Ġ Ġpath 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 2 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 1 Ġallows Ġpath 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 3 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 2 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 1 Ġallows Ġpath 3 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 4 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 3 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 1 Ġdoes Not Allow Ġ Ġpath 4 ) ĊĊĊĠĠĠĠĠĠĠ Ġ// Ġtest Ġun bounded Ġoutput ĠMultip licity Constraint ĊĠĠĠĠĠĠĠ Ġval Ġpath Constraint 2 Ġ= ĠPath Constraint < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , ĠMultip licity Constraint (), ĠMultip licity Constraint ( 1 , false , 0 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 5 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġdoes Not Allow Ġ Ġpath 5 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 6 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġallows Ġpath 6 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 7 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġallows Ġpath 7 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 8 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġallows Ġ Ġpath 8 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check ĠAdditional State Constraint ` (){ ĊĊĠĠĠĠĠĠĠ Ġval Ġasc Ġ= ĠAdditional States Constraint ( Additional States Type . OUTPUT , Test State B :: class . java , ĠMultip licity Constraint ( 1 , Ġfalse )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġtype Ġmatch ĊĠĠĠĠĠĠĠ Ġval Ġas 1 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State B :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( Ġasc Ġis Satisf ied By Ġas 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġas 2 Ġ= ĠAdditional States ( Additional States Type . INPUT , ĠTest State B :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( Ġasc Ġis Not Satisf ied By Ġas 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġas 3 Ġ= ĠAdditional States ( Additional States Type . REFERENCE , ĠTest State B :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert ( Ġasc Ġis Not Satisf ied By Ġas 3 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġstate Ġmatch ĊĠĠĠĠĠĠĠ Ġval Ġas 1 0 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State A :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert Ġ( asc Ġis Not Satisf ied By Ġas 1 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġas 1 1 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State B :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert Ġ( asc Ġis Satisf ied By Ġas 1 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġas 1 2 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State C :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert Ġ( asc Ġis Not Satisf ied By Ġas 1 2 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck ĠMultip licity Constraint Ġmatch ĊĠĠĠĠĠĠĠ Ġval Ġas 2 0 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State B :: class . java , Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġassert Ġ( asc Ġis Not Satisf ied By Ġas 2 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġas 2 1 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State B :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġassert Ġ( asc Ġis Satisf ied By Ġas 2 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġas 2 2 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State B :: class . java , Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġassert Ġ( asc Ġis Satisf ied By Ġas 2 2 ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check ĠPath Constraints Ġwith Ġadditional Ġinput Ġand Ġoutput Ġconstraints ` (){ ĊĊĊĠĠĠĠĠĠĠ Ġval Ġas 1 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State B :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġas 2 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State C :: class . java , Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġas 3 Ġ= ĠAdditional States ( Additional States Type . OUTPUT , ĠTest State D :: class . java , Ġ 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġasc 1 Ġ= ĠAdditional States Constraint ( Additional States Type . OUTPUT , ĠTest State B :: class . java , ĠMultip licity Constraint ( 1 , Ġtrue , Ġ 2 )) ĊĠĠĠĠĠĠĠ Ġval Ġasc 2 Ġ= ĠAdditional States Constraint ( Additional States Type . OUTPUT , ĠTest State C :: class . java , ĠMultip licity Constraint ( 1 , Ġtrue , Ġ 2 )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck ĠPath Constraint Ġwith Ġsingle ĠAdditional States Constraint ĊĠĠĠĠĠĠĠ Ġval Ġpath Constraint 1 Ġ= ĠPath Constraint < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġadditional States Constraints Ġ= Ġset Of ( asc 1 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 1 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 , Ġset Of ( as 1 )) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 1 Ġallows Ġpath 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 2 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 , Ġset Of ( as 2 )) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 1 Ġdoes Not Allow Ġ Ġpath 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 3 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 , Ġset Of ( as 1 , Ġas 2 )) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 1 Ġallows Ġ Ġpath 3 ) ĊĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck ĠPath Constraint Ġwith Ġmultiple ĠAdditional States Constraint ĊĠĠĠĠĠĠĠ Ġval Ġpath Constraint 2 Ġ= ĠPath Constraint < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġadditional States Constraints Ġ= Ġset Of ( asc 1 , Ġasc 2 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 2 1 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 , Ġset Of ( as 1 )) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġdoes Not Allow Ġ Ġpath 2 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 2 2 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 , Ġset Of ( as 2 )) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġdoes Not Allow Ġ Ġpath 2 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 2 3 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 , Ġset Of ( as 1 , Ġas 2 )) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġallows Ġ Ġpath 2 3 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpath 2 4 Ġ= ĠPath < Test State A >( Test Contract . Commands . Command 1 (), ĠTest State A . Test Status . STATUS A 1 , Ġ 1 , Ġ 1 , Ġset Of ( as 1 , Ġas 2 , Ġas 3 )) ĊĠĠĠĠĠĠĠ Ġassert ( path Constraint 2 Ġallows Ġ Ġpath 2 4 ) ĊĠĠĠ Ġ} Ċ }