Skip to content

Commit fbfac3f

Browse files
authored
Merge pull request #32 from input-output-hk/randomWalk
Make BatchAVLProver.randomWalk function reproducable
2 parents 2134553 + c2af0c1 commit fbfac3f

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

lock.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// DON'T EDIT THIS FILE.
2-
// This file is auto generated by sbt-lock 0.3.0.
2+
// This file is auto generated by sbt-lock 0.4.0.
33
// https://github.com/tkawachi/sbt-lock/
4-
dependencyOverrides in ThisBuild ++= Set(
4+
dependencyOverrides in ThisBuild ++= Seq(
55
"com.google.guava" % "guava" % "19.0",
66
"org.bouncycastle" % "bcprov-jdk15on" % "1.58",
77
"org.rudogma" % "supertagged_2.12" % "1.4",

project/build.properties

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

project/plugins.sbt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
12
logLevel := Level.Warn
23

3-
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
4+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
45

5-
addSbtPlugin("com.github.tkawachi" % "sbt-lock" % "0.3.0")
6+
addSbtPlugin("com.github.tkawachi" % "sbt-lock" % "0.4.0")
67

7-
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
8+
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
89

910
//addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")
1011

11-
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.27")
12+
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3")

src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ class BatchAVLProver[D <: Digest, HF <: ThreadUnsafeHash[D]](val keyLength: Int,
277277
}
278278

279279

280-
def randomWalk(): Option[(ADKey, ADValue)] = {
280+
def randomWalk(rand: Random = new Random): Option[(ADKey, ADValue)] = {
281281
def internalNodeFn(r: InternalProverNode[D], dummy: Unit.type) =
282-
Random.nextBoolean() match {
282+
rand.nextBoolean() match {
283283
case true =>
284284
(r.right, Unit)
285285
case false=>

src/test/scala/scorex/crypto/authds/avltree/batch/AVLBatchSpecification.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ class AVLBatchSpecification extends PropSpec with GeneratorDrivenPropertyChecks
2424
def randomKey(size: Int = 32): ADKey = ADKey @@ Random.randomBytes(size)
2525
def randomValue(size: Int = 32): ADValue = ADValue @@ Random.randomBytes(size)
2626

27+
property("randomWalk") {
28+
val TreeSize = 1000
29+
val prover = new BatchAVLProver[T, Blake2b256Unsafe](KL, None)
30+
val keyValues = (0 until TreeSize) map { i =>
31+
(ADKey @@ Blake2b256(i.toString.getBytes).take(KL), ADValue @@ (i.toString.getBytes))
32+
}
33+
keyValues.foreach(kv => prover.performOneOperation(Insert(kv._1, kv._2)))
34+
prover.generateProof()
35+
36+
forAll { seed: Long =>
37+
val e1 = prover.randomWalk(new scala.util.Random(seed))
38+
val e2 = prover.randomWalk(new scala.util.Random(seed))
39+
e1.get._1 shouldEqual e2.get._1
40+
e1.get._2 shouldEqual e2.get._2
41+
}
42+
}
43+
2744
property("unauthenticatedLookup") {
2845
val p = new BatchAVLProver[Digest32, Blake2b256Unsafe](keyLength = 8, valueLengthOpt = None)
2946

0 commit comments

Comments
 (0)