Skip to content

Commit

Permalink
[Chore] update scalatest (#689)
Browse files Browse the repository at this point in the history
* [Chore] Update ScalaTest

* [Chore] Update Scalamock

* [Chore] Update repo.nix
  • Loading branch information
kapke authored Sep 25, 2020
1 parent 6a58490 commit 7d7fd4e
Show file tree
Hide file tree
Showing 153 changed files with 1,409 additions and 700 deletions.
5 changes: 3 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ object Dependencies {
)

val testing: Seq[ModuleID] = Seq(
"org.scalatest" %% "scalatest" % "3.0.8" % "it,test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.6.0" % "test",
"org.scalatest" %% "scalatest" % "3.2.2" % "it,test",
"org.scalamock" %% "scalamock" % "5.0.0" % "test",
"org.scalatestplus" %% "scalacheck-1-14" % "3.2.2.0" % "test",
"org.scalacheck" %% "scalacheck" % "1.14.1" % "it,test"
)

Expand Down
648 changes: 512 additions & 136 deletions repo.nix

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import io.iohk.ethereum.mpt.MerklePatriciaTrie.defaultByteArraySerializable
import io.iohk.ethereum.utils.Logger
import io.iohk.ethereum.{ObjectGenerators, crypto}
import org.bouncycastle.util.encoders.Hex
import org.scalatest.FunSuite
import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

class MerklePatriciaTreeSpeedSpec
extends FunSuite
extends AnyFunSuite
with ScalaCheckPropertyChecks
with ObjectGenerators
with Logger
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import io.iohk.ethereum.domain._
import io.iohk.ethereum.network.p2p.messages.CommonMessages.SignedTransactions._
import io.iohk.ethereum.utils.Logger
import org.scalacheck.Gen
import org.scalatest.FunSuite
import org.bouncycastle.util.encoders.Hex
import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckPropertyChecks}

/**
Expand All @@ -17,7 +17,7 @@ import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckP
* - https://github.com/ethereum/pyrlp/blob/develop/tests/speed.py
*/
class RLPSpeedSuite
extends FunSuite
extends AnyFunSuite
with ScalaCheckPropertyChecks
with ScalaCheckDrivenPropertyChecks
with ObjectGenerators
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package io.iohk.ethereum.ets.blockchain

import java.util.concurrent.Executors

import akka.actor.ActorSystem
import io.iohk.ethereum.domain.Block
import io.iohk.ethereum.ets.common.TestOptions
import io.iohk.ethereum.extvm.ExtVMInterface
import io.iohk.ethereum.ledger.Ledger.VMImpl
import io.iohk.ethereum.nodebuilder.VmSetup
import io.iohk.ethereum.utils.{Config, Logger, VmConfig}
import org.scalatest._
import org.scalatest.{Args, BeforeAndAfterAll, Status}
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers

import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future}

Expand All @@ -18,7 +22,7 @@ object BlockchainSuite {
lazy val extvm: VMImpl = VmSetup.vm(VmConfig(Config.config), Config.blockchains.blockchainConfig, testMode = true)
}

class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with Logger {
class BlockchainSuite extends AnyFreeSpec with Matchers with BeforeAndAfterAll with Logger {
import BlockchainSuite.testContext

val unsupportedNetworks: Set[String] = Set(
Expand Down Expand Up @@ -60,7 +64,7 @@ class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with
cancel(s"Unsupported network: ${scenario.network}")
} else if (!supportedNetworks.contains(scenario.network)) {
fail(s"Unknown network: ${scenario.network}")
} else if (isCanceled(group.name, name)){
} else if (isCanceled(group.name, name)) {
cancel(s"Test: $name in group: ${group.name} not yet supported")
} else {
log.info(s"Running test: ${group.name}#$name")
Expand All @@ -82,7 +86,9 @@ class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with
}

private def isCanceled(groupName: String, testName: String): Boolean =
ignoredTests.get(groupName).isDefined && (ignoredTests(groupName).contains(testName) || ignoredTests(groupName).isEmpty)
ignoredTests.get(groupName).isDefined && (ignoredTests(groupName).contains(testName) || ignoredTests(
groupName
).isEmpty)

private def runScenario(scenario: BlockchainScenario, setup: ScenarioSetup, name: String): Unit = {

Expand Down Expand Up @@ -110,7 +116,9 @@ class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with
val lastBlock = getBestBlock

val expectedWorldStateHash =
scenario.postStateHash.orElse(finalWorld.map(_.stateRootHash)).getOrElse(throw new IllegalStateException("postState or PostStateHash not defined"))
scenario.postStateHash
.orElse(finalWorld.map(_.stateRootHash))
.getOrElse(throw new IllegalStateException("postState or PostStateHash not defined"))

lastBlock shouldBe defined

Expand Down
10 changes: 7 additions & 3 deletions src/ets/scala/io/iohk/ethereum/ets/vm/VMSuite.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.iohk.ethereum.ets.vm

import akka.util.ByteString
import io.iohk.ethereum.crypto.kec256
import io.iohk.ethereum.domain.TxLogEntry
import io.iohk.ethereum.ets.common.TestOptions
import io.iohk.ethereum.network.p2p.messages.PV63.TxLogEntryImplicits._
import io.iohk.ethereum.rlp._
import io.iohk.ethereum.utils.Logger
import io.iohk.ethereum.vm.MockWorldState._
import io.iohk.ethereum.vm._
import io.iohk.ethereum.crypto.kec256
import org.scalatest._
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers

class VMSuite extends FreeSpec with Matchers with Logger {
class VMSuite extends AnyFreeSpec with Matchers with Logger {

val vm = new TestVM

Expand Down Expand Up @@ -79,7 +81,9 @@ class VMSuite extends FreeSpec with Matchers with Logger {
result.internalTxs.flatMap(internalTxToCallCreate) shouldEqual callcreates
}

if (scenario.gas.isEmpty && scenario.out.isEmpty && scenario.callcreates.isEmpty && scenario.post.isEmpty && scenario.logs.isEmpty) {
if (
scenario.gas.isEmpty && scenario.out.isEmpty && scenario.callcreates.isEmpty && scenario.post.isEmpty && scenario.logs.isEmpty
) {
result.error.isDefined shouldBe true
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.iohk.ethereum.vm

import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FreeSpec, Matchers}
import org.scalatest.matchers.should.Matchers
import org.scalatest.freespec.AnyFreeSpec

class CallSelfDestructSpec extends FreeSpec with Matchers {
class CallSelfDestructSpec extends AnyFreeSpec with Matchers {

"EVM running CallSelfDestruct contract" - {

Expand Down
5 changes: 3 additions & 2 deletions src/evmTest/scala/io/iohk/ethereum/vm/CallerSpec.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.iohk.ethereum.vm

import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FreeSpec, Matchers}
import org.scalatest.matchers.should.Matchers
import org.scalatest.freespec.AnyFreeSpec
import io.iohk.ethereum.domain.UInt256

// scalastyle:off magic.number
class CallerSpec extends FreeSpec with Matchers {
class CallerSpec extends AnyFreeSpec with Matchers {

"EVM running Caller contract" - {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.iohk.ethereum.vm

import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FreeSpec, Matchers}
import org.scalatest.matchers.should.Matchers
import org.scalatest.freespec.AnyFreeSpec
import io.iohk.ethereum.domain.UInt256

// scalastyle:off magic.number
class ContractCallingItselfSpec extends FreeSpec with Matchers {
class ContractCallingItselfSpec extends AnyFreeSpec with Matchers {

"EVM running ContractCallingItself contract" - {

Expand Down
5 changes: 3 additions & 2 deletions src/evmTest/scala/io/iohk/ethereum/vm/FibonacciSpec.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.iohk.ethereum.vm

import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FreeSpec, Matchers}
import org.scalatest.matchers.should.Matchers
import org.scalatest.freespec.AnyFreeSpec
import io.iohk.ethereum.domain.UInt256

// scalastyle:off magic.number
class FibonacciSpec extends FreeSpec with Matchers {
class FibonacciSpec extends AnyFreeSpec with Matchers {

"EVM running Fibonacci contract" - {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.iohk.ethereum.vm

import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FreeSpec, Matchers}
import io.iohk.ethereum.domain.UInt256
import org.scalatest.matchers.should.Matchers
import org.scalatest.freespec.AnyFreeSpec

// scalastyle:off magic.number
class MinimumViableTokenSpec extends FreeSpec with Matchers {
class MinimumViableTokenSpec extends AnyFreeSpec with Matchers {

"EVM running MinimumViableToken contract" - {

Expand Down Expand Up @@ -38,8 +39,8 @@ class MinimumViableTokenSpec extends FreeSpec with Matchers {
val sender = createAccount(balance = 10)
val receiver = createAccount(balance = 10)

val (result, _) = deployContract("MinimumViableToken", creatorAddress = sender,
constructorArgs = Seq(100), gasLimit = 102934)
val (result, _) =
deployContract("MinimumViableToken", creatorAddress = sender, constructorArgs = Seq(100), gasLimit = 102934)

result.error shouldBe Some(OutOfGas)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.iohk.ethereum.vm

import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FreeSpec, Matchers}
import io.iohk.ethereum.domain.UInt256
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers

// scalastyle:off magic.number
class MutualRecursionSpec extends FreeSpec with Matchers {
class MutualRecursionSpec extends AnyFreeSpec with Matchers {

"EVM running MutualRecursion contract" - {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import io.iohk.ethereum.crypto._
import io.iohk.ethereum.domain.SignedTransaction.{FirstByteOfAddress, LastByteOfAddress}
import io.iohk.ethereum.nodebuilder.SecureRandomBuilder
import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FunSuite, Matchers}
import org.bouncycastle.crypto.params.ECPublicKeyParameters
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

class PrecompiledContractsSpecEvm extends FunSuite with Matchers with SecureRandomBuilder {
class PrecompiledContractsSpecEvm extends AnyFunSuite with Matchers with SecureRandomBuilder {

test("Precompiled Contracts") {
val keyPair = generateKeyPair(secureRandom)
Expand Down
5 changes: 3 additions & 2 deletions src/evmTest/scala/io/iohk/ethereum/vm/ThrowSpec.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.iohk.ethereum.vm

import io.iohk.ethereum.vm.utils.EvmTestEnv
import org.scalatest.{FreeSpec, Matchers}
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers

// scalastyle:off magic.number
class ThrowSpec extends FreeSpec with Matchers {
class ThrowSpec extends AnyFreeSpec with Matchers {

"EVM running Throw contract" - {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package io.iohk.ethereum.db

import java.io.File
import java.nio.file.Files

import akka.util.ByteString
import io.iohk.ethereum.ObjectGenerators
import io.iohk.ethereum.db.dataSource.{DataSource, DataSourceUpdate}
import io.iohk.ethereum.db.dataSource.DataSource.{Key, Namespace, Value}
import org.scalatest.FlatSpec
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with ObjectGenerators {

this: FlatSpec =>
this: AnyFlatSpec =>

val KeySizeWithoutPrefix: Int = 32
val KeySize: Int = KeySizeWithoutPrefix + 1
Expand All @@ -32,15 +33,15 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
}

def prepareUpdate(
namespace: Namespace = OtherNamespace,
toRemove: Seq[Key] = Nil,
toUpsert: Seq[(Key, Value)] = Nil
namespace: Namespace = OtherNamespace,
toRemove: Seq[Key] = Nil,
toUpsert: Seq[(Key, Value)] = Nil
): Seq[DataSourceUpdate] =
Seq(DataSourceUpdate(namespace, toRemove, toUpsert))

def updateInSeparateCalls(
dataSource: DataSource,
toUpsert: Seq[(ByteString, ByteString)]
dataSource: DataSource,
toUpsert: Seq[(ByteString, ByteString)]
): Unit = {
toUpsert.foreach { keyValuePair =>
dataSource.update(prepareUpdate(toUpsert = Seq(keyValuePair)))
Expand Down Expand Up @@ -93,9 +94,8 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
val keyListWithExtraByte = keyList.map(1.toByte +: _)
updateInSeparateCalls(db, keyList.zip(keyListWithExtraByte))

keyList.zip(keyListWithExtraByte).foreach {
case (key, value) =>
assert(db.get(OtherNamespace, key).contains(value))
keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
assert(db.get(OtherNamespace, key).contains(value))
}

db.destroy()
Expand All @@ -113,9 +113,8 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
val keyListWithExtraByte = keyList.map(1.toByte +: _)
db.update(prepareUpdate(toUpsert = keyList.zip(keyListWithExtraByte)))

keyList.zip(keyListWithExtraByte).foreach {
case (key, value) =>
assert(db.get(OtherNamespace, key).contains(value))
keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
assert(db.get(OtherNamespace, key).contains(value))
}

db.destroy()
Expand Down Expand Up @@ -191,9 +190,8 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
val valList2 = keyList.map(2.toByte +: _)
db.update(prepareUpdate(namespace = OtherNamespace2, toUpsert = keyList.zip(valList2)))

keyList.zip(valList1).foreach {
case (key, value) =>
assert(db.get(OtherNamespace, key).contains(value))
keyList.zip(valList1).foreach { case (key, value) =>
assert(db.get(OtherNamespace, key).contains(value))
}
keyList.zip(valList2).foreach { case (key, value) =>
assert(db.get(OtherNamespace2, key).contains(value))
Expand Down Expand Up @@ -223,9 +221,8 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
keyList.foreach { key =>
assert(db.get(OtherNamespace, key).isEmpty)
}
keyList.zip(valList2).foreach {
case (key, value) =>
assert(db.get(OtherNamespace2, key).contains(value))
keyList.zip(valList2).foreach { case (key, value) =>
assert(db.get(OtherNamespace2, key).contains(value))
}

//Removal of keys from the OtherNamespace2 namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ package io.iohk.ethereum.db

import io.iohk.ethereum.db.dataSource.{RocksDbConfig, RocksDbDataSource}
import io.iohk.ethereum.db.storage.Namespaces
import org.scalatest.FlatSpec
import org.scalatest.flatspec.AnyFlatSpec

class RocksDbDataSourceIntegrationSuite extends FlatSpec with DataSourceIntegrationTestBehavior {
class RocksDbDataSourceIntegrationSuite extends AnyFlatSpec with DataSourceIntegrationTestBehavior {

private def createDataSource(dataSourcePath: String) = RocksDbDataSource(new RocksDbConfig {
override val createIfMissing: Boolean = true
override val paranoidChecks: Boolean = true
override val path: String = dataSourcePath
override val maxThreads: Int = 1
override val maxOpenFiles: Int = 32
override val verifyChecksums: Boolean = true
override val levelCompaction: Boolean = true
override val blockSize: Long = 16384
override val blockCacheSize: Long = 33554432
}, Namespaces.nsSeq)
private def createDataSource(dataSourcePath: String) = RocksDbDataSource(
new RocksDbConfig {
override val createIfMissing: Boolean = true
override val paranoidChecks: Boolean = true
override val path: String = dataSourcePath
override val maxThreads: Int = 1
override val maxOpenFiles: Int = 32
override val verifyChecksums: Boolean = true
override val levelCompaction: Boolean = true
override val blockSize: Long = 16384
override val blockCacheSize: Long = 33554432
},
Namespaces.nsSeq
)

it should behave like dataSource(createDataSource)
}

Loading

0 comments on commit 7d7fd4e

Please sign in to comment.