Skip to content

Commit 282fe72

Browse files
Merge pull request #342 from chippr-robotics/copilot/un-ignore-test-failures
Investigate 6 ignored test failures from Scala 3 migration
2 parents 7812592 + 41a6a2b commit 282fe72

File tree

7 files changed

+42
-27
lines changed

7 files changed

+42
-27
lines changed

build.sbt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,21 @@ lazy val node = {
284284
(Compile / buildInfoOptions) += BuildInfoOption.ToMap,
285285
// Temporarily exclude test files with MockFactory compilation issues (Scala 3 migration)
286286
// These files need additional refactoring to work with Scala 3's MockFactory self-type requirements
287+
// Un-ignored 6 priority tests per issue to identify failure causes.
288+
// 2 tests fixed and compile successfully: OmmersPoolSpec, RLPxConnectionHandlerSpec
289+
// 4 tests have MockBlockchain/MockFactory Scala 3 incompatibility and need architectural changes
287290
(Test / excludeFilter) := {
288291
val base = (Test / excludeFilter).value
289292
base ||
290-
"RLPxConnectionHandlerSpec.scala" ||
291-
"OmmersPoolSpec.scala" ||
293+
"BranchResolutionSpec.scala" ||
292294
"ConsensusAdapterSpec.scala" ||
293295
"ConsensusImplSpec.scala" ||
296+
"FastSyncBranchResolverActorSpec.scala" ||
294297
"PoWMiningCoordinatorSpec.scala" ||
295298
"PoWMiningSpec.scala" ||
296299
"EthashMinerSpec.scala" ||
297300
"KeccakMinerSpec.scala" ||
298301
"MockedMinerSpec.scala" ||
299-
"BranchResolutionSpec.scala" ||
300-
"FastSyncBranchResolverActorSpec.scala" ||
301302
"MessageHandlerSpec.scala" ||
302303
"BlockExecutionSpec.scala" ||
303304
"QaJRCSpec.scala" ||

src/test/scala/com/chipprbots/ethereum/blockchain/sync/fast/FastSyncBranchResolverActorSpec.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class FastSyncBranchResolverActorSpec
6060
"fetch headers from the new master peer" - {
6161
"the chain is repaired from the first request to the new master pair and then the last two blocks are removed" in new TestSetup {
6262
implicit override lazy val system = self.system
63-
implicit val ioRuntime: IORuntime = IORuntime.global
63+
implicit override lazy val ioRuntime: IORuntime = IORuntime.global
6464

6565
val sender = TestProbe("sender")
6666

@@ -107,7 +107,7 @@ class FastSyncBranchResolverActorSpec
107107
"The chain is repaired doing binary searching with the new master peer and then remove the last invalid blocks" - {
108108
"highest common block is in the middle" in new TestSetup {
109109
implicit override lazy val system = self.system
110-
implicit val ioRuntime: IORuntime = IORuntime.global
110+
implicit override lazy val ioRuntime: IORuntime = IORuntime.global
111111

112112
val sender = TestProbe("sender")
113113

@@ -144,7 +144,7 @@ class FastSyncBranchResolverActorSpec
144144
}
145145
"highest common block is in the first half" in new TestSetup {
146146
implicit override lazy val system = self.system
147-
implicit val ioRuntime: IORuntime = IORuntime.global
147+
implicit override lazy val ioRuntime: IORuntime = IORuntime.global
148148

149149
val sender = TestProbe("sender")
150150

@@ -183,7 +183,7 @@ class FastSyncBranchResolverActorSpec
183183

184184
"highest common block is in the second half" in new TestSetup {
185185
implicit override lazy val system = self.system
186-
implicit val ioRuntime: IORuntime = IORuntime.global
186+
implicit override lazy val ioRuntime: IORuntime = IORuntime.global
187187

188188
val sender = TestProbe("sender")
189189

@@ -222,7 +222,7 @@ class FastSyncBranchResolverActorSpec
222222

223223
"No common block is found" in new TestSetup {
224224
implicit override lazy val system = self.system
225-
implicit val ioRuntime: IORuntime = IORuntime.global
225+
implicit override lazy val ioRuntime: IORuntime = IORuntime.global
226226

227227
val sender = TestProbe("sender")
228228

src/test/scala/com/chipprbots/ethereum/consensus/ConsensusAdapterSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,6 @@ class ConsensusAdapterSpec extends AnyFlatSpec with Matchers with ScalaFutures w
544544
blockchainReader.getBestBlock().get shouldEqual checkpointBlock
545545
}
546546

547-
trait ImportBlockTestSetup extends TestSetupWithVmAndValidators with MockBlockchain
547+
trait ImportBlockTestSetup extends TestSetupWithVmAndValidators with MockBlockchain with org.scalamock.scalatest.MockFactory
548548

549549
}

src/test/scala/com/chipprbots/ethereum/consensus/ConsensusImplSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ object ConsensusImplSpec {
8686
val initialBestBlock = initialChain.last
8787

8888
abstract class ConsensusSetup {
89-
private val testSetup = new EphemBlockchainTestSetup with MockFactory with org.scalatest.TestSuite {
89+
private val testSetup = new EphemBlockchainTestSetup with MockFactory {
9090
override lazy val blockExecution: BlockExecution = stub[BlockExecution]
9191
(blockExecution
9292
.executeAndValidateBlocks(_: List[Block], _: ChainWeight)(_: BlockchainConfig))

src/test/scala/com/chipprbots/ethereum/ledger/LedgerTestSetup.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ trait TestSetupWithVmAndValidators extends EphemBlockchainTestSetup {
303303
lazy val blockQueue: BlockQueue
304304

305305
implicit override lazy val ioRuntime: IORuntime = IORuntime.global
306-
// Provide runtimeContext as alias for compatibility
307-
implicit def runtimeContext: IORuntime = ioRuntime
308306

309307
override lazy val consensusAdapter: ConsensusAdapter = mkConsensus()
310308

@@ -434,7 +432,7 @@ trait TestSetupWithVmAndValidators extends EphemBlockchainTestSetup {
434432
// Using the global IORuntime is appropriate here because, in test scenarios,
435433
// validation operations do not require a custom runtime with specific threading characteristics.
436434
// Tests are typically run in isolation, so contention and performance concerns are minimal.
437-
runtimeContext
435+
ioRuntime
438436
)
439437
}
440438
}
@@ -493,7 +491,7 @@ trait MockBlockchain { self: TestSetupWithVmAndValidators with org.scalamock.sca
493491
(() => blockchainReader.genesisHeader).expects().returning(header)
494492
}
495493

496-
trait EphemBlockchain extends TestSetupWithVmAndValidators { self: org.scalamock.scalatest.MockFactory =>
494+
trait EphemBlockchain extends TestSetupWithVmAndValidators {
497495
override lazy val blockQueue: BlockQueue = BlockQueue(blockchainReader, SyncConfig(Config.config))
498496

499497
def blockImportWithMockedBlockExecution(blockExecutionMock: BlockExecution): ConsensusAdapter =
@@ -507,7 +505,7 @@ trait CheckpointHelpers {
507505
new CheckpointBlockGenerator().generate(parent, checkpoint)
508506
}
509507

510-
trait OmmersTestSetup extends EphemBlockchain { self: org.scalamock.scalatest.MockFactory =>
508+
trait OmmersTestSetup extends EphemBlockchain {
511509
object OmmerValidation extends Mocks.MockValidatorsAlwaysSucceed {
512510
override val ommersValidator: OmmersValidator =
513511
new StdOmmersValidator(blockHeaderValidator)

src/test/scala/com/chipprbots/ethereum/network/rlpx/RLPxConnectionHandlerSpec.scala

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import com.chipprbots.ethereum.security.SecureRandomBuilder
3333
import org.scalatest.Ignore
3434

3535
// SCALA 3 MIGRATION: Fixed by creating manual stub implementation for AuthHandshaker
36-
@Ignore
36+
// @Ignore - Un-ignored per issue to identify test failures
3737
class RLPxConnectionHandlerSpec
3838
extends TestKit(ActorSystem("RLPxConnectionHandlerSpec_System"))
3939
with AnyFlatSpecLike
@@ -192,8 +192,11 @@ class RLPxConnectionHandlerSpec
192192
rlpxConnectionParent.expectTerminated(rlpxConnection)
193193
}
194194

195+
// SCALA 3 MIGRATION: Removed self-type constraint `this: org.scalamock.scalatest.MockFactory =>`
196+
// because Scala 3 doesn't allow instantiating TestSetup with `new TestSetup` when the self-type
197+
// is present, even though the outer class (RLPxConnectionHandlerSpec) extends MockFactory.
198+
// The mock functionality still works because the outer class provides MockFactory.
195199
trait TestSetup extends SecureRandomBuilder {
196-
this: org.scalamock.scalatest.MockFactory =>
197200

198201
// Mock parameters for RLPxConnectionHandler
199202
val mockMessageDecoder: MessageDecoder = new MessageDecoder {
@@ -205,13 +208,13 @@ class RLPxConnectionHandlerSpec
205208
val connection: TestProbe = TestProbe()
206209
val mockMessageCodec: MessageCodec = mock[MessageCodec]
207210
val mockHelloExtractor: HelloCodec = mock[HelloCodec]
208-
211+
209212
private def createStubAuthHandshaker(): AuthHandshaker = {
210213
import java.security.SecureRandom
211214
import com.chipprbots.ethereum.crypto.generateKeyPair
212-
215+
213216
val sr = new SecureRandom()
214-
217+
215218
AuthHandshaker(
216219
nodeKey = generateKeyPair(sr),
217220
nonce = ByteString.empty,
@@ -268,11 +271,21 @@ class RLPxConnectionHandlerSpec
268271
.expects(data)
269272
// MIGRATION: Scala 3 requires explicit type ascription for mock with complex parameterized types
270273
// Create a minimal Secrets instance for test purposes
271-
.returning((response, AuthHandshakeSuccess(
272-
new Secrets(Array.emptyByteArray, Array.emptyByteArray, Array.emptyByteArray,
273-
new org.bouncycastle.crypto.digests.KeccakDigest(256),
274-
new org.bouncycastle.crypto.digests.KeccakDigest(256)),
275-
ByteString())))
274+
.returning(
275+
(
276+
response,
277+
AuthHandshakeSuccess(
278+
new Secrets(
279+
Array.emptyByteArray,
280+
Array.emptyByteArray,
281+
Array.emptyByteArray,
282+
new org.bouncycastle.crypto.digests.KeccakDigest(256),
283+
new org.bouncycastle.crypto.digests.KeccakDigest(256)
284+
),
285+
ByteString()
286+
)
287+
)
288+
)
276289
(mockHelloExtractor.readHello _)
277290
.expects(ByteString.empty)
278291
.returning(Some((Hello(5, "", Capability.ETH63 :: Nil, 30303, ByteString("abc")), Seq.empty)))

src/test/scala/com/chipprbots/ethereum/ommers/OmmersPoolSpec.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ class OmmersPoolSpec
125125
}
126126
}
127127

128+
// SCALA 3 MIGRATION: Removed self-type constraint `this: org.scalamock.scalatest.MockFactory =>`
129+
// because Scala 3 doesn't allow instantiating TestSetup with `new TestSetup` when the self-type
130+
// is present, even though the outer class (OmmersPoolSpec) extends MockFactory.
131+
// The mock functionality still works because the outer class provides MockFactory.
128132
trait TestSetup {
129-
this: org.scalamock.scalatest.MockFactory =>
130133

131134
// In order to support all the blocks for the given scenarios
132135
val ommersPoolSize: Int = 8

0 commit comments

Comments
 (0)