Skip to content

[ETCM-980] restore json OptionNoneToNullSerializer #1071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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