Giter Site home page Giter Site logo

hyperledger / web3j-unit Goto Github PK

View Code? Open in Web Editor NEW
23.0 7.0 23.0 1.98 MB

Smart contract testing framework via integrated EVM and various Ethereum clients

Home Page: https://www.web3labs.com/epirus

License: Apache License 2.0

Shell 9.16% Kotlin 68.13% Java 20.56% Solidity 2.15%
blockchain testing web3j ethereum geth parity docker

web3j-unit's Introduction

Web3j-unit Build Status

Web3j-unit is a Junit 5 extension to streamline the creation of Ethereum contract tests.

Multiple Ethereum implementations are supported including Geth and Besu. To run tests built using Web3j-unit, docker is required on the host.

Instances of Web3j, TransactionManager and GasProvider are injected into the Junit runner.

You can find a sample here.

You can find an example using docker-compose here. This spins up VMWare Concord nodes using a docker-compose file.

Getting Started

  1. Add dependency to gradle.
   repositories {
      mavenCentral()
      jcenter()
      maven { url "https://hyperledger.jfrog.io/artifactory/besu-maven/" }
      maven { url "https://artifacts.consensys.net/public/maven/maven/" }
      maven { url "https://splunk.jfrog.io/splunk/ext-releases-local" }
      maven { url "https://dl.cloudsmith.io/public/consensys/quorum-mainnet-launcher/maven/" }
   }

   implementation "org.web3j:core:4.11.3"
   testCompile "org.web3j:web3j-unit:4.11.3"
  1. Create a new test with the @EVMTest annotation. An embedded EVM is used by default. To use Geth or Besu pass the node type into the annotation: @EVMTest(NodeType.GETH) or @EVMTest(NodeType.BESU)
@EVMTest
class GreeterTest {

}
  1. Inject instance of Web3j TransactionManager and ContractGasProvider in your test method.
@EVMTest
class GreeterTest {

    @Test
    fun greeterDeploys(
        web3j: Web3j,
        transactionManager: TransactionManager,
        gasProvider: ContractGasProvider
    ) {}

}
  1. Deploy your contract in the test.
@EVMTest
class GreeterTest {

    @Test
    fun greeterDeploys(
        web3j: Web3j,
        transactionManager: TransactionManager,
        gasProvider: ContractGasProvider
    ) {
        val greeter = Greeter.deploy(web3j, transactionManager, gasProvider, "Hello EVM").send()
        val greeting = greeter.greet().send()
        assertEquals("Hello EVM", greeting)
    }

}
  1. Run the test!

Using a custom docker-compose file

  1. Add dependency to gradle.
  repositories {
     mavenCentral()
     jcenter()
  }

  implementation "org.web3j:core:4.11.3"
  testCompile "org.web3j:web3j-unit:4.11.3"
  1. Create a new test with the @EVMComposeTest annotation. By default, uses test.yml file in the project home, and runs web3j on service name node1 exposing the port 8545. Can be customised to use specific docker-compose file, service name and port by @EVMComposeTest("src/test/resources/geth.yml", "ethnode1", 8080) Here, we connect to the service named ethnode1 in the src/test/resources/geth.yml docker-compose file which exposes the port 8080 for web3j to connect to.
@EVMComposeTest("src/test/resources/geth.yml", "ethnode1", 8080)
class GreeterTest {

}
  1. Inject instance of Web3j TransactionManager and ContractGasProvider in your test method.
@EVMComposeTest("src/test/resources/geth.yml", "ethnode1", 8080)
class GreeterTest {

    @Test
    fun greeterDeploys(
        web3j: Web3j,
        transactionManager: TransactionManager,
        gasProvider: ContractGasProvider
    ) {}

}
  1. Deploy your contract in the test.
@EVMComposeTest("src/test/resources/geth.yml", "ethnode1", 8080)
class GreeterTest {

    @Test
    fun greeterDeploys(
        web3j: Web3j,
        transactionManager: TransactionManager,
        gasProvider: ContractGasProvider
    ) {
        val greeter = Greeter.deploy(web3j, transactionManager, gasProvider, "Hello EVM").send()
        val greeting = greeter.greet().send()
        assertEquals("Hello EVM", greeting)
    }

}
  1. Run the test!

web3j-unit's People

Contributors

cfelde avatar gtebrean avatar iikirilov avatar alexandrour avatar rach-id avatar nicksneo avatar antonydenyer avatar puneetha17 avatar xaviarias avatar andrii-kl avatar conor10 avatar iloomans avatar josh-richardson avatar

Stargazers

Wiseman Lim avatar Tuan Nguyen avatar  avatar Alireza (0xAlireza) avatar Lucas Godoy avatar Darren avatar 白云 avatar  avatar Seiko avatar  avatar Moncef AOUDIA avatar Sergey Chunayev avatar Yekta Sarioglu avatar Huynhanh83 avatar Devin Forder avatar Angel Ortega (he/they) avatar mani avatar  avatar Artur Daveyan avatar Or Noyman avatar Naveen avatar ligi avatar  avatar

Watchers

James Cloos avatar  avatar abhi avatar  avatar Yasser Hassan avatar  avatar  avatar

web3j-unit's Issues

Funding an account in a unit test?

Was trying to figure out a way to test a deposit contract that I am working with, and am getting stumped on how to actually spin up an embedded node with a funded wallet

I'm using a quick helper to give me a generated Credentials object

fun generateCreds(): Credentials {
    val password = UUID.randomUUID().toString()
    val walletDirectory = createTempDir()
    val wallet = WalletUtils.generateNewWalletFile(password, walletDirectory)
    return WalletUtils.loadCredentials(password, File("$walletDirectory/$wallet"))
}

However, this account obviously has a 0 balance... I see there is a way through the genesis file to prefund an address, and I suppose it would be possible to generate a wallet, dictate the desired genesis funding, and then load that wallet explicitly, but I'm wondering if there is a more elegant way that I am missing

Tag 4.5.18

The tag for version 4.5.18 is missing.

Could not find org.hyperledger.besu:*

Could not find org.hyperledger.besu:*

Cannot build project using web3j-unit v4.9.0

Steps To Reproduce

build.gradle

...
repositories {
    google()
    mavenCentral()
}
...
dependencies {
    ... 
    implementation("org.web3j:core:4.9.0")
    implementation("org.web3j:web3j-unit:4.9.0")
    implementation("org.web3j:web3j-evm:4.9.0")
    ...
}

ScTest.java

@Slf4j
@EVMTest
class ScTest {
...
}

Run gradle test

./gradlew :smart-contract:test

Expected behavior

the test has started

Actual behavior

> Task :smart-contract:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':smart-contract:test'.
> Could not resolve all files for configuration ':smart-contract:testRuntimeClasspath'.
   > Could not find org.hyperledger.besu:plugin-api:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/plugin-api/21.7.2/plugin-api-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/plugin-api/21.7.2/plugin-api-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:besu:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/besu/21.7.2/besu-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/besu/21.7.2/besu-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:api:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/api/21.7.2/api-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/api/21.7.2/api-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:config:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/config/21.7.2/config-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/config/21.7.2/config-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:core:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/core/21.7.2/core-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/core/21.7.2/core-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:crypto:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/crypto/21.7.2/crypto-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/crypto/21.7.2/crypto-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:rlp:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/rlp/21.7.2/rlp-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/rlp/21.7.2/rlp-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:kvstore:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/kvstore/21.7.2/kvstore-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/kvstore/21.7.2/kvstore-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:metrics-core:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/metrics-core/21.7.2/metrics-core-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/metrics-core/21.7.2/metrics-core-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:trie:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/trie/21.7.2/trie-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/trie/21.7.2/trie-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu.internal:util:21.7.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/internal/util/21.7.2/util-21.7.2.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/internal/util/21.7.2/util-21.7.2.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu:bls12-381:0.3.0.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/bls12-381/0.3.0/bls12-381-0.3.0.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/bls12-381/0.3.0/bls12-381-0.3.0.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find org.hyperledger.besu:secp256k1:0.3.0.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/hyperledger/besu/secp256k1/0.3.0/secp256k1-0.3.0.pom
       - https://repo.maven.apache.org/maven2/org/hyperledger/besu/secp256k1/0.3.0/secp256k1-0.3.0.pom
     Required by:
         project :smart-contract > org.web3j:web3j-unit:4.9.0
         project :smart-contract > org.web3j:web3j-evm:4.9.0
   > Could not find com.beust:klaxon:5.0.1.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/beust/klaxon/5.0.1/klaxon-5.0.1.pom
       - https://repo.maven.apache.org/maven2/com/beust/klaxon/5.0.1/klaxon-5.0.1.pom
     Required by:
         project :smart-contract > org.web3j:web3j-evm:4.9.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 4s
5 actionable tasks: 1 executed, 4 up-to-date

Environment

  • Web3j 4.9.0
  • Java 11
  • Ubuntu 20.04

Additional context

Yesterday it worked

eth_newfilter and eth_getLogs: UnsupportedOperationException

val filter = EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, creatorWallet.address)
val x = asCreator.nFTCreatedEventFlowable(filter)
println(x.test().events).  // [UnsupportedOperationException eth_newfilter]

Is there a way to get the event data that was emitted? In previous versions of web3j (4.8.4) could use the TransactionReceipt and the wrapper generated a function to get the Event in a non flowable way - but in the later versions only the flowable ones get generated.

trying to get the logs also has the same exception

Environment

  • Web3j 4.9.4
  • Java or Android version
  • Java

Nonce incorrect when deploying @BeforeEach

@EVMTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MyContractTest {

  private lateinit var web3j: Web3j
  private lateinit var transactionManager: TransactionManager
  private lateinit var contractGasProvider: ContractGasProvider
  private lateinit var contract: MyContract

  @BeforeAll
    fun setup(
      web3j: Web3j,
      transactionManager: TransactionManager,
      contractGasProvider: ContractGasProvider
    ) {
      this.web3j = web3j
      this.transactionManager = transactionManager
      this.contractGasProvider = contractGasProvider
    }

    @BeforeEach
    fun deploy() {
      contract = MyContract.deploy(web3j, transactionManager, contractGasProvider).send()
    }

    ....

This code example would result in the following error for anything beyond the first unit test

13:03:37.755 [Test worker] INFO org.web3j.evm.EmbeddedEthereum - Starting with root: 0x301445f058a527a71728a09c0abba3826743616030b1ab77c752597eb3814ac4
13:03:37.758 [Test worker] WARN org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor - Invalid transaction: transaction nonce 1 below sender account nonce 2
13:03:37.759 [Test worker] INFO org.web3j.evm.EmbeddedEthereum - Ending with root: 0x72711436a155d7a8edc25f532c804090624808d74a54b592d34a3c9dd1a9294a
13:03:37.760 [Test worker] WARN org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor - Invalid transaction: transaction nonce 1 below sender account nonce 2

Transaction receipt was not generated after 30 seconds for transaction: 0x41c9b40a778043225741ad6f79ca1a3beaf4bab51846927cb60a3f3936194b49
org.web3j.protocol.exceptions.TransactionException: Transaction receipt was not generated after 30 seconds for transaction: 0x41c9b40a778043225741ad6f79ca1a3beaf4bab51846927cb60a3f3936194b49
	at org.web3j.tx.response.PollingTransactionReceiptProcessor.getTransactionReceipt(PollingTransactionReceiptProcessor.java:61)
	at org.web3j.tx.response.PollingTransactionReceiptProcessor.waitForTransactionReceipt(PollingTransactionReceiptProcessor.java:38)
	at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:167)
	at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
	at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:127)
	at org.web3j.tx.Contract.executeTransaction(Contract.java:366)
	at org.web3j.tx.Contract.create(Contract.java:421)
	at org.web3j.tx.Contract.deploy(Contract.java:485)
	at org.web3j.tx.Contract.lambda$deployRemoteCall$10(Contract.java:687)
	at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
	at org.project.example.generated.contracts.MyContractTest.deploy(MyContractTest.kt:48)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptLifecycleMethod(TimeoutExtension.java:111)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptBeforeEachMethod(TimeoutExtension.java:67)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeMethodInExtensionContext(ClassBasedTestDescriptor.java:464)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$synthesizeBeforeEachMethodAdapter$16(ClassBasedTestDescriptor.java:449)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachMethods$2(TestMethodTestDescriptor.java:159)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$5(TestMethodTestDescriptor.java:187)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:187)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachMethods(TestMethodTestDescriptor.java:156)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:102)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:82)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:78)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.base/java.lang.Thread.run(Thread.java:829)

Option to specify genesis file for Embedded Service

The ServiceBuilder should be able to pass a genesis file path to the Configuration object passed into an EmbeddedService instance.

This will allow users to specify custom genesis files for the EmbeddedService similar to what can already be done for the dockerized instances of Besu and Geth.

The main issue is that the default genesis path is "dev" (this is for the dockerized instances to use the pre-generated default genesis files in the resources). For the EmbeddedService the default should be "null" so that EmbeddedEthereum uses a pre-generated genesis file.

TransactionException with empty revert reason

TransactionException with empty revert reason

Steps To Reproduce

Here's my test:

package bounty_hunter_gradle

import kotlin.test.assertFailsWith
import com.google.common.truth.Truth.assertThat
import java.math.BigInteger
import java.time.Duration
import java.time.Instant
import org.junit.jupiter.api.Test
import org.web3j.EVMTest
import org.web3j.NodeType
import org.web3j.protocol.Web3j
import org.web3j.protocol.core.methods.response.TransactionReceipt
import org.web3j.protocol.exceptions.TransactionException
import org.web3j.tx.TransactionManager
import org.web3j.tx.gas.ContractGasProvider
import bounty_hunter_gradle.web3j.Bounties

@EVMTest(type = NodeType.EMBEDDED)
class AppTest {

  @Test
  fun shouldAnswerWithTrue(
    web3j: Web3j, transactionManager: TransactionManager, gasProvider: ContractGasProvider,
  ) {
    val bounties: Bounties = Bounties.deploy(web3j, transactionManager, gasProvider).send()
    val deadline: BigInteger = BigInteger.valueOf(Instant.now().plus(Duration.ofHours(1)).getEpochSecond())
    val send: TransactionReceipt  = bounties.issueBounty("test_bounty", deadline, BigInteger.valueOf(1000)).send()
    assertThat(send.getStatus()).isEqualTo("ok")
  }
}

Here's the contract: Bounties.sol.txt

Here's the test run details: index.html.txt

Expected behavior

The error message for TransactionException contains the reason the transaction failed.

Actual behavior

Here's the test output:

org.web3j.protocol.exceptions.TransactionException: Transaction 0x0d91b6a3ab8c18cfb2788d6bc3f67e3d7f59d46be96f4aa06dc4a83bb29b5697 has failed with status: 0x0. Gas used: 36782. Revert reason: ''.
	at app//org.web3j.tx.Contract.executeTransaction(Contract.java:419)
	at app//org.web3j.tx.Contract.executeTransaction(Contract.java:358)
	at app//org.web3j.tx.Contract.executeTransaction(Contract.java:352)
	at app//org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$4(Contract.java:457)
	at app//org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
	at app//bounty_hunter_gradle.AppTest.shouldAnswerWithTrue(AppTest.kt:30)
...

Environment

JUnit test with the embedded EVM

_

  • Web3j version: 4.9.4
  • Java or Android version: openjdk version "17.0.4.1" 2022-08-12 LTS
  • Operating System: Ubuntu

Additional context

none

Container GETH does not start

EVMTest nodetype GETH not working

I'm trying to run an integration test with @EVMTest(type = NodeType.GETH, version = "stable") annotation, but as soon as the ethereum-go container starts, it stops.

In the container logs I can see the message

Fatal: keyfile must be given as the only argument
Incorrect Usage. flag provided but not defined: -rpc

Steps To Reproduce

Run a test in a class annotated with @EVMTest(type = NodeType.GETH

Expected behavior

Container should spin up

Actual behavior

It doesn't

Environment

  • Web3j version: 4.9.6
  • Java 17
  • Mac os

Adding the possibility to specify only the genesis in Configuration

The Configuration class should be able to be instantiated using only a genesis file:

Configuration(genesisPath)

Also, it would be nice if it could take a list of Addresses and fund them:

Configuration(List<Address>, amount, genesis)

or to each account its own value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.