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.besuPluginLibrary)
  alias(libs.plugins.web3j)
  alias(libs.plugins.web3jSolidity)
  alias(libs.plugins.lombok)
  alias(libs.plugins.gradleVersions)
  alias(libs.plugins.dependencyManagement)
}

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

compileJava {
  options.annotationProcessorGeneratedSourcesDirectory = file("$buildDir/generated/sources/annotationProcessor/java/main")
  options.compilerArgs += [
    '-Alog4j.graalvm.groupId=' + project.group,
    '-Alog4j.graalvm.artifactId=' + project.name
  ]
}

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 "net.consensys.linea.zktracer:arithmetization:${libs.versions.arithmetization.get()}"

  testImplementation 'org.assertj:assertj-core'

  testImplementation 'org.junit.jupiter:junit-jupiter-api'
  testImplementation 'org.junit.jupiter:junit-jupiter-params'
  testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

  testImplementation "org.wiremock:wiremock:${libs.versions.wiremock.get()}"
}

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

jar {
  enabled = false
}
