package Ġnet . cord a . core . node Ċ Ċ import Ġnet . cord a . core . contracts .* Ċ import Ġnet . cord a . core . crypto . Composite Key Ċ import Ġnet . cord a . core . crypto . Secure Hash Ċ import Ġnet . cord a . core . node . services . Vault Ċ import Ġnet . cord a . core . utilities . D UMMY _ NOT ARY Ċ import Ġorg . junit . Test Ċ import Ġkotlin . test . assertEquals ĊĊ Ċ class ĠVault Update Tests Ġ{ ĊĊĠĠĠ Ġobject ĠDummy Contract Ġ: ĠContract Ġ{ ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġverify ( tx : ĠTransaction For Contract ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġlegal Contract Reference : ĠSecure Hash Ġ= ĠSecure Hash . sha 2 5 6 ("") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠDummy State Ġ: ĠContract State Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġparticipants : ĠList < Composite Key > ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget () Ġ= Ġempty List () ĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġcontract Ġ= ĠVault Update Tests . Dummy Contract ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġstate Ref 0 Ġ= ĠState Ref ( Secure Hash . random SHA 2 5 6 (), Ġ 0 ) ĊĠĠĠ Ġprivate Ġval Ġstate Ref 1 Ġ= ĠState Ref ( Secure Hash . random SHA 2 5 6 (), Ġ 1 ) ĊĠĠĠ Ġprivate Ġval Ġstate Ref 2 Ġ= ĠState Ref ( Secure Hash . random SHA 2 5 6 (), Ġ 2 ) ĊĠĠĠ Ġprivate Ġval Ġstate Ref 3 Ġ= ĠState Ref ( Secure Hash . random SHA 2 5 6 (), Ġ 3 ) ĊĠĠĠ Ġprivate Ġval Ġstate Ref 4 Ġ= ĠState Ref ( Secure Hash . random SHA 2 5 6 (), Ġ 4 ) ĊĊĠĠĠ Ġprivate Ġval Ġstate And Ref 0 Ġ= ĠState And Ref ( Transaction State ( Dummy State (), ĠD UMMY _ NOT ARY ), Ġstate Ref 0 ) ĊĠĠĠ Ġprivate Ġval Ġstate And Ref 1 Ġ= ĠState And Ref ( Transaction State ( Dummy State (), ĠD UMMY _ NOT ARY ), Ġstate Ref 1 ) ĊĠĠĠ Ġprivate Ġval Ġstate And Ref 2 Ġ= ĠState And Ref ( Transaction State ( Dummy State (), ĠD UMMY _ NOT ARY ), Ġstate Ref 2 ) ĊĠĠĠ Ġprivate Ġval Ġstate And Ref 3 Ġ= ĠState And Ref ( Transaction State ( Dummy State (), ĠD UMMY _ NOT ARY ), Ġstate Ref 3 ) ĊĠĠĠ Ġprivate Ġval Ġstate And Ref 4 Ġ= ĠState And Ref ( Transaction State ( Dummy State (), ĠD UMMY _ NOT ARY ), Ġstate Ref 4 ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` nothing Ġplus Ġnothing Ġis Ġnothing `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbefore Ġ= ĠVault . No Update ĊĠĠĠĠĠĠĠ Ġval Ġafter Ġ= Ġbefore Ġ+ ĠVault . No Update ĊĠĠĠĠĠĠĠ ĠassertEquals ( before , Ġafter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` something Ġplus Ġnothing Ġis Ġsomething `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbefore Ġ= ĠVault . Update ( set Of ( state And Ref 0 , Ġstate And Ref 1 ), Ġset Of ( state And Ref 2 , Ġstate And Ref 3 )) ĊĠĠĠĠĠĠĠ Ġval Ġafter Ġ= Ġbefore Ġ+ ĠVault . No Update ĊĠĠĠĠĠĠĠ ĠassertEquals ( before , Ġafter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` nothing Ġplus Ġsomething Ġis Ġsomething `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbefore Ġ= ĠVault . No Update ĊĠĠĠĠĠĠĠ Ġval Ġafter Ġ= Ġbefore Ġ+ ĠVault . Update ( set Of ( state And Ref 0 , Ġstate And Ref 1 ), Ġset Of ( state And Ref 2 , Ġstate And Ref 3 )) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠVault . Update ( set Of ( state And Ref 0 , Ġstate And Ref 1 ), Ġset Of ( state And Ref 2 , Ġstate And Ref 3 )) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected , Ġafter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` something Ġplus Ġconsume Ġstate Ġ 0 Ġis Ġsomething Ġwithout Ġstate Ġ 0 Ġoutput `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbefore Ġ= ĠVault . Update ( set Of ( state And Ref 2 , Ġstate And Ref 3 ), Ġset Of ( state And Ref 0 , Ġstate And Ref 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġafter Ġ= Ġbefore Ġ+ ĠVault . Update ( set Of ( state And Ref 0 ), Ġset Of ()) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠVault . Update ( set Of ( state And Ref 2 , Ġstate And Ref 3 ), Ġset Of ( state And Ref 1 )) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected , Ġafter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` something Ġplus Ġproduce Ġstate Ġ 4 Ġis Ġsomething Ġwith Ġadditional Ġstate Ġ 4 Ġoutput `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbefore Ġ= ĠVault . Update ( set Of ( state And Ref 2 , Ġstate And Ref 3 ), Ġset Of ( state And Ref 0 , Ġstate And Ref 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġafter Ġ= Ġbefore Ġ+ ĠVault . Update ( set Of (), Ġset Of ( state And Ref 4 )) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠVault . Update ( set Of ( state And Ref 2 , Ġstate And Ref 3 ), Ġset Of ( state And Ref 0 , Ġstate And Ref 1 , Ġstate And Ref 4 )) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected , Ġafter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` something Ġplus Ġconsume Ġstates Ġ 0 Ġand Ġ 1 , Ġand Ġproduce Ġstate Ġ 4 , Ġis Ġsomething Ġwithout Ġstate Ġ 0 Ġand Ġ 1 Ġoutputs Ġand Ġonly Ġstate Ġ 4 Ġoutput `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbefore Ġ= ĠVault . Update ( set Of ( state And Ref 2 , Ġstate And Ref 3 ), Ġset Of ( state And Ref 0 , Ġstate And Ref 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġafter Ġ= Ġbefore Ġ+ ĠVault . Update ( set Of ( state And Ref 0 , Ġstate And Ref 1 ), Ġset Of ( state And Ref 4 )) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠVault . Update ( set Of ( state And Ref 2 , Ġstate And Ref 3 ), Ġset Of ( state And Ref 4 )) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected , Ġafter ) ĊĠĠĠ Ġ} Ċ } Ċ