Warchant / testcontainers-iroha

MOVED TO

Home Page:https://github.com/hyperledger/iroha-java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Codacy Badge codecov GitPitch

testcontainers-iroha

Testcontainers image for single Iroha peer and iroha network.

Features

  • run one or multiple independent iroha peers (not connected to a network) with IrohaContainer class.
  • run one or multiple independent iroha networks with IrohaNetwork class. All peers within a network are connected to a single network.
  • define custom genesis block or peer config for peer/network at run-time.
  • select iroha or postgres version at run-time.

Install

https://jitpack.io/#warchant/testcontainers-iroha

Usage

Single Peer

class SinglePeerTest {

  IrohaContainer iroha = new IrohaContainer();

  @BeforeAll
  public void beforeAll(){
    iroha.start(); // starts iroha and postgres
  }

  @AfterAll
  public void afterAll(){
    iroha.stop(); // stops iroha and postgres
  }

  @Test
  public TestWithIroha (){
    URI toriiAddr = iroha.getToriiAddress();  // iroha API host:port (torii)
    IrohaAPI api  = iroha.getApi();  // or use async Iroha API wrapper directly
    // ...
  }
}

IrohaContainer starts Postgres and Iroha docker containers with given PeerConfig. There is a default config for test purposes.

Configuration

To change default configuration:

IrohaContainer iroha = new IrohaContainer()
    .withPeerConfig( /* pass config here */ );

iroha.start();
...
iroha.stop();

Network Of Peers

class IrohaNetworkTest {

  IrohaNetwork iroha = new IrohaNetwork(5 /* peers */);

  // networks are completely independent
  IrohaNetwork network2 = new IrohaNetwork(5 /* peers */)
            .withNetworkName("someUniqueName");

  @BeforeAll
  public void beforeAll(){
    iroha.start(); // starts all containers
  }

  @AfterAll
  public void afterAll(){
    iroha.stop(); // stops all containers
  }

  @Test
  public TestWithIroha (){
    List<URI> toriiAddr = iroha.getToriiAddress();  // list of iroha API host:port (torii)
    List<IrohaAPI> apis = iroha.getApis();  // or list of async Iroha API wrappers, 1 per peer
    // ...
  }
}

Configuration

To change default configuration:

IrohaNetwork network = new IrohaNetwork(5 /* peers */);

// setup shared iroha config
network.withIrohaConfig(IrohaConfig.builder()
  .setMst_enable(true)
  .build())

// to change genesis block (peers are added automatically)
network.addTransaction(tx);

network.start();
...
network.stop();

Known Issues

If you get an Exception:

com.github.dockerjava.api.exception.DockerException: Mounts denied

You are probably on MAC and you need to add /var/folder to docker paths:

Please refer to testcontainers/testcontainers-java#730

About

MOVED TO

https://github.com/hyperledger/iroha-java

License:Apache License 2.0


Languages

Language:Java 65.6%Language:Groovy 19.8%Language:Shell 14.0%Language:Dockerfile 0.6%