Skip to content

Commit 7ac59f7

Browse files
committed
merging issues
2 parents ea33f01 + 7af35b9 commit 7ac59f7

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
language: scala
2+
jdk:
3+
- oraclejdk9
4+
scala:
5+
- 2.12.7
16
sudo: required
27
branches:
38
only:
@@ -7,4 +12,6 @@ services:
712
- docker
813
before_install:
914
- docker build -t scrypto:test .
10-
script: docker run --rm -it scrypto:test sbt test
15+
script:
16+
- sbt test:compile
17+
- docker run --rm -it scrypto:test sbt test

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name := "scrypto"
55
lazy val commonSettings = Seq(
66
organization := "org.scorexfoundation",
77
version := "2.1.5",
8-
scalaVersion := "2.12.5",
8+
scalaVersion := "2.12.7",
99
resolvers += Resolver.sonatypeRepo("public"),
1010
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),
1111
homepage := Some(url("https://github.com/input-output-hk/scrypto")),

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sbt.version=1.1.1
1+
sbt.version=1.2.6
22

src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class BatchAVLProverSerializer[D <: Digest, HF <: CryptographicHash[D]](implicit
103103
case l: ProverLeaf[D] =>
104104
Bytes.concat(Array(0.toByte), l.key, l.nextLeafKey, l.value)
105105
case n: ProxyInternalNode[D] if n.isEmpty =>
106-
Bytes.concat(Array(2.toByte, n.balance), n.key, n.leftLabel, n.rightLabel)
106+
Bytes.concat(Array(2.toByte, n.balance), n.key, n.leftLabel, n.rightLabel, n.label)
107107
case n: InternalProverNode[D] =>
108108
val leftBytes = loop(n.left)
109109
val rightBytes = loop(n.right)
@@ -134,7 +134,8 @@ class BatchAVLProverSerializer[D <: Digest, HF <: CryptographicHash[D]](implicit
134134
val key = ADKey @@ bytes.slice(2, keyLength + 2)
135135
val leftLabel = hf.byteArrayToDigest(bytes.slice(keyLength + 2, keyLength + 2 + labelLength)).get
136136
val rightLabel = hf.byteArrayToDigest(bytes.slice(keyLength + 2 + labelLength, keyLength + 2 + 2 * labelLength)).get
137-
new ProxyInternalNode[D](key, None, leftLabel, rightLabel, balance)
137+
val selfLabel = hf.byteArrayToDigest(bytes.slice(keyLength + 2 + 2 * labelLength, keyLength + 2 + 3 * labelLength)).get
138+
new ProxyInternalNode[D](key, Some(selfLabel), leftLabel, rightLabel, balance)
138139
case _ =>
139140
???
140141
}

src/main/scala/scorex/crypto/authds/avltree/batch/serialization/ProxyInternalNode.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class ProxyInternalNode[D <: Digest](protected var pk: ADKey,
1212
(implicit val phf: CryptographicHash[D])
1313
extends InternalProverNode(k = pk, l = null, r = null, b = pb)(phf) {
1414

15-
override def label: D = if (isEmpty) selfLabelOpt.getOrElse(leftLabel) else super.label
15+
override def computeLabel: D = hf.prefixedHash(1: Byte, Array(b), leftLabel, rightLabel)
16+
17+
override def label: D = if (isEmpty) selfLabelOpt.getOrElse(computeLabel) else super.label
1618

1719
def mutate(n: ProverNodes[D]): Unit = {
1820
if (n.label sameElements leftLabel) {

src/test/scala/scorex/crypto/authds/avltree/batch/serialization/AVLBatchSerializationSpecification.scala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scorex.crypto.authds.avltree.batch.serialization
22

3-
import org.scalacheck.Gen
3+
import org.scalacheck.{Gen, Shrink}
44
import org.scalatest.PropSpec
55
import org.scalatest.prop.GeneratorDrivenPropertyChecks
66
import scorex.crypto.authds.avltree.batch._
@@ -18,6 +18,8 @@ class AVLBatchSerializationSpecification extends PropSpec with GeneratorDrivenPr
1818
type HF = Blake2b256.type
1919
implicit val hf: HF = Blake2b256
2020

21+
implicit def noShrink[A]: Shrink[A] = Shrink(_ => Stream.empty)
22+
2123
def randomKey(size: Int = 32): ADKey = ADKey @@ Random.randomBytes(size)
2224

2325
def randomValue(size: Int = 32): ADValue = ADValue @@ Random.randomBytes(size)
@@ -79,6 +81,22 @@ class AVLBatchSerializationSpecification extends PropSpec with GeneratorDrivenPr
7981
}
8082
}
8183

84+
property("manifest serialization") {
85+
val serializer = new BatchAVLProverSerializer[D, HF]
86+
forAll(Gen.choose(100, 100000)) { treeSize: Int =>
87+
val tree = generateProver(treeSize)
88+
val kl = tree.keyLength
89+
val digest = tree.digest
90+
val sliced = serializer.slice(tree)
91+
92+
val manifest = sliced._1
93+
val manifestBytes = serializer.manifestToBytes(manifest)
94+
val deserializedManifest = serializer.manifestFromBytes(manifestBytes).get
95+
96+
deserializedManifest.oldRootAndHeight._1.label shouldBe manifest.oldRootAndHeight._1.label
97+
}
98+
}
99+
82100
def leftTree(n: ProverNodes[D]): Seq[ProverNodes[D]] = n match {
83101
case n: ProxyInternalNode[D] if n.isEmpty =>
84102
Seq(n)

0 commit comments

Comments
 (0)