Skip to content

Commit f4287e4

Browse files
Fix JsonRpcControllerFixture Scala 3 MockFactory compatibility
- Converted JsonRpcControllerFixture to accept implicit MockFactory parameter - Created JsonRpcControllerTestSupport trait for test specs to provide implicit MockFactory - Updated all JsonRpcController test specs to extend JsonRpcControllerTestSupport - Fixed validators mock expectation setup to work with imported MockFactory context - Resolved all 202 JsonRpcControllerFixture compilation errors The solution uses a factory pattern where the test spec (which extends MockFactory and TestSuite) provides itself as an implicit MockFactory to the fixture. This works around Scala 3's limitation where anonymous classes created by 'new' don't automatically satisfy MockFactory's TestSuite self-type requirement. Co-authored-by: realcodywburns <13103499+realcodywburns@users.noreply.github.com>
1 parent 3f160b9 commit f4287e4

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

src/test/scala/com/chipprbots/ethereum/jsonrpc/JsonRpcControllerEthLegacyTransactionSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class JsonRpcControllerEthLegacyTransactionSpec
4242
with Matchers
4343
with JRCMatchers
4444
with org.scalamock.scalatest.MockFactory
45+
with JsonRpcControllerTestSupport
4546
with ScalaCheckPropertyChecks
4647
with ScalaFutures
4748
with LongPatience

src/test/scala/com/chipprbots/ethereum/jsonrpc/JsonRpcControllerEthSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class JsonRpcControllerEthSpec
5959
with JRCMatchers
6060
with ScalaCheckPropertyChecks
6161
with org.scalamock.scalatest.MockFactory
62+
with JsonRpcControllerTestSupport
6263
with ScalaFutures
6364
with LongPatience
6465
with Eventually {

src/test/scala/com/chipprbots/ethereum/jsonrpc/JsonRpcControllerFixture.scala

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,23 @@ import com.chipprbots.ethereum.nodebuilder.ApisBuilder
4040
import com.chipprbots.ethereum.utils.Config
4141
import com.chipprbots.ethereum.utils.FilterConfig
4242

43-
class JsonRpcControllerFixture(implicit system: ActorSystem)
43+
/** Factory for creating JsonRpcControllerFixture instances with mocks.
44+
* This is needed because in Scala 3, MockFactory requires TestSuite self-type,
45+
* which anonymous classes created by 'new' don't satisfy.
46+
*/
47+
object JsonRpcControllerFixture {
48+
def apply()(implicit system: ActorSystem, mockFactory: org.scalamock.scalatest.MockFactory): JsonRpcControllerFixture = {
49+
new JsonRpcControllerFixture()(system, mockFactory)
50+
}
51+
}
52+
53+
class JsonRpcControllerFixture(implicit system: ActorSystem, mockFactory: org.scalamock.scalatest.MockFactory)
4454
extends EphemBlockchainTestSetup
4555
with JsonMethodsImplicits
46-
with ApisBuilder
47-
with org.scalamock.scalatest.MockFactory {
56+
with ApisBuilder {
57+
58+
// Import all mockFactory members to enable mock creation and expectations
59+
import mockFactory._
4860

4961
def config: JsonRpcConfig = JsonRpcConfig(Config.config, available)
5062

@@ -61,11 +73,14 @@ class JsonRpcControllerFixture(implicit system: ActorSystem)
6173
val syncingController: TestProbe = TestProbe()
6274

6375
override lazy val stxLedger: StxLedger = mock[StxLedger]
64-
override lazy val validators: ValidatorsExecutor = mock[ValidatorsExecutor]
65-
(() => validators.signedTransactionValidator)
66-
.expects()
67-
.returns(null)
68-
.anyNumberOfTimes()
76+
override lazy val validators: ValidatorsExecutor = {
77+
val v = mock[ValidatorsExecutor]
78+
(() => v.signedTransactionValidator)
79+
.expects()
80+
.returns(null)
81+
.anyNumberOfTimes()
82+
v
83+
}
6984

7085
override lazy val mining: TestMining = buildTestMining()
7186
.withValidators(validators)

src/test/scala/com/chipprbots/ethereum/jsonrpc/JsonRpcControllerPersonalSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class JsonRpcControllerPersonalSpec
3535
with Matchers
3636
with JRCMatchers
3737
with org.scalamock.scalatest.MockFactory
38+
with JsonRpcControllerTestSupport
3839
with ScalaCheckPropertyChecks
3940
with ScalaFutures
4041
with LongPatience

src/test/scala/com/chipprbots/ethereum/jsonrpc/JsonRpcControllerSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class JsonRpcControllerSpec
4545
with Matchers
4646
with JRCMatchers
4747
with org.scalamock.scalatest.MockFactory
48+
with JsonRpcControllerTestSupport
4849
with ScalaCheckPropertyChecks
4950
with ScalaFutures
5051
with LongPatience
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.chipprbots.ethereum.jsonrpc
2+
3+
import org.scalamock.scalatest.MockFactory
4+
5+
/** Support trait for JsonRpcController tests that use JsonRpcControllerFixture.
6+
*
7+
* In Scala 3, MockFactory requires TestSuite self-type, which anonymous classes
8+
* created by 'new JsonRpcControllerFixture' don't satisfy. This trait provides
9+
* the test spec itself as an implicit MockFactory so that JsonRpcControllerFixture
10+
* can delegate mock creation to the test spec.
11+
*
12+
* Usage: Mix this trait into test specs that use JsonRpcControllerFixture.
13+
*/
14+
trait JsonRpcControllerTestSupport { self: MockFactory =>
15+
implicit protected def mockFactoryProvider: MockFactory = this
16+
}

0 commit comments

Comments
 (0)