package Ġio . open future . api . component . web 3 Ċ Ċ import Ġio . open future . api . config . UnitTest Ċ import Ġio . open future . api . config . any Ċ import Ġio . open future . api . config . any String Ċ import Ġio . open future . api . config . pro pe ty . E thereum Properties Ċ import Ġio . open future . api . exception . Execute Transaction Exception Ċ import Ġio . open future . api . exception . Function Call Exception Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . BDD Mockito . given Ċ import Ġorg . mockito . Mock Ċ import Ġorg . web 3 j . abi . Type Reference Ċ import Ġorg . web 3 j . abi . datat ypes . generated . Uint 2 5 6 Ċ import Ġorg . web 3 j . crypto . Credentials Ċ import Ġorg . web 3 j . crypto . EC KeyPair Ċ import Ġorg . web 3 j . protocol . Web 3 j Ċ import Ġorg . web 3 j . protocol . core . Default Block Parameter Ċ import Ġorg . web 3 j . protocol . core . Default Block ParameterName . LATE ST Ċ import Ġorg . web 3 j . protocol . core . Request Ċ import Ġorg . web 3 j . protocol . core . Response Ċ import Ġorg . web 3 j . protocol . core . methods . request . Transaction Ċ import Ġorg . web 3 j . protocol . core . methods . response .* Ċ import Ġjava . math . BigInteger Ċ import Ġjava . util .* Ċ Ċ internal Ġclass ĠWeb 3 Wrapper Tests Ġ: ĠUnit Test () Ġ{ ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġweb 3 j : ĠWeb 3 j ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġproperties : ĠEthereum Properties ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcall : ĠE th Call ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġerror : ĠResponse . Error ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcall Request : ĠRequest < Transaction , ĠE th Call > ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġnet Version Request : ĠRequest < String , ĠNet Version > ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġtransaction Request : ĠRequest < String , ĠE th Send Transaction > ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġtransaction Count Request : ĠRequest < String , ĠE th Get Transaction Count > ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġtransaction Receipt Request : ĠRequest < String , ĠE th Get Transaction Receipt > ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġnet Version : ĠNet Version ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġtransaction : ĠE th Send Transaction ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġtransaction Count : ĠE th Get Transaction Count ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġtransaction Receipt : ĠE th Get Transaction Receipt ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcredentials : ĠCredentials ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġweb 3 Wrapper : ĠWeb 3 Wrapper ĊĊĠĠĠ Ġprivate Ġval Ġaddress Value Ġ= Ġ" 0 xba 3 7 1 6 3 6 2 5 b 3 f 2 e 9 6 1 1 2 5 6 2 8 5 8 c 1 2 b 7 5 9 6 3 af 1 3 8 " ĊĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġweb 3 Wrapper Ġ= ĠWeb 3 Wrapper ( web 3 j , Ġproperties ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdeploy Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġoptional Transaction Receipt Ġ= ĠOptional . of ( Transaction Receipt (). apply Ġ{ Ġcontract Address Ġ= Ġaddress Value Ġ}) ĊĊĠĠĠĠĠĠĠ Ġgiven ( properties . get Credentials ()). willReturn ( credentials ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . address ). willReturn ( address Value ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Count ( address Value , ĠL ATE ST )). willReturn ( transaction Count Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count Request . send ()). willReturn ( transaction Count ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count . transaction Count ). willReturn ( BigInteger . ZERO ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Send Raw Transaction ( any String ())). willReturn ( transaction Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . ec KeyPair ). willReturn ( create EC KeyPair ()) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count . transaction Count ). willReturn ( BigInteger . ZERO ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Request . send ()). willReturn ( transaction ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction . transaction Hash ). willReturn (" hash ") ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Receipt ( transaction . transaction Hash )). willReturn ( transaction Receipt Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Receipt Request . send ()). willReturn ( transaction Receipt ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Receipt . transaction Receipt ). willReturn ( optional Transaction Receipt ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Address Ġ= Ġweb 3 Wrapper . deploy (" data ", ĠlistOf ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual Address ). isNotEmpty () ĊĠĠĠĠĠĠĠ ĠassertThat ( actual Address ). isEqualTo Ign oring Case ( address Value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠExecute Transaction Exception :: class ) ĊĠĠĠ Ġfun Ġdeploy When Transaction Error Should Throw Exception Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( properties . get Credentials ()). willReturn ( credentials ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . address ). willReturn ( address Value ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . ec KeyPair ). willReturn ( create EC KeyPair ()) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Count ( address Value , ĠL ATE ST )). willReturn ( transaction Count Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count Request . send ()). willReturn ( transaction Count ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count . transaction Count ). willReturn ( BigInteger . ZERO ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Send Raw Transaction ( any String ())). willReturn ( transaction Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Request . send ()). willReturn ( transaction ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction . has Error ()). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction . error ). willReturn ( error ) ĊĠĠĠĠĠĠĠ Ġgiven ( error . message ). willReturn (" error ") ĊĊĠĠĠĠĠĠĠ Ġweb 3 Wrapper . deploy (" data " Ġ, listOf ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcall Function Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( properties . get Credentials ()). willReturn ( credentials ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . address ). willReturn ( address Value ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Count ( address Value , ĠL ATE ST )). willReturn ( transaction Count Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count Request . send ()). willReturn ( transaction Count ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count . transaction Count ). willReturn ( BigInteger . ZERO ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Call ( any ( Transaction :: class . java ), Ġany ( Default Block Parameter :: class . java ))). willReturn ( call Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( call Request . send ()). willReturn ( call ) ĊĠĠĠĠĠĠĠ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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 """) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Result Ġ= Ġweb 3 Wrapper . call Function (" get Share Holder Count ", ĠlistOf (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( object Ġ: ĠType Reference < Uint 2 5 6 >() Ġ{}), Ġaddress Value ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual Result ). isNotEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠFunction Call Exception :: class ) ĊĠĠĠ Ġfun Ġcall Function When Call Error Should Throw Exception Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( properties . get Credentials ()). willReturn ( credentials ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . address ). willReturn ( address Value ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Count ( address Value , ĠL ATE ST )). willReturn ( transaction Count Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count Request . send ()). willReturn ( transaction Count ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count . transaction Count ). willReturn ( BigInteger . ZERO ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Call ( any ( Transaction :: class . java ), Ġany ( Default Block Parameter :: class . java ))). willReturn ( call Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( call Request . send ()). willReturn ( call ) ĊĠĠĠĠĠĠĠ Ġgiven ( call . has Error ()). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven ( call . error ). willReturn ( error ) ĊĠĠĠĠĠĠĠ Ġgiven ( error . message ). willReturn (" error ") ĊĊĠĠĠĠĠĠĠ Ġweb 3 Wrapper . call Function (" get Share Holder Count ", ĠlistOf (), ĠlistOf ( object Ġ: ĠType Reference < Uint 2 5 6 >() Ġ{}), Ġaddress Value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcall Transaction Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġoptional Transaction Receipt Ġ= ĠOptional . of ( Transaction Receipt (). apply Ġ{ Ġtransaction Hash Ġ= Ġ" hash " Ġ}) ĊĊĠĠĠĠĠĠĠ Ġgiven ( properties . get Credentials ()). willReturn ( credentials ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . address ). willReturn ( address Value ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . ec KeyPair ). willReturn ( create EC KeyPair ()) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Count ( address Value , ĠL ATE ST )). willReturn ( transaction Count Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count Request . send ()). willReturn ( transaction Count ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count . transaction Count ). willReturn ( BigInteger . ZERO ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Send Raw Transaction ( any String ())). willReturn ( transaction Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Receipt ( any String ())). willReturn ( transaction Receipt Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Receipt Request . send ()). willReturn ( transaction Receipt ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Request . send ()). willReturn ( transaction ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction . transaction Hash ). willReturn (" hash ") ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Receipt . transaction Receipt ). willReturn ( optional Transaction Receipt ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Transactional Hash Ġ= Ġweb 3 Wrapper . call Transaction (" deactivate ", ĠlistOf (), ĠlistOf (), Ġaddress Value ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual Transactional Hash ). isNotEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠExecute Transaction Exception :: class ) ĊĠĠĠ Ġfun Ġcall Transaction When Transaction Error Should Throw Exception Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( properties . get Credentials ()). willReturn ( credentials ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . address ). willReturn ( address Value ) ĊĠĠĠĠĠĠĠ Ġgiven ( credentials . ec KeyPair ). willReturn ( create EC KeyPair ()) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Get Transaction Count ( address Value , ĠL ATE ST )). willReturn ( transaction Count Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count Request . send ()). willReturn ( transaction Count ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Count . transaction Count ). willReturn ( BigInteger . ZERO ) ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . eth Send Raw Transaction ( any String ())). willReturn ( transaction Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction Request . send ()). willReturn ( transaction ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction . has Error ()). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven ( transaction . error ). willReturn ( error ) ĊĠĠĠĠĠĠĠ Ġgiven ( error . message ). willReturn (" error ") ĊĊĠĠĠĠĠĠĠ Ġweb 3 Wrapper . call Transaction (" deactivate ", ĠlistOf (), ĠlistOf (), Ġaddress Value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Net Version Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġversion Ġ= Ġ" version " ĊĠĠĠĠĠĠĠ Ġgiven ( web 3 j . net Version ()). willReturn ( net Version Request ) ĊĠĠĠĠĠĠĠ Ġgiven ( net Version Request . send ()). willReturn ( net Version ) ĊĠĠĠĠĠĠĠ Ġgiven ( net Version . net Version ). willReturn ( version ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Version Ġ= Ġweb 3 Wrapper . get Net Version () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual Version ). isEqualTo ( version ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate EC KeyPair (): ĠEC KeyPair Ġ= ĠEC KeyPair ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBigInteger (" 7 0 4 3 4 8 7 4 8 2 0 5 6 1 1 6 7 8 3 3 4 1 3 3 1 4 4 6 5 7 1 7 8 2 1 9 1 2 0 3 2 2 2 4 5 5 9 3 0 3 5 1 7 6 0 2 6 5 6 9 3 5 3 2 9 3 8 9 1 1 4 2 5 0 3 0 3 "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBigInteger (" 8 5 5 2 7 8 7 8 6 7 5 7 7 6 9 1 4 7 8 4 8 4 5 5 1 0 5 8 7 0 2 8 2 1 3 9 0 0 3 8 4 5 2 3 9 6 9 4 1 5 2 3 6 8 8 4 0 7 3 8 1 3 6 2 3 1 3 1 9 8 3 9 6 8 9 6 3 3 6 4 1 4 4 6 9 4 1 6 " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" 9 1 3 6 5 0 1 0 7 9 2 5 3 2 3 4 4 5 5 2 3 5 4 2 0 3 8 8 3 6 9 7 7 1 1 1 4 1 6 6 2 5 5 9 7 6 5 8 4 3 0 9 1 4 9 4 4 2 6 1 3 5 5 5 7 6 ")) Ċ Ċ }