Skip to content

iikirilov/web3j-unit

 
 

Repository files navigation

Web3j-unit Build Status

⚠️ This is a work in progress! ⚠

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.

Getting Started

  1. Add dependency to gradle. N.B. Only snapshots are available at this time.
   repositories {
       maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
   }

   testCompile "org.web3j:web3j-unit:4.6.0-SNAPSHOT"
  1. Create a new test with the @EVMTest annotation. An instance of Besu is used by default. To use Geth pass the node type into the annotation: @EVMTest(NodeType.GETH)
@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!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 85.6%
  • Shell 14.4%