package Ġio . open future . chain . core . service . transaction Ċ Ċ import Ġio . open future . chain . config . Service Tests Ċ import Ġio . open future . chain . core . model . entity . transaction . confirmed . Transfer Transaction Ċ import Ġio . open future . chain . core . model . entity . transaction . payload . Transfer Transaction Payload Ċ import Ġio . open future . chain . core . repository . Transfer Transaction Repository Ċ import Ġio . open future . chain . core . service . Contract Service Ċ import Ġio . open future . chain . core . service . StateManager Ċ import Ġio . open future . chain . core . service . Transfer Transaction Service Ċ import Ġio . open future . chain . core . service . transaction . confirmed . Default Transfer Transaction Service Ċ import Ġio . open future . chain . smart contract . deploy . calculation . Contract Cost Calculator Ċ import Ġio . open future . chain . smart contract . execution . Contract Executor Ċ import Ġorg . bouncycastle . pq c . math . linear algebra . Byte Utils Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . BDD Mockito .* Ċ import Ġorg . mockito . Mock Ċ import Ġorg . springframework . test . util . Reflection TestUtils Ċ Ċ class ĠDefault Transfer Transaction Service Test Ġ: ĠService Tests () Ġ{ ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġrepository : ĠTransfer Transaction Repository ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcontract Service : ĠContract Service ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcontract Executor : ĠContract Executor ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġcontract Cost Calculator : ĠContract Cost Calculator ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġstate Manager : ĠState Manager ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtransaction Service : ĠTransfer Transaction Service ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtransfer Transaction : ĠTransfer Transaction ĊĊĠĠĠ Ġprivate Ġval Ġdelegate Address Ġ= Ġ" delegate Address " ĊĠĠĠ Ġprivate Ġval Ġsender Address Ġ= Ġ" sender Address " ĊĠĠĠ Ġprivate Ġvar Ġcontract Cost : ĠLong Ġ= Ġ 3 0 L ĊĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġtransaction Service Ġ= ĠDefault Transfer Transaction Service ( repository , Ġcontract Service , Ġcontract Cost Calculator , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontract Executor ) ĊĠĠĠĠĠĠĠ ĠReflection TestUtils . setField ( transaction Service , Ġ" state Manager ", Ġstate Manager , ĠState Manager :: class . java ) ĊĠĠĠĠĠĠĠ Ġval Ġcode Ġ= Ġthis :: class . java . getResource AsStream ("/ classes / Java Contract . class "). read Bytes () ĊĠĠĠĠĠĠĠ Ġval Ġbytecode Ġ= ĠByte Utils . to HexString ( code ) ĊĠĠĠĠĠĠĠ Ġtransfer Transaction Ġ= ĠTransfer Transaction ( 1 2 1 3 2 5 4 5 4 , Ġ 0 , Ġsender Address , Ġ"", Ġ"", Ġ"", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTransfer Transaction Payload ( 0 , Ġnull , Ġbytecode )) ĊĊĠĠĠĠĠĠĠ Ġgiven ( contract Cost Calculator . calculate Cost ( code )). willReturn ( contract Cost ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġprocess When Fee IsNot En ough Should Return Error Result Receipt () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsend Fee Ġ= Ġ 1 0 L ĊĠĠĠĠĠĠĠ Ġval Ġexpected Size Ġ= Ġ 1 ĊĠĠĠĠĠĠĠ Ġval Ġexpected Error Ġ= Ġ" Contract Ġis Ġnot Ġdeployed . ĠThe Ġfee Ġwas Ġchar ged , Ġbut Ġthis Ġis Ġnot Ġenough Ġfor Ġdeploy ." ĊĠĠĠĠĠĠĠ Ġtransfer Transaction . fee Ġ= Ġsend Fee ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġtransaction Service . process ( transfer Transaction , Ġdelegate Address ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Size , Ġresult . get Results (). size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Error , Ġresult . get Results (). first (). error ) ĊĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Wallet Balance By Address ( sender Address , Ġ- send Fee ) ĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Wallet Balance By Address ( delegate Address , Ġsend Fee ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġprocess When Fee Is GreaterThan Contract Cost Should Return Two Result Receipt () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsend Fee Ġ= Ġ 4 0 L ĊĠĠĠĠĠĠĠ Ġval Ġexpected Size Ġ= Ġ 2 ĊĠĠĠĠĠĠĠ Ġval Ġexpected Delivery Ġ= Ġsend Fee Ġ- Ġcontract Cost ĊĠĠĠĠĠĠĠ Ġtransfer Transaction . fee Ġ= Ġsend Fee ĊĊĠĠĠĠĠĠĠ Ġgiven ( contract Service . generate Address ( sender Address )). willReturn ( sender Address ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġtransaction Service . process ( transfer Transaction , Ġdelegate Address ) ĊĠĠĠĠĠĠĠ Ġval Ġactual Sender Receipt Result Ġ= Ġresult . get Results (). find Ġ{ Ġit . from Ġ== Ġsender Address Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġactual Delegate Receipt Result Ġ= Ġresult . get Results (). find Ġ{ Ġit . from Ġ== Ġdelegate Address Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Size , Ġresult . get Results (). size ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( delegate Address , Ġactual Sender Receipt Result ?. to ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( send Fee , Ġactual Sender Receipt Result ?. amount ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( actual Sender Receipt Result ?. error . isNull Or Blank ()) ĊĠĠĠĠĠĠĠ ĠassertTrue ( actual Sender Receipt Result ?. data !!. isNotEmpty ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( sender Address , Ġactual Delegate Receipt Result ?. to ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Delivery , Ġactual Delegate Receipt Result ?. amount ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( actual Delegate Receipt Result ?. error . isNull Or Blank ()) ĊĠĠĠĠĠĠĠ ĠassertTrue ( actual Delegate Receipt Result ?. data . isNull Or Blank ()) ĊĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Smart Contract Storage ( any String (), Ġany String ()) ĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Wallet Balance By Address ( sender Address , Ġ- contract Cost ) ĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Wallet Balance By Address ( delegate Address , Ġcontract Cost ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġprocess When Fee Is Equal Contract Cost Should Return One Result Receipt () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsend Fee Ġ= Ġ 3 0 L ĊĠĠĠĠĠĠĠ Ġval Ġexpected Size Ġ= Ġ 1 ĊĠĠĠĠĠĠĠ Ġtransfer Transaction . fee Ġ= Ġsend Fee ĊĊĠĠĠĠĠĠĠ Ġgiven ( contract Service . generate Address ( sender Address )). willReturn ( sender Address ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġtransaction Service . process ( transfer Transaction , Ġdelegate Address ) ĊĠĠĠĠĠĠĠ Ġval Ġactual Receipt Result Ġ= Ġresult . get Results (). first () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Size , Ġresult . get Results (). size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( sender Address , Ġactual Receipt Result . from ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( delegate Address , Ġactual Receipt Result . to ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( send Fee , Ġactual Receipt Result . amount ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( actual Receipt Result . error . isNull Or Blank ()) ĊĠĠĠĠĠĠĠ ĠassertTrue ( actual Receipt Result . data !!. isNotEmpty ()) ĊĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Smart Contract Storage ( any String (), Ġany String ()) ĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Wallet Balance By Address ( sender Address , Ġ- contract Cost ) ĊĠĠĠĠĠĠĠ Ġverify ( state Manager ). update Wallet Balance By Address ( delegate Address , Ġcontract Cost ) ĊĠĠĠ Ġ} Ċ Ċ }