Skip to content

Commit

Permalink
[ETCM-533] scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bsuieric committed Jan 26, 2021
1 parent 7620a47 commit 4ba7d45
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
19 changes: 15 additions & 4 deletions src/main/scala/io/iohk/ethereum/jsonrpc/EthProofService.scala
Expand Up @@ -5,7 +5,14 @@ import cats.implicits._
import io.iohk.ethereum.consensus.blocks.BlockGenerator
import io.iohk.ethereum.domain.{Account, Address, Block, Blockchain, UInt256}
import io.iohk.ethereum.jsonrpc.ProofService.StorageValueProof.asRlpSerializedNode
import io.iohk.ethereum.jsonrpc.ProofService.{GetProofRequest, GetProofResponse, ProofAccount, StorageProof, StorageProofKey, StorageValueProof}
import io.iohk.ethereum.jsonrpc.ProofService.{
GetProofRequest,
GetProofResponse,
ProofAccount,
StorageProof,
StorageProofKey,
StorageValueProof
}
import io.iohk.ethereum.mpt.{MptNode, MptTraversals}
import monix.eval.Task

Expand All @@ -30,6 +37,7 @@ object ProofService {
val value: BigInt
val proof: Seq[ByteString]
}

/**
* Object proving a relationship of a storage value to an account's storageHash
*
Expand All @@ -40,13 +48,16 @@ object ProofService {
case class StorageValueProof(
key: StorageProofKey,
value: BigInt = BigInt(0),
proof: Seq[ByteString] = Seq.empty[MptNode].map(asRlpSerializedNode)) extends StorageProof
proof: Seq[ByteString] = Seq.empty[MptNode].map(asRlpSerializedNode)
) extends StorageProof

object StorageValueProof {
def apply(position: BigInt, value: Option[BigInt], proof: Option[Vector[MptNode]]): StorageValueProof =
(value, proof) match {
case (Some(value), Some(proof)) => new StorageValueProof(key = StorageProofKey(position), value = value, proof = proof.map(asRlpSerializedNode))
case (None, Some(proof)) => new StorageValueProof(key = StorageProofKey(position), proof = proof.map(asRlpSerializedNode))
case (Some(value), Some(proof)) =>
new StorageValueProof(key = StorageProofKey(position), value = value, proof = proof.map(asRlpSerializedNode))
case (None, Some(proof)) =>
new StorageValueProof(key = StorageProofKey(position), proof = proof.map(asRlpSerializedNode))
case (Some(value), None) => new StorageValueProof(key = StorageProofKey(position), value = value)
case (None, None) => new StorageValueProof(key = StorageProofKey(position))
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/io/iohk/ethereum/mpt/MerklePatriciaTrie.scala
Expand Up @@ -9,7 +9,6 @@ import io.iohk.ethereum.rlp.RLPImplicits._
import io.iohk.ethereum.rlp.{encode => encodeRLP}
import org.bouncycastle.util.encoders.Hex
import io.iohk.ethereum.utils.ByteUtils.matchingLength

import scala.annotation.tailrec

object MerklePatriciaTrie {
Expand Down Expand Up @@ -103,7 +102,8 @@ class MerklePatriciaTrie[K, V] private (private[mpt] val rootNode: Option[MptNod
def getProof(key: K): Option[Vector[MptNode]] = {
pathTraverse[Vector[MptNode]](Vector.empty, mkKeyNibbles(key)) { case (acc, node) =>
node match {
case Some(nextNodeOnExt @ (_: BranchNode | _: ExtensionNode | _: LeafNode | _: HashNode)) => acc :+ nextNodeOnExt
case Some(nextNodeOnExt @ (_: BranchNode | _: ExtensionNode | _: LeafNode | _: HashNode)) =>
acc :+ nextNodeOnExt
case _ => acc
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/test/scala/io/iohk/ethereum/domain/BlockchainSpec.scala
Expand Up @@ -6,7 +6,7 @@ import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
import io.iohk.ethereum.db.dataSource.EphemDataSource
import io.iohk.ethereum.db.storage.StateStorage
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields.HefPostEcip1097
import io.iohk.ethereum.mpt.MerklePatriciaTrie
import io.iohk.ethereum.mpt.{HashNode, MerklePatriciaTrie}
import io.iohk.ethereum.{BlockHelpers, Fixtures, ObjectGenerators}
import io.iohk.ethereum.ObjectGenerators._
import io.iohk.ethereum.proof.MptProofVerifier
Expand Down Expand Up @@ -177,9 +177,11 @@ class BlockchainSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyCh

val wrongAddress = Address(666)
val retrievedAccountProofWrong = blockchain.getAccountProof(wrongAddress, headerWithAcc.number)
//the account doesn't exist, so we can't retrieve it, but we do receive a proof of non-existence with a full path of nodes that we iterated
retrievedAccountProofWrong.isDefined shouldBe true
retrievedAccountProofWrong.size shouldBe 1
//the account doesn't exist, so we can't retrieve it, but we do receive a proof of non-existence with a full path of nodes(root node) that we iterated
(retrievedAccountProofWrong.getOrElse(Vector.empty).toList match {
case _ @HashNode(_) :: Nil => true
case _ => false
}) shouldBe true
mptWithAcc.get(wrongAddress) shouldBe None
}

Expand Down

0 comments on commit 4ba7d45

Please sign in to comment.