Skip to content

Commit f7ef53a

Browse files
authored
Merge pull request #75 from input-output-hk/scala-213
Scala 2.13
2 parents 2bb9a5b + 0459cf6 commit f7ef53a

28 files changed

+94
-82
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ language: scala
44
scala:
55
- 2.12.10
66
- 2.11.12
7+
- 2.13.1
78
jdk:
89
- oraclejdk8
910
cache:

Diff for: build.sbt

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ description := "Cryptographic primitives for Scala"
77

88
lazy val scala212 = "2.12.10"
99
lazy val scala211 = "2.11.12"
10-
crossScalaVersions := Seq(scala212, scala211)
11-
scalaVersion := scala212
10+
lazy val scala213 = "2.13.1"
11+
12+
crossScalaVersions := Seq(scala212, scala211, scala213)
13+
scalaVersion := scala213
1214

1315
javacOptions ++=
14-
"-source" :: "1.7" ::
15-
"-target" :: "1.7" ::
16+
"-source" :: "1.8" ::
17+
"-target" :: "1.8" ::
1618
Nil
1719

1820
lazy val commonSettings = Seq(
@@ -31,17 +33,19 @@ lazy val commonSettings = Seq(
3133
)
3234

3335
libraryDependencies ++= Seq(
34-
"org.rudogma" %% "supertagged" % "1.4",
36+
"org.rudogma" %% "supertagged" % "1.5",
3537
"com.google.guava" % "guava" % "20.0",
3638
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
3739
"org.whispersystems" % "curve25519-java" % "0.5.0",
3840
"org.bouncycastle" % "bcprov-jdk15on" % "1.64",
39-
"org.scorexfoundation" %% "scorex-util" % "0.1.6"
41+
"org.scorexfoundation" %% "scorex-util" % "0.1.7"
4042
)
4143

4244
libraryDependencies ++= Seq(
43-
"org.scalatest" %% "scalatest" % "3.0.+" % "test",
44-
"org.scalacheck" %% "scalacheck" % "1.13.+" % "test"
45+
"org.scalatest" %% "scalatest" % "3.1.+" % Test,
46+
"org.scalacheck" %% "scalacheck" % "1.14.+" % Test,
47+
// https://mvnrepository.com/artifact/org.scalatestplus/scalatestplus-scalacheck
48+
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test
4549
)
4650

4751
publishMavenStyle := true

Diff for: project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sbt.version=1.2.6
1+
sbt.version=1.2.8
22

Diff for: src/main/scala/scorex/crypto/authds/TwoPartyDictionary.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scorex.crypto.authds
22

33
import scorex.crypto.authds.avltree.batch.Operation
4-
import scorex.utils.ScorexEncoding
4+
import scorex.util.ScorexEncoding
55

66
import scala.util.Try
77

Diff for: src/main/scala/scorex/crypto/authds/TwoPartyProofElement.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scorex.crypto.authds
22

33
import scorex.crypto.authds.legacy.treap.Level
4-
import scorex.utils.ScorexEncoding
4+
import scorex.util.ScorexEncoding
55

66
trait TwoPartyProofElement extends ScorexEncoding {
77
val bytes: Array[Byte]

Diff for: src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
2929
(implicit val hf: HF = Blake2b256)
3030
extends AuthenticatedTreeOps[D] with ToStringHelper with ScorexLogging {
3131

32-
protected val labelLength = hf.DigestSize
32+
protected val labelLength: Int = hf.DigestSize
3333

3434
private[batch] var topNode: ProverNodes[D] = oldRootAndHeight.map(_._1).getOrElse({
3535
val t = new ProverLeaf(NegativeInfinityKey,
@@ -230,7 +230,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
230230
}
231231
}
232232

233-
loop(topNode, false)
233+
loop(topNode, keyFound = false)
234234
}
235235

236236
/**
@@ -267,7 +267,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
267267
* that contains only this info)
268268
* - Condense the sequence of values if they are mostly not randomly distributed
269269
* */
270-
def packTree(rNode: ProverNodes[D]) {
270+
def packTree(rNode: ProverNodes[D]): Unit = {
271271
// Post order traversal to pack up the tree
272272
if (!rNode.visited) {
273273
packagedTree += LabelInPackagedProof
@@ -357,21 +357,21 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
357357
* @return Random leaf from the tree that is not positive or negative infinity
358358
*/
359359
def randomWalk(rand: Random = new Random): Option[(ADKey, ADValue)] = {
360-
def internalNodeFn(r: InternalProverNode[D], dummy: Unit.type) =
360+
def internalNodeFn(r: InternalProverNode[D], dummy: Unit): (ProverNodes[D], Unit) =
361361
rand.nextBoolean() match {
362362
case true =>
363-
(r.right, Unit)
363+
(r.right, ())
364364
case false =>
365-
(r.left, Unit)
365+
(r.left, ())
366366
}
367367

368-
def leafFn(leaf: ProverLeaf[D], dummy: Unit.type): Option[(ADKey, ADValue)] = {
368+
def leafFn(leaf: ProverLeaf[D], dummy: Unit): Option[(ADKey, ADValue)] = {
369369
if (leaf.key sameElements PositiveInfinityKey) None
370370
else if (leaf.key sameElements NegativeInfinityKey) None
371371
else Some(leaf.key -> leaf.value)
372372
}
373373

374-
treeWalk(internalNodeFn, leafFn, Unit)
374+
treeWalk(internalNodeFn, leafFn, ())
375375
}
376376

377377
/**
@@ -442,7 +442,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
442442
var fail: Boolean = false
443443

444444
def checkTreeHelper(rNode: ProverNodes[D]): (ProverLeaf[D], ProverLeaf[D], Int) = {
445-
def myRequire(t: Boolean, s: String) = {
445+
def myRequire(t: Boolean, s: String): Unit = {
446446
if (!t) {
447447
var x = rNode.key(0).toInt
448448
if (x < 0) x = x + 256

Diff for: src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLVerifier.scala

+12-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import scorex.crypto.authds._
55
import scorex.crypto.hash._
66
import scorex.utils.ByteArray
77

8-
import scala.collection.mutable
98
import scala.util.{Failure, Try}
109

1110
/**
@@ -33,7 +32,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
3332

3433
override val collectChangedNodes: Boolean = false
3534

36-
protected val labelLength = hf.DigestSize
35+
protected val labelLength: Int = hf.DigestSize
3736

3837
/**
3938
* Returns Some[the current digest of the authenticated data structure],
@@ -169,7 +168,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
169168
// Now reconstruct the tree from the proof, which has the post order traversal
170169
// of the tree
171170
var numNodes = 0
172-
val s = new mutable.Stack[VerifierNodes[D]] // Nodes and depths
171+
var s = List.empty[VerifierNodes[D]] // Nodes and depths
173172
var i = 0
174173
var previousLeaf: Option[Leaf[D]] = None
175174
while (proof(i) != EndOfTreeInPackagedProof) {
@@ -181,7 +180,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
181180
case LabelInPackagedProof =>
182181
val label = proof.slice(i, i + labelLength).asInstanceOf[D]
183182
i += labelLength
184-
s.push(new LabelOnlyNode[D](label))
183+
s = new LabelOnlyNode[D](label) +: s
185184
previousLeaf = None
186185
case LeafInPackagedProof =>
187186
val key = if (previousLeaf.nonEmpty) {
@@ -202,17 +201,21 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
202201
val value = ADValue @@ proof.slice(i, i + valueLength)
203202
i += valueLength
204203
val leaf = new VerifierLeaf[D](key, value, nextLeafKey)
205-
s.push(leaf)
204+
s = leaf +: s
205+
206206
previousLeaf = Some(leaf)
207207
case _ =>
208-
val right = s.pop
209-
val left = s.pop
210-
s.push(new InternalVerifierNode(left, right, Balance @@ n))
208+
val right = s.head
209+
s = s.tail
210+
val left = s.head
211+
s = s.tail
212+
s = new InternalVerifierNode(left, right, Balance @@ n) +: s
213+
211214
}
212215
}
213216

214217
require(s.size == 1)
215-
val root = s.pop
218+
val root = s.head
216219
require(startingDigest startsWith root.label)
217220
directionsIndex = (i + 1) * 8 // Directions start right after the packed tree, which we just finished
218221
Some(root)

Diff for: src/main/scala/scorex/crypto/authds/avltree/batch/Operation.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scorex.crypto.authds.avltree.batch
22

33
import com.google.common.primitives.Longs
44
import scorex.crypto.authds.{ADKey, ADValue}
5-
import scorex.utils.ScorexEncoding
5+
import scorex.util.ScorexEncoding
66

77
import scala.util.{Failure, Success, Try}
88

Diff for: src/main/scala/scorex/crypto/authds/avltree/batch/ToStringHelper.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scorex.crypto.authds.avltree.batch
22

3-
import scorex.utils.ScorexEncoding
3+
import scorex.util.ScorexEncoding
44

55
trait ToStringHelper extends ScorexEncoding {
66
//Needed for debug (toString) only

Diff for: src/main/scala/scorex/crypto/authds/legacy/avltree/AVLTree.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,6 @@ class AVLTree[HF <: CryptographicHash[_ <: Digest]](keyLength: Int,
263263

264264
val (newTopNode, changeHappened, childHeightIncreased) = modifyHelper(topNode, foundAbove = false)
265265
if (changeHappened) topNode = newTopNode
266-
AVLModifyProof(key, proofStream)
266+
AVLModifyProof(key, proofStream.toSeq) //toSeq required for 2.13
267267
}
268268
}

Diff for: src/main/scala/scorex/crypto/authds/legacy/treap/Treap.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,6 @@ class Treap[HF <: CryptographicHash[_ <: Digest]](rootOpt: Option[Leaf] = None)
147147

148148
val (newTopNode: ProverNodes, changeHappened: Boolean) = modifyHelper(topNode, foundAbove = false)
149149
if (changeHappened) topNode = newTopNode
150-
TreapModifyProof(key, proofStream)
150+
TreapModifyProof(key, proofStream.toSeq) // .toSeq required for 2.13
151151
}
152152
}

Diff for: src/main/scala/scorex/crypto/authds/merkle/MerkleProof.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scorex.crypto.authds.merkle
22

33
import scorex.crypto.authds.{LeafData, Side}
44
import scorex.crypto.hash.{CryptographicHash, Digest}
5-
import scorex.utils.ScorexEncoding
5+
import scorex.util.ScorexEncoding
66

77
/**
88
* Proof is given leaf data, leaf hash sibling and also siblings for parent nodes. Using this data, it is possible to

Diff for: src/main/scala/scorex/crypto/authds/merkle/Node.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scorex.crypto.authds.merkle
22

33
import scorex.crypto.authds.LeafData
44
import scorex.crypto.hash._
5-
import scorex.utils.ScorexEncoding
5+
import scorex.util.ScorexEncoding
66

77
trait Node[D <: Digest] extends ScorexEncoding {
88
def hash: D

Diff for: src/main/scala/scorex/crypto/authds/merkle/sparse/Node.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scorex.crypto.authds.merkle.sparse
22

33
import scorex.crypto.authds.LeafData
4-
import scorex.crypto.encode.Base16
4+
import scorex.util.encode.Base16
55
import scorex.crypto.hash._
66

77
trait Node[D <: Digest] {

Diff for: src/test/scala/scorex/crypto/TestingCommons.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package scorex.crypto
33
import java.io.File
44

55
import org.scalacheck.{Arbitrary, Gen}
6-
import org.scalatest.Matchers
6+
import org.scalatest.matchers.should.Matchers
77

88
import scala.util.Random
99

Diff for: src/test/scala/scorex/crypto/authds/avltree/AVLDeleteSpecification.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package scorex.crypto.authds.avltree
22

3-
import org.scalatest.PropSpec
4-
import org.scalatest.prop.GeneratorDrivenPropertyChecks
3+
4+
import org.scalatest.propspec.AnyPropSpec
5+
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
56
import scorex.crypto.authds.avltree.batch._
67
import scorex.crypto.authds.{ADKey, ADValue, TwoPartyTests}
78
import scorex.crypto.hash.{Blake2b256, Digest32, Sha256}
89

9-
class AVLDeleteSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests {
10+
class AVLDeleteSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests {
1011

1112
val KL = 26
1213
val VL = 8

Diff for: src/test/scala/scorex/crypto/authds/avltree/AVLTreeSpecification.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package scorex.crypto.authds.avltree
22

33
import org.scalacheck.{Arbitrary, Gen}
4-
import org.scalatest.PropSpec
5-
import org.scalatest.prop.GeneratorDrivenPropertyChecks
4+
import org.scalatest.propspec.AnyPropSpec
5+
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
66
import scorex.crypto.authds.avltree.batch.{Insert, InsertOrUpdate, Lookup, Update}
77
import scorex.crypto.authds.legacy.avltree.{AVLModifyProof, AVLTree}
88
import scorex.crypto.authds.{ADKey, ADValue, TwoPartyTests}
99
import scorex.crypto.hash.Sha256
1010

11-
class AVLTreeSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests {
11+
class AVLTreeSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests {
1212

1313
val KL = 26
1414
val VL = 8

Diff for: src/test/scala/scorex/crypto/authds/avltree/batch/AVLBatchSpecification.scala

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ package scorex.crypto.authds.avltree.batch
22

33
import com.google.common.primitives.Longs
44
import org.scalacheck.{Arbitrary, Gen}
5-
import org.scalatest.PropSpec
6-
import org.scalatest.prop.GeneratorDrivenPropertyChecks
7-
import scorex.crypto.authds.avltree.batch.BatchingPlayground.{D, HF, generateProver, time}
5+
import org.scalatest.propspec.AnyPropSpec
6+
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
87
import scorex.crypto.authds.legacy.avltree.AVLTree
98
import scorex.crypto.authds._
10-
import scorex.crypto.encode.{Base16, Base58}
11-
import scorex.crypto.hash.{Blake2b256, _}
9+
import scorex.util.encode.{Base16, Base58}
10+
import scorex.crypto.hash._
1211
import scorex.utils.{ByteArray, Random}
1312

1413
import scala.util.Random.{nextInt => randomInt}
1514
import scala.util.{Failure, Try}
1615

17-
class AVLBatchSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests
16+
class AVLBatchSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests
1817
with BatchTestingHelpers {
1918

2019
property("return removed leafs and internal nodes for small tree") {

Diff for: src/test/scala/scorex/crypto/authds/avltree/batch/AVLBatchStatefulSpecification.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package scorex.crypto.authds.avltree.batch
33
import com.google.common.primitives.Longs
44
import org.scalacheck.commands.Commands
55
import org.scalacheck.{Gen, Prop}
6-
import org.scalatest.PropSpec
6+
import org.scalatest.propspec.AnyPropSpec
77
import scorex.crypto.authds._
88
import scorex.crypto.hash.{Blake2b256, Digest32}
99
import scorex.utils.{Random => RandomBytes}
1010

1111
import scala.util.{Failure, Random, Success, Try}
1212

13-
class AVLBatchStatefulSpecification extends PropSpec {
13+
class AVLBatchStatefulSpecification extends AnyPropSpec {
1414

1515
property("BatchAVLProver: prove and verify") {
1616
AVLCommands.property().check

Diff for: src/test/scala/scorex/crypto/authds/avltree/batch/BatchTesting.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LegacyProver(tree: AVLTree[_]) {
3232
case Failure(e) => throw BatchFailure(e, m)
3333
}
3434
}
35-
BatchSuccessSimple(aggregatedProofs)
35+
BatchSuccessSimple(aggregatedProofs.toSeq)
3636
} match {
3737
case Success(p) => p
3838
case Failure(e: BatchFailure) => e

Diff for: src/test/scala/scorex/crypto/authds/avltree/batch/BatchTestingHelpers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scorex.crypto.authds.avltree.batch
22

3-
import org.scalatest.Matchers
3+
import org.scalatest.matchers.should.Matchers
44
import scorex.crypto.authds.{ADKey, ADValue}
55
import scorex.crypto.hash.{Blake2b256, Digest32}
66
import scorex.utils.Random

Diff for: src/test/scala/scorex/crypto/authds/avltree/batch/BatchingPlayground.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scorex.crypto.authds.avltree.batch
22

33
import com.google.common.primitives.Longs
4-
import org.scalatest.Matchers
4+
import org.scalatest.matchers.should.Matchers
55
import scorex.crypto.authds.legacy.avltree.{AVLModifyProof, AVLTree}
66
import scorex.crypto.authds.{ADDigest, ADKey, ADValue}
77
import scorex.crypto.hash.{Blake2b256, Digest32, Sha256}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package scorex.crypto.authds.avltree.batch.serialization
22

33
import org.scalacheck.{Gen, Shrink}
4-
import org.scalatest.PropSpec
5-
import org.scalatest.prop.GeneratorDrivenPropertyChecks
4+
import org.scalatest.propspec.AnyPropSpec
5+
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
66
import scorex.crypto.authds.avltree.batch._
77
import scorex.crypto.authds.{ADKey, ADValue, TwoPartyTests}
88
import scorex.crypto.hash.{Blake2b256, _}
99
import scorex.utils.Random
1010

11-
class AVLBatchSerializationSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests {
11+
class AVLBatchSerializationSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests {
1212

1313
val InitialTreeSize = 1000
1414
val KL = 26

0 commit comments

Comments
 (0)