package Ġorg . ke thereum . rpc Ċ Ċ import Ġokhttp 3 . mock webserver . Mock Response Ċ import Ġokhttp 3 . mock webserver . Mock WebServer Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . ke thereum . extensions . hex To BigInteger Ċ import Ġorg . ke thereum . model . Address Ċ import Ġorg . ke thereum . rpc . model . Block Information Ċ import Ġorg . w alle th . k hex . hex To ByteArray Ċ import Ġjava . math . BigInteger Ċ Ċ class ĠThe E thereum RPC Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġserver Ġ= ĠMock WebServer () ĊĠĠĠ Ġprivate Ġval Ġtested Ġby Ġlazy Ġ{ ĠEthereum RPC ( base URL Ġ= Ġserver . url (" "). toString ()) Ġ} ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġrun Before Every Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġserver . start () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġrun After Every Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġserver . shutdown () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Balance Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// language = JSON ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġ"{\" jsonrpc \":\" 2 . 0 \",\" id \": 8 3 ,\" result \":\" 0 x 0 2 3 4 c 8 a 3 3 9 7 aab 5 8 \" }\ n " ĊĠĠĠĠĠĠĠ Ġserver . enqueue ( Mock Response (). set Body ( response )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( tested . get Balance ( Address (" 0 x 0 "), " latest ") ?. result ). isEqualTo (" 0 x 0 2 3 4 c 8 a 3 3 9 7 aab 5 8 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsend Tx Error Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// language = JSON ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġ"{\" jsonrpc \":\" 2 . 0 \",\" error \":{\" code \": - 3 2 0 1 0 ,\" message \":\" Transaction Ġwith Ġthe Ġsame Ġhash Ġwas Ġalready Ġimported .\" }, \" id \": 1 ,\" in 3 \":{\" last Validator Change \": 6 8 5 9 3 ,\" last NodeList \": 2 1 9 8 8 ,\" exec Time \": 7 6 }}\ n " ĊĠĠĠĠĠĠĠ Ġserver . enqueue ( Mock Response (). set Body ( response )) ĊĊĠĠĠĠĠĠĠ Ġval Ġsend Raw Transaction Ġ= Ġtested . send Raw Transaction (" 0 x 0 ") ĊĠĠĠĠĠĠĠ ĠassertThat ( send Raw Transaction ?. error ?. message ). isEqualTo (" Transaction Ġwith Ġthe Ġsame Ġhash Ġwas Ġalready Ġimported .") ĊĠĠĠĠĠĠĠ ĠassertThat ( send Raw Transaction ?. error ?. code ). isEqualTo (- 3 2 0 1 0 ) ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsend Raw Transaction Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// language = JSON ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġ"{\" jsonrpc \":\" 2 . 0 \",\" id \": 8 3 ,\" result \":\" 0 xe 6 7 0 ec 6 4 3 4 1 7 7 1 6 0 6 e 5 5 d 6 b 4 ca 3 5 a 1 a 6 b 7 5 ee 3 d 5 1 4 5 a 9 9 d 0 5 9 2 1 0 2 6 d 1 5 2 7 3 3 1 \" }\ n " ĊĠĠĠĠĠĠĠ Ġserver . enqueue ( Mock Response (). set Body ( response )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( tested . send Raw Transaction (" 0 x 0 0 ") ?. result ). isEqualTo (" 0 xe 6 7 0 ec 6 4 3 4 1 7 7 1 6 0 6 e 5 5 d 6 b 4 ca 3 5 a 1 a 6 b 7 5 ee 3 d 5 1 4 5 a 9 9 d 0 5 9 2 1 0 2 6 d 1 5 2 7 3 3 1 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Block Number Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// language = JSON ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġ"{\" jsonrpc \":\" 2 . 0 \",\" id \": 8 3 ,\" result \":\" 0 x 4 2 9 9 d \" }\ n " ĊĠĠĠĠĠĠĠ Ġserver . enqueue ( Mock Response (). set Body ( response )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( tested . block Number ()?. result ). isEqualTo (" 0 x 4 2 9 9 d ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Block By Number Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// language = JSON ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġ""" {" jsonrpc ": Ġ" 2 . 0 ", ĊĠ Ġ" id ": Ġ 2 , ĊĠ Ġ" result ": Ġ{ ĊĠĠĠ Ġ" difficulty ": Ġ" 0 x 6 cea 8 0 1 8 7 1 8 ", ĊĠĠĠ Ġ" extra Data ": Ġ" 0 xd 7 8 3 0 1 0 1 0 0 8 4 4 7 6 5 7 4 6 8 8 7 6 7 6 f 3 1 2 e 3 4 2 e 3 2 8 5 6 c 6 9 6 e 7 5 7 8 ", ĊĠĠĠ Ġ" gas Limit ": Ġ" 0 x 2 fe fd 8 ", ĊĠĠĠ Ġ" gas Used ": Ġ" 0 x 5 2 0 8 ", ĊĠĠĠ Ġ" hash ": Ġ" 0 x 3 a 7 2 d 7 6 9 1 cd 7 2 0 cbb 4 ff fb 8 1 4 5 0 4 4 d 3 ff 5 b 3 c 2 4 ef 0 2 aff af 0 9 d 8 8 d 0 b 6 2 c 6 ba 1 a ", ĊĠĠĠ Ġ" logs B loom ": Ġ" 0 x 0 0 0 0 0 0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x 1 c ", ĊĠĠĠĠĠĠĠ Ġ" r ": Ġ" 0 xd cd 1 8 3 c 3 4 a 1 ceb 7 9 3 4 b 7 fb 3 2 f 3 1 6 9 b 8 f 3 fff 4 3 da 9 3 6 5 5 3 e 4 d 9 2 ae 9 7 bb 0 a 9 a 7 6 5 ", ĊĠĠĠĠĠĠĠ Ġ" s ": Ġ" 0 x 7 6 d 4 be 3 d 6 2 b 9 e 6 e 6 bb 8 c 4 9 4 c 3 2 2 8 f 4 df 3 1 b 5 c 2 0 d 8 f 8 9 2 fe 1 d 9 d 3 5 f 0 7 af ab 3 d 7 3 " ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ], ĊĠĠĠ Ġ" transactions Root ": Ġ" 0 x 7 ab 6 6 8 0 c 6 d 2 fb 2 1 c 3 ce 5 aa ff 8 1 4 3 2 d 3 7 7 c 2 a 1 0 ed 4 a 1 dbf 6 1 4 c 0 4 c 2 2 4 c 3 4 b 5 bfc ", ĊĠĠĠ Ġ" unc les ": Ġ[ ĊĠĠĠĠĠ Ġ" 0 x 5 f 1 9 7 2 f 7 9 8 9 6 4 8 9 5 bf 2 9 c 8 2 bd 6 d 1 1 1 7 5 5 3 d 4 2 2 2 d 6 0 9 d 0 7 a 8 3 2 1 ea ade cf 4 4 0 f 1 2 "] }} """ ĊĠĠĠĠĠĠĠ Ġserver . enqueue ( Mock Response (). set Body ( response )) ĊĊĠĠĠĠĠĠĠ Ġval Ġblock By Number : ĠBlock Information ? Ġ= Ġtested . getBlock By Number (" 0 x 1 2 3 4 ") ĊĠĠĠĠĠĠĠ ĠassertThat ( block By Number ). isNotNull ĊĠĠĠĠĠĠĠ ĠassertThat ( block By Number !!. transactions . size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġfirst Signed Transaction Ġ= Ġblock By Number . transactions . first () ĊĠĠĠĠĠĠĠ Ġval Ġfirst Transaction Ġ= Ġfirst Signed Transaction . transaction ĊĠĠĠĠĠĠĠ Ġval Ġfirst Signature Ġ= Ġfirst Signed Transaction . signature Data ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . from ). isEqualTo ( Address (" 0 x 8 6 7 a 5 2 2 1 5 6 4 1 6 0 c 1 2 8 f 2 b 0 ec 6 b 2 2 2 1 6 c 3 8 0 ddc 7 6 ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . gas Limit ). isEqualTo (" 0 x 5 2 0 8 ". hex To BigInteger ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . gas Price ). isEqualTo (" 0 xd 4 fc 4 7 cf 6 ". hex To BigInteger ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . tx Hash ). isEqualTo (" 0 xce eb def 5 9 ab 3 cd de 1 5 2 6 7 2 0 1 4 b 4 5 1 f 7 5 bb 7 9 7 4 b 9 dca 4 b 3 0 e 5 4 5 b 6 8 6 4 d 9 ff ca 9 d ") ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . input ). isEqualTo (" 0 x ". hex To ByteArray (). toList ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . nonce ). isEqualTo ( BigInteger . valueOf ( 1 6 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . to ). isEqualTo ( Address (" 0 x 3 2 be 3 4 3 b 9 4 f 8 6 0 1 2 4 dc 4 fee 2 7 8 fd cbd 3 8 c 1 0 2 d 8 8 ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( first Transaction . value ). isEqualTo (" 0 x 5 9 6 c 9 0 f 0 9 f 5 4 7 4 0 0 ". hex To BigInteger ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( first Signature . v ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEqualTo (" 0 x 1 c ". hex To BigInteger (). to Byte ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( first Signature . r ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEqualTo (" 0 xd cd 1 8 3 c 3 4 a 1 ceb 7 9 3 4 b 7 fb 3 2 f 3 1 6 9 b 8 f 3 fff 4 3 da 9 3 6 5 5 3 e 4 d 9 2 ae 9 7 bb 0 a 9 a 7 6 5 ". hex To BigInteger ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( first Signature . s ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. isEqualTo (" 0 x 7 6 d 4 be 3 d 6 2 b 9 e 6 e 6 bb 8 c 4 9 4 c 3 2 2 8 f 4 df 3 1 b 5 c 2 0 d 8 f 8 9 2 fe 1 d 9 d 3 5 f 0 7 af ab 3 d 7 3 ". hex To BigInteger ()) ĊĠĠĠ Ġ} ĊĊ Ċ }