Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use the 'org.web3j.solidity' Gradle plugin to compile contracts #14361

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ bld/
[Oo]bj/
[Ll]og/
[Ll]ogs/
!hedera-node/test-clients/src/main/solidity/Logs

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
org.gradle.jvmargs=-Xmx6144m -Dfile.encoding=UTF-8

# Enable Gradle caching
org.gradle.configuration-cache=true
# org.gradle.configuration-cache=true
org.gradle.caching=true

# Enable parallel workers
Expand Down
1 change: 1 addition & 0 deletions gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ dependencies {
implementation("org.gradlex:extra-java-module-info:1.9")
implementation("org.gradlex:jvm-dependency-conflict-resolution:2.1.2")
implementation("org.gradlex:java-module-dependencies:1.7.1")
implementation("org.web3j.solidity:solidity-gradle-plugin:0.5.1")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (C) 2022-2024 Hiero a Series of LF Projects, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.gradle.tasks

import javax.inject.Inject
import org.gradle.StartParameter
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.process.ExecOperations

@Suppress("LeakingThis")
abstract class GitClone : DefaultTask() {

@get:Input abstract val url: Property<String>

@get:Input @get:Optional abstract val tag: Property<String>

@get:Input @get:Optional abstract val branch: Property<String>

@get:Input abstract val offline: Property<Boolean>

@get:OutputDirectory abstract val localCloneDirectory: DirectoryProperty

@get:Inject protected abstract val exec: ExecOperations

@get:Inject protected abstract val startParameter: StartParameter

@get:Inject protected abstract val layout: ProjectLayout

init {
offline.set(startParameter.isOffline)
localCloneDirectory.set(layout.buildDirectory.dir("hedera-protobufs"))
// If a 'branch' is configured, the task is never up-to-date as it may change
outputs.upToDateWhen { !branch.isPresent }
}

@TaskAction
fun cloneOrUpdate() {
if (!tag.isPresent && !branch.isPresent || tag.isPresent && branch.isPresent) {
throw RuntimeException("Define either 'tag' or 'branch'")
}

val localClone = localCloneDirectory.get()
if (!offline.get()) {
exec.exec {
if (!localClone.dir(".git").asFile.exists()) {
workingDir = localClone.asFile.parentFile
commandLine("git", "clone", url.get(), "-q")
} else {
workingDir = localClone.asFile
commandLine("git", "fetch", "-q")
}
}
}
if (tag.isPresent) {
exec.exec {
workingDir = localClone.asFile
commandLine("git", "checkout", tag.get(), "-q")
}
exec.exec {
workingDir = localClone.asFile
commandLine("git", "reset", "--hard", tag.get(), "-q")
}
} else {
exec.exec {
workingDir = localClone.asFile
commandLine("git", "checkout", branch.get(), "-q")
}
exec.exec {
workingDir = localClone.asFile
commandLine("git", "reset", "--hard", "origin/${branch.get()}", "-q")
}
}
}
}
58 changes: 58 additions & 0 deletions hedera-node/test-clients/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.hedera.gradle.tasks.GitClone
import org.web3j.solidity.gradle.plugin.EVMVersion
import org.web3j.solidity.gradle.plugin.OutputComponent
import org.web3j.solidity.gradle.plugin.SolidityCompile
import org.web3j.solidity.gradle.plugin.SolidityResolve
import org.web3j.solidity.gradle.plugin.SoliditySourceSet

plugins {
id("com.hedera.gradle.services")
id("com.hedera.gradle.shadow-jar")
id("org.web3j.solidity")
}

description = "Hedera Services Test Clients for End to End Tests (EET)"
Expand All @@ -32,6 +39,57 @@ mainModuleInfo {

testModuleInfo { runtimeOnly("org.junit.jupiter.api") }

// Clone 'hedera-smart-contracts' to obtain system contracts
val cloneSmartContracts =
tasks.register<GitClone>("cloneSmartContracts") {
offline = gradle.startParameter.isOffline
url = "https://github.com/hashgraph/hedera-smart-contracts.git"
localCloneDirectory = layout.buildDirectory.dir("hedera-smart-contracts")
tag = "v0.10.1"
}

// General solidity configuration
solidity {
setCombinedOutputComponents()
setOutputComponents(OutputComponent.BIN, OutputComponent.ABI)
// evmVersion = EVMVersion.CANCUN
prettyJson = true
optimize = false
allowPaths.add(layout.projectDirectory.dir("src/main/solidity").asFile.absolutePath)
allowPaths.add(
layout.buildDirectory
.dir("hedera-smart-contracts/contracts/system-contracts")
.get()
.asFile
.absolutePath
)
}

sourceSets.main {
withConvention(SoliditySourceSet::class) {
solidity {
destinationDirectory = layout.buildDirectory.dir("generated/solidity")
// TODO remove this filtering and make all 'sol' files compile
include("AddressValueRet/*")
include("Returner.abi/*")
include("Placeholder/*")
}
}
}

tasks.withType<SolidityResolve>().configureEach {
inputs.dir(cloneSmartContracts.flatMap { it.localCloneDirectory })
}

tasks.withType<SolidityCompile>().configureEach {
inputs.dir(cloneSmartContracts.flatMap { it.localCloneDirectory })
}

tasks.processResources { from(tasks.named("compileSolidity")) { into("contract/contracts") } }

// TODO register separate SolidityCompile - complete configuration of task
tasks.register<SolidityCompile>("compileSolidityParis") { evmVersion = EVMVersion.PARIS }

sourceSets {
create("rcdiff")
create("yahcli")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
import org.json.JSONTokener;

public class Utils {
public static final String RESOURCE_PATH = "src/main/resources/contract/contracts/%1$s/%1$s%2$s";
public static final String RESOURCE_PATH = "src/main/solidity/%1$s/%1$s%2$s";

public static final String UNIQUE_CLASSPATH_RESOURCE_TPL = "contract/contracts/%s/%s";
public static final String UNIQUE_CLASSPATH_RESOURCE_TPL = "contract/contracts/%s";
private static final Logger log = LogManager.getLogger(Utils.class);
private static final String JSON_EXTENSION = ".json";
private static final String JSON_EXTENSION = ".abi";

public static ByteString eventSignatureOf(String event) {
return ByteString.copyFrom(Hash.keccak256(Bytes.wrap(event.getBytes())).toArray());
Expand Down Expand Up @@ -192,8 +192,7 @@ public static String getABIFor(final FunctionType type, final String functionNam

public static String getResourceABIFor(
final FunctionType type, final String functionName, final String contractName) {
final var resourcePath =
String.format(UNIQUE_CLASSPATH_RESOURCE_TPL, contractName, contractName + JSON_EXTENSION);
final var resourcePath = String.format(UNIQUE_CLASSPATH_RESOURCE_TPL, contractName + JSON_EXTENSION);
try (final var input = Utils.class.getClassLoader().getResourceAsStream(resourcePath)) {
return getFunctionAbiFrom(input, functionName, type);
} catch (final IOException e) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading