Skip to content

Commit

Permalink
[ETCM-980] restore json OptionNoneToNullSerializer (#1071)
Browse files Browse the repository at this point in the history
This reverts commit 357bc89 regarding OptionNoneToNullSerializer.
  • Loading branch information
strauss-m committed Jul 23, 2021
1 parent 3ddb68a commit 3f6b82f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
Expand Up @@ -7,6 +7,7 @@ import org.json4s.CustomSerializer
import org.json4s.DefaultFormats
import org.json4s.Extraction
import org.json4s.Formats
import org.json4s.JNull
import org.json4s.JString

import io.iohk.ethereum.domain.Address
Expand All @@ -15,7 +16,8 @@ import io.iohk.ethereum.testmode.EthTransactionResponse

object JsonSerializers {
implicit val formats: Formats =
DefaultFormats + UnformattedDataJsonSerializer + QuantitiesSerializer + AddressJsonSerializer + EthTransactionResponseSerializer
DefaultFormats + UnformattedDataJsonSerializer + QuantitiesSerializer +
OptionNoneToJNullSerializer + AddressJsonSerializer + EthTransactionResponseSerializer

object UnformattedDataJsonSerializer
extends CustomSerializer[ByteString](_ =>
Expand All @@ -38,6 +40,14 @@ object JsonSerializers {
)
)

object OptionNoneToJNullSerializer
extends CustomSerializer[Option[_]](formats =>
(
PartialFunction.empty,
{ case None => JNull }
)
)

object AddressJsonSerializer
extends CustomSerializer[Address](_ =>
(
Expand Down
Expand Up @@ -8,7 +8,9 @@ import monix.eval.Task
import monix.execution.Scheduler.Implicits.global

import org.bouncycastle.util.encoders.Hex
import org.json4s.DefaultFormats
import org.json4s.Extraction
import org.json4s.Formats
import org.json4s.JsonAST._
import org.json4s.JsonDSL._
import org.scalatest.concurrent.Eventually
Expand All @@ -27,6 +29,9 @@ import io.iohk.ethereum.jsonrpc.EthTxService._
import io.iohk.ethereum.jsonrpc.EthUserService._
import io.iohk.ethereum.jsonrpc.FilterManager.TxLog
import io.iohk.ethereum.jsonrpc.PersonalService._
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.OptionNoneToJNullSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.QuantitiesSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.UnformattedDataJsonSerializer
import io.iohk.ethereum.transactions.PendingTransactionsManager.PendingTransaction

// scalastyle:off magic.number
Expand All @@ -41,6 +46,9 @@ class JsonRpcControllerEthLegacyTransactionSpec
with LongPatience
with Eventually {

implicit val formats: Formats = DefaultFormats.preservingEmptyValues + OptionNoneToJNullSerializer +
QuantitiesSerializer + UnformattedDataJsonSerializer

it should "handle eth_getTransactionByBlockHashAndIndex request" in new JsonRpcControllerFixture {
val blockToRequest = Block(Fixtures.Blocks.Block3125369.header, Fixtures.Blocks.Block3125369.body)
val txIndexToRequest = blockToRequest.body.transactionList.size / 2
Expand Down
Expand Up @@ -8,7 +8,9 @@ import monix.eval.Task
import monix.execution.Scheduler.Implicits.global

import org.bouncycastle.util.encoders.Hex
import org.json4s.DefaultFormats
import org.json4s.Extraction
import org.json4s.Formats
import org.json4s.JsonAST._
import org.json4s.JsonDSL._
import org.scalatest.concurrent.Eventually
Expand Down Expand Up @@ -38,6 +40,9 @@ import io.iohk.ethereum.jsonrpc.ProofService.GetProofResponse
import io.iohk.ethereum.jsonrpc.ProofService.ProofAccount
import io.iohk.ethereum.jsonrpc.ProofService.StorageProofKey
import io.iohk.ethereum.jsonrpc.ProofService.StorageValueProof
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.OptionNoneToJNullSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.QuantitiesSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.UnformattedDataJsonSerializer
import io.iohk.ethereum.ledger.InMemoryWorldStateProxy
import io.iohk.ethereum.ommers.OmmersPool
import io.iohk.ethereum.ommers.OmmersPool.Ommers
Expand All @@ -56,6 +61,9 @@ class JsonRpcControllerEthSpec
with LongPatience
with Eventually {

implicit val formats: Formats = DefaultFormats.preservingEmptyValues + OptionNoneToJNullSerializer +
QuantitiesSerializer + UnformattedDataJsonSerializer

it should "eth_protocolVersion" in new JsonRpcControllerFixture {
val rpcRequest = newJsonRpcRequest("eth_protocolVersion")
val response = jsonRpcController.handleRequest(rpcRequest).runSyncUnsafe()
Expand Down
Expand Up @@ -10,6 +10,8 @@ import monix.eval.Task
import monix.execution.Scheduler.Implicits.global

import org.bouncycastle.util.encoders.Hex
import org.json4s.DefaultFormats
import org.json4s.Formats
import org.json4s.JsonAST._
import org.json4s.JsonDSL._
import org.scalatest.concurrent.Eventually
Expand All @@ -22,6 +24,9 @@ import io.iohk.ethereum.LongPatience
import io.iohk.ethereum.WithActorSystemShutDown
import io.iohk.ethereum.domain._
import io.iohk.ethereum.jsonrpc.PersonalService._
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.OptionNoneToJNullSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.QuantitiesSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.UnformattedDataJsonSerializer

class JsonRpcControllerPersonalSpec
extends TestKit(ActorSystem("JsonRpcControllerPersonalSpec_System"))
Expand All @@ -34,6 +39,9 @@ class JsonRpcControllerPersonalSpec
with LongPatience
with Eventually {

implicit val formats: Formats = DefaultFormats.preservingEmptyValues + OptionNoneToJNullSerializer +
QuantitiesSerializer + UnformattedDataJsonSerializer

it should "personal_importRawKey" in new JsonRpcControllerFixture {
val key = "7a44789ed3cd85861c0bbf9693c7e1de1862dd4396c390147ecf1275099c6e6f"
val keyBytes = ByteString(Hex.decode(key))
Expand Down
Expand Up @@ -8,6 +8,8 @@ import monix.execution.Scheduler.Implicits.global

import scala.concurrent.duration._

import org.json4s.DefaultFormats
import org.json4s.Formats
import org.json4s.JArray
import org.json4s.JObject
import org.json4s.JString
Expand All @@ -26,6 +28,9 @@ import io.iohk.ethereum.jsonrpc.DebugService.ListPeersInfoResponse
import io.iohk.ethereum.jsonrpc.NetService.ListeningResponse
import io.iohk.ethereum.jsonrpc.NetService.PeerCountResponse
import io.iohk.ethereum.jsonrpc.NetService.VersionResponse
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.OptionNoneToJNullSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.QuantitiesSerializer
import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.UnformattedDataJsonSerializer
import io.iohk.ethereum.jsonrpc.server.controllers.JsonRpcBaseController.JsonRpcConfig
import io.iohk.ethereum.jsonrpc.server.http.JsonRpcHttpServer
import io.iohk.ethereum.jsonrpc.server.ipc.JsonRpcIpcServer
Expand All @@ -44,6 +49,9 @@ class JsonRpcControllerSpec
with LongPatience
with Eventually {

implicit val formats: Formats = DefaultFormats.preservingEmptyValues + OptionNoneToJNullSerializer +
QuantitiesSerializer + UnformattedDataJsonSerializer

"JsonRpcController" should "handle valid sha3 request" in new JsonRpcControllerFixture {
val rpcRequest = newJsonRpcRequest("web3_sha3", JString("0x1234") :: Nil)

Expand Down

0 comments on commit 3f6b82f

Please sign in to comment.