Skip to content

Commit bfc624b

Browse files
author
Michal Mrozek
committed
[CHORE] Fix tests
1 parent 35495d1 commit bfc624b

File tree

4 files changed

+133
-60
lines changed

4 files changed

+133
-60
lines changed

src/benchmark/scala/io/iohk/ethereum/mpt/MerklePatriciaTreeSpeedSpec.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ import io.iohk.ethereum.db.storage.{ArchiveNodeStorage, MptStorage, NodeStorage,
66
import io.iohk.ethereum.mpt.MerklePatriciaTrie.defaultByteArraySerializable
77
import io.iohk.ethereum.utils.Logger
88
import org.scalatest.FunSuite
9-
import org.scalatest.prop.PropertyChecks
109
import org.bouncycastle.util.encoders.Hex
10+
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
1111

12-
class MerklePatriciaTreeSpeedSpec extends FunSuite
13-
with PropertyChecks
14-
with ObjectGenerators
15-
with Logger
16-
with PersistentStorage {
12+
class MerklePatriciaTreeSpeedSpec
13+
extends FunSuite
14+
with ScalaCheckPropertyChecks
15+
with ObjectGenerators
16+
with Logger
17+
with PersistentStorage {
1718

1819
test("Performance test (From: https://github.com/ethereum/wiki/wiki/Benchmarks)") {
1920
val Rounds = 1000
2021
val Symmetric = true
2122

2223
val start: Long = System.currentTimeMillis
23-
val emptyTrie = MerklePatriciaTrie[Array[Byte], Array[Byte]](new SerializingMptStorage(new ArchiveNodeStorage(new NodeStorage(EphemDataSource()))))
24+
val emptyTrie = MerklePatriciaTrie[Array[Byte], Array[Byte]](
25+
new SerializingMptStorage(new ArchiveNodeStorage(new NodeStorage(EphemDataSource())))
26+
)
2427
var seed: Array[Byte] = Array.fill(32)(0.toByte)
2528

2629
val trieResult = (0 until Rounds).foldLeft(emptyTrie) { case (recTrie, i) =>
@@ -29,7 +32,7 @@ class MerklePatriciaTreeSpeedSpec extends FunSuite
2932
else {
3033
val mykey = seed
3134
seed = Node.hashFn(seed)
32-
val myval = if ((seed(0) & 0xFF) % 2 == 1) Array[Byte](seed.last) else seed
35+
val myval = if ((seed(0) & 0xff) % 2 == 1) Array[Byte](seed.last) else seed
3336
recTrie.put(mykey, myval)
3437
}
3538
}
@@ -55,7 +58,7 @@ class MerklePatriciaTreeSpeedSpec extends FunSuite
5558
val EmptyTrie = MerklePatriciaTrie[Array[Byte], Array[Byte]](ns)(defaultByteArraySer, defaultByteArraySer)
5659

5760
var t = System.currentTimeMillis()
58-
(1 to 20000000).foldLeft(EmptyTrie){ case (trie, i) =>
61+
(1 to 20000000).foldLeft(EmptyTrie) { case (trie, i) =>
5962
val k = hashFn(("hello" + i).getBytes)
6063
val v = hashFn(("world" + i).getBytes)
6164

src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import io.iohk.ethereum.network.p2p.messages.CommonMessages.SignedTransactions._
88
import io.iohk.ethereum.utils.Logger
99
import org.scalacheck.Gen
1010
import org.scalatest.FunSuite
11-
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks}
1211
import org.bouncycastle.util.encoders.Hex
12+
import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckPropertyChecks}
1313

1414
/**
1515
* Tests based on
1616
* - https://github.com/cryptape/ruby-rlp/blob/master/test/speed.rb
1717
* - https://github.com/ethereum/pyrlp/blob/develop/tests/speed.py
1818
*/
19-
class RLPSpeedSuite extends FunSuite
20-
with PropertyChecks
21-
with GeneratorDrivenPropertyChecks
19+
class RLPSpeedSuite
20+
extends FunSuite
21+
with ScalaCheckPropertyChecks
22+
with ScalaCheckDrivenPropertyChecks
2223
with ObjectGenerators
2324
with Logger {
2425

@@ -43,13 +44,15 @@ class RLPSpeedSuite extends FunSuite
4344
log.info(s"TX serializations / sec: (${rounds.toFloat / elapsedTxSerialization})")
4445

4546
val txDeserializationStart: Long = System.currentTimeMillis
46-
val deserializedTx: SignedTransaction = doTestDeserialize(serializedTx, (b: Array[Byte]) => b.toSignedTransaction, rounds)
47+
val deserializedTx: SignedTransaction =
48+
doTestDeserialize(serializedTx, (b: Array[Byte]) => b.toSignedTransaction, rounds)
4749
val elapsedTxDeserialization = (System.currentTimeMillis() - txDeserializationStart) / 1000f
4850
log.info(s"TX deserializations / sec: (${rounds.toFloat / elapsedTxDeserialization})")
4951
}
5052

5153
test("Performance decode") {
52-
val blockRaw: String = "f8cbf8c7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a02f4399b08efe68945c1cf90ffe85bbe3ce978959da753f9e649f034015b8817da00000000000000000000000000000000000000000000000000000000000000000834000008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0"
54+
val blockRaw: String =
55+
"f8cbf8c7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a02f4399b08efe68945c1cf90ffe85bbe3ce978959da753f9e649f034015b8817da00000000000000000000000000000000000000000000000000000000000000000834000008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0"
5356
val payload: Array[Byte] = Hex.decode(blockRaw)
5457
val ITERATIONS: Int = 10000000
5558
log.info("Starting " + ITERATIONS + " decoding iterations...")
@@ -80,7 +83,8 @@ class RLPSpeedSuite extends FunSuite
8083
gasLimit = 90000,
8184
receivingAddress = Address(Hex.decode("1c51bf013add0857c5d9cf2f71a7f15ca93d4816")),
8285
value = BigInt("1049756850000000000"),
83-
payload = ByteString.empty),
86+
payload = ByteString.empty
87+
),
8488
pointSign = 28,
8589
signatureRandom = ByteString(Hex.decode("cfe3ad31d6612f8d787c45f115cc5b43fb22bcc210b62ae71dc7cbf0a6bea8df")),
8690
signature = ByteString(Hex.decode("57db8998114fae3c337e99dbd8573d4085691880f4576c6c1f6c5bbfe67d6cf0")),
@@ -90,5 +94,8 @@ class RLPSpeedSuite extends FunSuite
9094
lazy val blockGen: Gen[Block] = for {
9195
header <- blockHeaderGen
9296
uncles <- blockHeaderGen
93-
} yield Block(header = header, BlockBody(transactionList = List.fill(10)(validTransaction), uncleNodesList = Seq(uncles)))
97+
} yield Block(
98+
header = header,
99+
BlockBody(transactionList = List.fill(10)(validTransaction), uncleNodesList = Seq(uncles))
100+
)
94101
}

src/it/scala/io/iohk/ethereum/db/DataSourceIntegrationTestBehavior.scala

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ package io.iohk.ethereum.db
22

33
import java.io.File
44
import java.nio.file.Files
5-
65
import akka.util.ByteString
76
import io.iohk.ethereum.ObjectGenerators
87
import io.iohk.ethereum.db.dataSource.DataSource
98
import org.scalatest.FlatSpec
10-
import org.scalatest.prop.PropertyChecks
9+
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
1110

12-
trait DataSourceIntegrationTestBehavior
13-
extends PropertyChecks
14-
with ObjectGenerators {
11+
trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with ObjectGenerators {
1512

1613
this: FlatSpec =>
1714

@@ -23,7 +20,6 @@ trait DataSourceIntegrationTestBehavior
2320

2421
val MaxIncreaseInLength = 10
2522

26-
2723
def withDir(testCode: String => Any): Unit = {
2824
val path = Files.createTempDirectory("testdb").getFileName.toString
2925
try {
@@ -34,7 +30,10 @@ trait DataSourceIntegrationTestBehavior
3430
}
3531
}
3632

37-
def updateInSeparateCalls(dataSource: DataSource, toUpsert: Seq[(ByteString, ByteString)]): DataSource = {
33+
def updateInSeparateCalls(
34+
dataSource: DataSource,
35+
toUpsert: Seq[(ByteString, ByteString)]
36+
): DataSource = {
3837
toUpsert.foldLeft(dataSource) { case (recDB, keyValuePair) =>
3938
recDB.update(OtherNamespace, Seq(), Seq(keyValuePair))
4039
}
@@ -50,7 +49,9 @@ trait DataSourceIntegrationTestBehavior
5049
dataSource = createDataSource(path),
5150
toUpsert = keyList.zip(keyList)
5251
)
53-
keyList.foreach { key => assert(db.get(OtherNamespace, key).contains(key)) }
52+
keyList.foreach { key =>
53+
assert(db.get(OtherNamespace, key).contains(key))
54+
}
5455

5556
db.destroy()
5657
}
@@ -61,9 +62,15 @@ trait DataSourceIntegrationTestBehavior
6162
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix)) { unFilteredKeyList: Seq[ByteString] =>
6263
withDir { path =>
6364
val keyList = unFilteredKeyList.take(KeyNumberLimit)
64-
val db = createDataSource(path).update(OtherNamespace, Seq(), keyList.zip(keyList))
65+
val db = createDataSource(path).update(
66+
OtherNamespace,
67+
Seq(),
68+
keyList.zip(keyList)
69+
)
6570

66-
keyList.foreach { key => assert(db.get(OtherNamespace, key).contains(key)) }
71+
keyList.foreach { key =>
72+
assert(db.get(OtherNamespace, key).contains(key))
73+
}
6774

6875
db.destroy()
6976
}
@@ -74,10 +81,15 @@ trait DataSourceIntegrationTestBehavior
7481
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix)) { unFilteredKeyList: Seq[ByteString] =>
7582
withDir { path =>
7683
val keyList = unFilteredKeyList.take(KeyNumberLimit)
77-
val db = createDataSource(path).update(OtherNamespace, Seq(), keyList.zip(keyList))
84+
val db = createDataSource(path).update(
85+
OtherNamespace,
86+
Seq(),
87+
keyList.zip(keyList)
88+
)
7889

7990
val keyListWithExtraByte = keyList.map(1.toByte +: _)
80-
val dbAfterUpdate = updateInSeparateCalls(db, keyList.zip(keyListWithExtraByte))
91+
val dbAfterUpdate =
92+
updateInSeparateCalls(db, keyList.zip(keyListWithExtraByte))
8193

8294
keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
8395
assert(dbAfterUpdate.get(OtherNamespace, key).contains(value))
@@ -92,10 +104,18 @@ trait DataSourceIntegrationTestBehavior
92104
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix)) { unFilteredKeyList: Seq[ByteString] =>
93105
withDir { path =>
94106
val keyList = unFilteredKeyList.take(KeyNumberLimit)
95-
val db = createDataSource(path).update(OtherNamespace, Seq(), keyList.zip(keyList))
107+
val db = createDataSource(path).update(
108+
OtherNamespace,
109+
Seq(),
110+
keyList.zip(keyList)
111+
)
96112

97113
val keyListWithExtraByte = keyList.map(1.toByte +: _)
98-
val dbAfterUpdate = db.update(OtherNamespace, Seq(), keyList.zip(keyListWithExtraByte))
114+
val dbAfterUpdate = db.update(
115+
OtherNamespace,
116+
Seq(),
117+
keyList.zip(keyListWithExtraByte)
118+
)
99119

100120
keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
101121
assert(dbAfterUpdate.get(OtherNamespace, key).contains(value))
@@ -110,10 +130,17 @@ trait DataSourceIntegrationTestBehavior
110130
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix)) { unFilteredKeyList: Seq[ByteString] =>
111131
withDir { path =>
112132
val keyList = unFilteredKeyList.take(KeyNumberLimit)
113-
val db = createDataSource(path).update(namespace = OtherNamespace, toRemove = Seq(), toUpsert = keyList.zip(keyList))
133+
val db = createDataSource(path)
134+
.update(
135+
namespace = OtherNamespace,
136+
toRemove = Seq(),
137+
toUpsert = keyList.zip(keyList)
138+
)
114139
.clear
115140

116-
keyList.foreach { key => assert(db.get(OtherNamespace, key).isEmpty) }
141+
keyList.foreach { key =>
142+
assert(db.get(OtherNamespace, key).isEmpty)
143+
}
117144

118145
db.destroy()
119146
}
@@ -124,11 +151,17 @@ trait DataSourceIntegrationTestBehavior
124151
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix)) { unFilteredKeyList: Seq[ByteString] =>
125152
withDir { path =>
126153
val keyList = unFilteredKeyList.take(KeyNumberLimit)
127-
val db = createDataSource(path).update(namespace = OtherNamespace, toRemove = Seq(), toUpsert = keyList.zip(keyList))
154+
val db = createDataSource(path).update(
155+
namespace = OtherNamespace,
156+
toRemove = Seq(),
157+
toUpsert = keyList.zip(keyList)
158+
)
128159
db.close()
129160

130161
val dbAfterClose = createDataSource(path)
131-
keyList.foreach { key => assert(dbAfterClose.get(OtherNamespace, key).contains(key)) }
162+
keyList.foreach { key =>
163+
assert(dbAfterClose.get(OtherNamespace, key).contains(key))
164+
}
132165

133166
dbAfterClose.destroy()
134167
}
@@ -139,13 +172,19 @@ trait DataSourceIntegrationTestBehavior
139172
withDir { path =>
140173
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix)) { unFilteredKeyList: Seq[ByteString] =>
141174
val keyList = unFilteredKeyList.take(KeyNumberLimit)
142-
val db = createDataSource(path).update(namespace = OtherNamespace, toRemove = Seq(), toUpsert = keyList.zip(keyList))
175+
val db = createDataSource(path).update(
176+
namespace = OtherNamespace,
177+
toRemove = Seq(),
178+
toUpsert = keyList.zip(keyList)
179+
)
143180
db.destroy()
144181

145182
assert(!new File(path).exists())
146183

147184
val dbAfterDestroy = createDataSource(path)
148-
keyList.foreach { key => assert(dbAfterDestroy.get(OtherNamespace, key).isEmpty) }
185+
keyList.foreach { key =>
186+
assert(dbAfterDestroy.get(OtherNamespace, key).isEmpty)
187+
}
149188

150189
dbAfterDestroy.destroy()
151190
}
@@ -194,16 +233,22 @@ trait DataSourceIntegrationTestBehavior
194233
//Removal of keys from the OtherNamespace namespace
195234
db.update(OtherNamespace, keyList, Nil)
196235

197-
keyList.foreach { key => assert(db.get(OtherNamespace, key).isEmpty) }
236+
keyList.foreach { key =>
237+
assert(db.get(OtherNamespace, key).isEmpty)
238+
}
198239
keyList.zip(valList2).foreach { case (key, value) =>
199240
assert(db.get(OtherNamespace2, key).contains(value))
200241
}
201242

202243
//Removal of keys from the OtherNamespace2 namespace
203244
db.update(OtherNamespace2, keyList, Nil)
204245

205-
keyList.foreach { key => assert(db.get(OtherNamespace, key).isEmpty) }
206-
keyList.foreach { key => assert(db.get(OtherNamespace2, key).isEmpty) }
246+
keyList.foreach { key =>
247+
assert(db.get(OtherNamespace, key).isEmpty)
248+
}
249+
keyList.foreach { key =>
250+
assert(db.get(OtherNamespace2, key).isEmpty)
251+
}
207252

208253
db.destroy()
209254
}

0 commit comments

Comments
 (0)