Skip to content

Latest commit

 

History

History
 
 

testcontainers

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

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