Skip to content

Commit b92da8a

Browse files
author
Leonor Boga
committed
ETCM-944 Fix tests
1 parent 6afa3b2 commit b92da8a

File tree

12 files changed

+29
-93
lines changed

12 files changed

+29
-93
lines changed

src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class BlockImporterItSpec
141141
"BlockImporter" should "not discard blocks of the main chain if the reorganisation failed" in {
142142

143143
//ledger with not mocked blockExecution
144-
val ledger = new TestLedgerImpl(successValidators)
144+
val ledger = new TestLedgerImplNotMockedBlockExecution(successValidators)
145145
val blockImporter = system.actorOf(
146146
BlockImporter.props(
147147
fetcherProbe.ref,
@@ -253,7 +253,7 @@ class BlockImporterItSpec
253253
val newBlock: Block = getBlock(genesisBlock.number + 5, difficulty = 104, parent = parent.header.hash)
254254
val invalidBlock = newBlock.copy(header = newBlock.header.copy(beneficiary = Address(111).bytes))
255255

256-
val ledger = new TestLedgerImpl(successValidators)
256+
val ledger = new TestLedgerImplNotMockedBlockExecution(successValidators)
257257
val blockImporter = system.actorOf(
258258
BlockImporter.props(
259259
fetcherProbe.ref,
@@ -271,7 +271,6 @@ class BlockImporterItSpec
271271
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(List(invalidBlock)))
272272

273273
eventually {
274-
275274
val msg = fetcherProbe
276275
.fishForMessage(Timeouts.longTimeout) {
277276
case BlockFetcher.FetchStateNode(_, _) => true

src/it/scala/io/iohk/ethereum/txExecTest/ContractTest.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import java.util.concurrent.Executors
4-
import io.iohk.ethereum.domain.{BlockchainImpl, BlockchainStorages, Receipt}
5-
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation, Ledger}
3+
import io.iohk.ethereum.domain.{BlockchainImpl, Receipt}
4+
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation}
65
import io.iohk.ethereum.txExecTest.util.FixtureProvider
76
import io.iohk.ethereum.utils.Config
87
import org.scalatest.flatspec.AnyFlatSpec
98
import org.scalatest.matchers.should.Matchers
109

11-
import scala.concurrent.ExecutionContext
12-
1310
class ContractTest extends AnyFlatSpec with Matchers {
1411
val blockchainConfig = Config.blockchains.blockchainConfig
1512
val syncConfig = Config.SyncConfig(Config.config)
16-
val vm = new Ledger.VMImpl
17-
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
1813
val noErrors = a[Right[_, Seq[Receipt]]]
1914

2015
"Ledger" should "execute and validate" in new ScenarioSetup {
2116
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
22-
val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)
17+
lazy val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)
18+
19+
override lazy val blockchain = BlockchainImpl(testBlockchainStorages)
2320

2421
//block only with ether transfers
2522
val blockValidation = new BlockValidation(consensus, blockchain, BlockQueue(blockchain, syncConfig))

src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import java.util.concurrent.Executors
4-
import io.iohk.ethereum.domain.{Address, BlockchainImpl, Receipt, UInt256}
5-
import io.iohk.ethereum.ledger._
3+
import io.iohk.ethereum.domain.{Address, Receipt, UInt256}
4+
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation}
65
import io.iohk.ethereum.txExecTest.util.FixtureProvider
76
import io.iohk.ethereum.utils.{BlockchainConfig, ForkBlockNumbers, MonetaryPolicyConfig}
87
import org.scalatest.flatspec.AnyFlatSpec
98
import org.scalatest.matchers.should.Matchers
109

11-
import scala.concurrent.ExecutionContext
12-
1310
class ECIP1017Test extends AnyFlatSpec with Matchers {
1411

1512
val EraDuration = 3
@@ -53,13 +50,9 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
5350
gasTieBreaker = false,
5451
treasuryAddress = Address(0)
5552
)
56-
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
57-
5853
val noErrors = a[Right[_, Seq[Receipt]]]
5954
}
6055

61-
val vm = new Ledger.VMImpl
62-
6356
/**
6457
* Tests the block reward calculation through out all the monetary policy through all the eras till block
6558
* mining reward goes to zero. Block mining reward is tested till era 200 (that starts at block number 602)
@@ -72,11 +65,9 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
7265
val startBlock = 1
7366
val endBlock = 602
7467

75-
protected val testBlockchainStorages = FixtureProvider.prepareStorages(startBlock, fixtures)
68+
protected val testBlockchainStorages = FixtureProvider.prepareStorages(endBlock, fixtures)
7669

7770
(startBlock to endBlock) foreach { blockToExecute =>
78-
val storages = FixtureProvider.prepareStorages(blockToExecute - 1, fixtures)
79-
val blockchain = BlockchainImpl(storages)
8071
val blockValidation = new BlockValidation(consensus, blockchain, BlockQueue(blockchain, syncConfig))
8172
val blockExecution = new BlockExecution(
8273
blockchain,

src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import java.util.concurrent.Executors
4-
import io.iohk.ethereum.domain.{Address, BlockchainImpl, Receipt, UInt256}
3+
import io.iohk.ethereum.domain.{Address, Receipt, UInt256}
54
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation}
65
import io.iohk.ethereum.txExecTest.util.FixtureProvider
76
import io.iohk.ethereum.utils.{BlockchainConfig, ForkBlockNumbers, MonetaryPolicyConfig}
87
import org.scalatest.flatspec.AnyFlatSpec
98
import org.scalatest.matchers.should.Matchers
109

11-
import scala.concurrent.ExecutionContext
12-
13-
// scalastyle:off magic.number
1410
class ForksTest extends AnyFlatSpec with Matchers {
1511

1612
trait TestSetup extends ScenarioSetup {
@@ -52,9 +48,7 @@ class ForksTest extends AnyFlatSpec with Matchers {
5248
ethCompatibleStorage = true,
5349
treasuryAddress = Address(0)
5450
)
55-
5651
val noErrors = a[Right[_, Seq[Receipt]]]
57-
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
5852
}
5953

6054
"Ledger" should "execute blocks with respect to forks" in new TestSetup {
@@ -63,11 +57,9 @@ class ForksTest extends AnyFlatSpec with Matchers {
6357
val startBlock = 1
6458
val endBlock = 11
6559

66-
protected val testBlockchainStorages = FixtureProvider.prepareStorages(startBlock, fixtures)
60+
protected val testBlockchainStorages = FixtureProvider.prepareStorages(endBlock, fixtures)
6761

6862
(startBlock to endBlock) foreach { blockToExecute =>
69-
val storages = FixtureProvider.prepareStorages(blockToExecute - 1, fixtures)
70-
val blockchain = BlockchainImpl(storages)
7163
val blockValidation = new BlockValidation(consensus, blockchain, BlockQueue(blockchain, syncConfig))
7264
val blockExecution = new BlockExecution(
7365
blockchain,
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import io.iohk.ethereum.blockchain.sync
3+
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
44
import io.iohk.ethereum.domain.{BlockchainImpl, BlockchainStorages}
55
import io.iohk.ethereum.ledger.Ledger.VMImpl
66

7-
trait ScenarioSetup extends sync.ScenarioSetup {
7+
trait ScenarioSetup extends EphemBlockchainTestSetup {
88
protected val testBlockchainStorages: BlockchainStorages
9-
109
override lazy val blockchain: BlockchainImpl = BlockchainImpl(testBlockchainStorages)
1110
override lazy val vm: VMImpl = new VMImpl
1211
}

src/it/scala/io/iohk/ethereum/txExecTest/util/FixtureProvider.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ object FixtureProvider {
205205
)
206206
}
207207

208-
private def withClose[A, B <: Closeable](closeable: B)(f: B => A): A = try { f(closeable) }
209-
finally { closeable.close() }
208+
private def withClose[A, B <: Closeable](closeable: B)(f: B => A): A = {
209+
try { f(closeable) }
210+
finally { closeable.close() }
211+
}
210212
}

src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncSpec.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import akka.testkit.TestActor.AutoPilot
88
import akka.testkit.{TestKit, TestProbe}
99
import akka.util.ByteString
1010
import io.iohk.ethereum.blockchain.sync.StateSyncUtils.{MptNodeData, TrieProvider}
11-
import io.iohk.ethereum.blockchain.sync.fast.SyncStateSchedulerActor._
1211
import io.iohk.ethereum.blockchain.sync.fast.{SyncStateScheduler, SyncStateSchedulerActor}
1312
import io.iohk.ethereum.blockchain.sync.fast.SyncStateSchedulerActor.{
1413
RestartRequested,
@@ -17,7 +16,6 @@ import io.iohk.ethereum.blockchain.sync.fast.SyncStateSchedulerActor.{
1716
StateSyncStats,
1817
WaitingForNewTargetBlock
1918
}
20-
import io.iohk.ethereum.db.dataSource.RocksDbDataSource.IterationError
2119
import io.iohk.ethereum.domain.{Address, BlockchainImpl, ChainWeight}
2220
import io.iohk.ethereum.network.EtcPeerManagerActor._
2321
import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.MessageFromPeer
@@ -28,7 +26,6 @@ import io.iohk.ethereum.network.{Peer, PeerId}
2826
import io.iohk.ethereum.utils.Config
2927
import io.iohk.ethereum.{Fixtures, ObjectGenerators, WithActorSystemShutDown}
3028
import monix.execution.Scheduler
31-
import monix.reactive.Observable
3229
import org.scalactic.anyvals.PosInt
3330
import org.scalatest.BeforeAndAfterAll
3431
import org.scalatest.flatspec.AnyFlatSpecLike
@@ -154,7 +151,7 @@ class StateSyncSpec
154151
bestBlockHash = peerStatus.bestHash
155152
)
156153

157-
val trieProvider = new TrieProvider(blockchain, storagesInstance.storages.evmCodeStorage, blockchainConfig)
154+
val trieProvider = new TrieProvider(blockchain, getNewStorages.storages.evmCodeStorage, blockchainConfig)
158155

159156
val peersMap = (1 to 8).map { i =>
160157
(

src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object StateSyncUtils extends EphemBlockchainTestSetup {
3333

3434
def buildWorld(accountData: Seq[MptNodeData], existingTree: Option[ByteString] = None): ByteString = {
3535
val init = InMemoryWorldStateProxy(
36-
storagesInstance.storages.evmCodeStorage,
36+
evmCodeStorage,
3737
blockchain.getBackingStorage(1),
3838
blockchain,
3939
blockchainConfig.accountStartNonce,

src/test/scala/io/iohk/ethereum/blockchain/sync/SyncSchedulerStateSpec.scala

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/test/scala/io/iohk/ethereum/consensus/pow/PoWConsensusSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class PoWConsensusSpec
129129
powConsensus.minerCoordinatorRef.isDefined shouldBe true
130130
}
131131

132-
trait TestSetup extends ScenarioSetup with MockFactory {
132+
trait TestSetup extends EphemBlockchainTestSetup with MockFactory {
133133
override lazy val blockchain: BlockchainImpl = mock[BlockchainImpl]
134134
val evmCodeStorage: EvmCodeStorage = mock[EvmCodeStorage]
135135
val validator: ValidatorsExecutor = successValidators.asInstanceOf[ValidatorsExecutor]

src/test/scala/io/iohk/ethereum/ledger/BlockValidationSpec.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,35 @@ import org.scalatest.wordspec.AnyWordSpec
1111
import io.iohk.ethereum.utils.ByteStringUtils._
1212

1313
class BlockValidationSpec extends AnyWordSpec with Matchers with MockFactory {
14+
import BlockValidationTestSetup._
1415

1516
"BlockValidation" should {
1617
"validate block after execution" when {
17-
"report valid results from execution as correct" in new BlockValidationTestSetup {
18+
"report valid results from execution as correct" in {
1819
blockValidation.validateBlockAfterExecution(block, stateRootHash, receipts, gasUsed) shouldBe Right(
1920
BlockExecutionSuccess
2021
)
2122
}
2223

23-
"report as invalid a block that doesn't have the correct gas used" in new BlockValidationTestSetup {
24+
"report as invalid a block that doesn't have the correct gas used" in {
2425
val invalidGasUsed: BigInt = gasUsed + 1
2526
blockValidation.validateBlockAfterExecution(block, stateRootHash, receipts, invalidGasUsed).isLeft shouldBe true
2627
}
2728

28-
"report as invalid a block that doesn't have the correct state root hash" in new BlockValidationTestSetup {
29+
"report as invalid a block that doesn't have the correct state root hash" in {
2930
val invalidStateRootHash: ByteString = concatByteStrings((stateRootHash.head + 1).toByte, stateRootHash.tail)
3031
blockValidation.validateBlockAfterExecution(block, invalidStateRootHash, receipts, gasUsed).isLeft shouldBe true
3132
}
3233

33-
"report as invalid a block that doesn't have the correct receipts information" in new BlockValidationTestSetup {
34+
"report as invalid a block that doesn't have the correct receipts information" in {
3435
val invalidReceipts: Seq[Receipt] = Seq.empty[Receipt]
3536
blockValidation.validateBlockAfterExecution(block, stateRootHash, invalidReceipts, gasUsed).isLeft shouldBe true
3637
}
3738
}
3839
}
3940

4041
// scalastyle:off magic.number
41-
trait BlockValidationTestSetup {
42+
object BlockValidationTestSetup {
4243
private val setup = new io.iohk.ethereum.blockchain.sync.ScenarioSetup {
4344
override lazy val blockchain: BlockchainImpl = mock[BlockchainImpl]
4445

src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ trait TestSetupWithVmAndValidators extends EphemBlockchainTestSetup {
268268

269269
implicit val schedulerContext: Scheduler = Scheduler.fixedPool("ledger-test-pool", 4)
270270

271-
class FailingTestLedgerImpl(validators: Validators)(implicit testContext: Scheduler)
271+
class TestLedgerImplNotMockedBlockExecution(validators: Validators)(implicit testContext: Scheduler)
272272
extends LedgerImpl(
273273
blockchain,
274274
storagesInstance.storages.evmCodeStorage,
@@ -314,7 +314,7 @@ trait TestSetupWithVmAndValidators extends EphemBlockchainTestSetup {
314314
}
315315

316316
override lazy val ledger = new TestLedgerImpl(successValidators)
317-
lazy val failingLedger = new FailingTestLedgerImpl(successValidators)
317+
lazy val failingLedger = new TestLedgerImplNotMockedBlockExecution(successValidators)
318318

319319
def randomHash(): ByteString =
320320
ObjectGenerators.byteStringOfLengthNGen(32).sample.get

0 commit comments

Comments
 (0)