import java.time.LocalTime

/*
 * Copyright Consensys Software Inc.
 *
 * This file is dual-licensed under either the MIT license or Apache License 2.0.
 * See the LICENSE-MIT and LICENSE-APACHE files in the repository root for details.
 *
 * SPDX-License-Identifier: MIT OR Apache-2.0
 */

plugins {
  alias(libs.plugins.web3j)
  alias(libs.plugins.web3jSolidity)
  alias(libs.plugins.lombok)
  alias(libs.plugins.gradleVersions)
  alias(libs.plugins.dependencyManagement)
  alias(libs.plugins.download)
}

def lineaSequencerProject = project(lineaSequencerProjectPath)
apply from: lineaSequencerProject.file("gradle/java.gradle")
apply from: lineaSequencerProject.file("gradle/dependency-management.gradle")
apply from: lineaSequencerProject.file('gradle/common-dependencies.gradle')
apply from: lineaSequencerProject.file("gradle/lint.gradle")

web3j {
  generatedPackageName = 'linea.plugin.acc.test.tests.web3j.generated'
}

solidity {
  resolvePackages = false
  optimizeRuns = 1
  // TODO: remove the forced version, when DEV network is upgraded to support latest forks
  version '0.8.19'
}

processTestResources.dependsOn("${lineaSequencerProjectPath}:acceptance-tests:generateTestContractWrappers")

tasks.register('acceptanceTests', Test) {
  description = 'Runs acceptance tests.'

  inputs.property("integration.date", LocalTime.now()) // so it runs on every invocation

  useJUnitPlatform {
    includeTags("AcceptanceTest")
  }

  // Configure resource limits
  boolean isCiServer = System.getenv().containsKey("CI")
  maxParallelForks = isCiServer ? Runtime.runtime.availableProcessors() : 2
  systemProperties["junit.jupiter.execution.parallel.enabled"] = false
}

dependencies {
  annotationProcessor 'org.apache.logging.log4j:log4j-core'

  implementation 'org.apache.logging.log4j:log4j-core'

  testImplementation project("${lineaSequencerProjectPath}:sequencer")

  testImplementation "${besuArtifactGroup}:besu-datatypes"
  testImplementation "${besuArtifactGroup}:besu-evm"
  testImplementation "${besuArtifactGroup}.internal:besu-consensus-clique"
  testImplementation "${besuArtifactGroup}.internal:besu-ethereum-api"
  testImplementation "${besuArtifactGroup}.internal:besu-ethereum-core"
  testImplementation "${besuArtifactGroup}.internal:besu-ethereum-eth"
  testImplementation "${besuArtifactGroup}.internal:besu-acceptance-tests-dsl"
  testImplementation "${besuArtifactGroup}.internal:besu-metrics-core"
  testImplementation "${besuArtifactGroup}.internal:besu-crypto-services"
  testImplementation group: "${besuArtifactGroup}.internal", name: "besu-ethereum-core", classifier: "test-support"

  testImplementation 'net.consensys.linea.zktracer:arithmetization'

  testImplementation 'org.awaitility:awaitility'
}

// Do not run acceptance tests with ./gradlew test, only with ./gradlew acceptanceTests
test.enabled = false

jar {
  enabled = false
}
