Search in sources :

Example 1 with FinalizedBlock

use of io.nem.symbol.sdk.model.blockchain.FinalizedBlock in project nem2-sdk-java by nemtech.

the class ChainRepositoryIntegrationTest method getChainInfo.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getChainInfo(RepositoryType type) {
    ChainInfo chainInfo = get(getChainRepository(type).getChainInfo());
    assertTrue(chainInfo.getScoreLow().longValue() >= 0);
    assertTrue(chainInfo.getScoreHigh().longValue() >= 0);
    assertTrue(chainInfo.getHeight().longValue() > 0);
    FinalizedBlock finalizedBlock = chainInfo.getLatestFinalizedBlock();
    assertTrue(finalizedBlock.getFinalizationEpoch() >= 0);
    assertTrue(finalizedBlock.getFinalizationPoint() >= 0);
    assertTrue(finalizedBlock.getHeight().longValue() > 0);
    assertNotNull(finalizedBlock.getHash());
}
Also used : ChainInfo(io.nem.symbol.sdk.model.blockchain.ChainInfo) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with FinalizedBlock

use of io.nem.symbol.sdk.model.blockchain.FinalizedBlock in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method subscribeFinalizedBlock.

@Test
public void subscribeFinalizedBlock() throws ExecutionException, InterruptedException, TimeoutException {
    simulateWebSocketStartup();
    FinalizedBlock finalizedBlock = new FinalizedBlock(1L, 2L, BigInteger.valueOf(3), "abc");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(finalizedBlock, JsonObject.class);
    String channelName = ListenerChannel.FINALIZED_BLOCK.toString();
    List<FinalizedBlock> finalizedBlocks = new ArrayList<>();
    listener.finalizedBlock().forEach(finalizedBlocks::add);
    handle(transactionInfoDtoJsonObject, channelName);
    Assertions.assertEquals(1, finalizedBlocks.size());
    Assertions.assertEquals(finalizedBlock, finalizedBlocks.get(0));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName)));
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 3 with FinalizedBlock

use of io.nem.symbol.sdk.model.blockchain.FinalizedBlock in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method subscribeFinalizedBlock.

@Test
public void subscribeFinalizedBlock() throws ExecutionException, InterruptedException, TimeoutException {
    simulateWebSocketStartup();
    String channelName = ListenerChannel.FINALIZED_BLOCK.toString();
    FinalizedBlock finalizedBlock = new FinalizedBlock(1L, 2L, BigInteger.valueOf(3), "abc");
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(finalizedBlock, ObjectNode.class);
    List<FinalizedBlock> finalizedBlocks = new ArrayList<>();
    listener.finalizedBlock().forEach(finalizedBlocks::add);
    handle(transactionInfoDtoJsonObject, channelName);
    Assertions.assertEquals(1, finalizedBlocks.size());
    Assertions.assertEquals(1, finalizedBlocks.size());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName)));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with FinalizedBlock

use of io.nem.symbol.sdk.model.blockchain.FinalizedBlock in project nem2-sdk-java by nemtech.

the class FinalizationRepositoryIntegrationTest method getFinalizationProofAtCurrentFinalizedHeight.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getFinalizationProofAtCurrentFinalizedHeight(RepositoryType type) {
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    FinalizedBlock finalizedBlock = get(repositoryFactory.createChainRepository().getChainInfo()).getLatestFinalizedBlock();
    FinalizationRepository repository = repositoryFactory.createFinalizationRepository();
    FinalizationProof finalizationProof = get(repository.getFinalizationProofAtHeight(finalizedBlock.getHeight()));
    Assertions.assertEquals(finalizationProof.getFinalizationEpoch(), finalizationProof.getFinalizationEpoch());
    Assertions.assertEquals(finalizationProof.getFinalizationPoint(), finalizationProof.getFinalizationPoint());
    Assertions.assertEquals(finalizationProof.getHeight(), finalizationProof.getHeight());
    Assertions.assertEquals(1, finalizationProof.getVersion());
}
Also used : FinalizationProof(io.nem.symbol.sdk.model.finalization.FinalizationProof) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) FinalizationRepository(io.nem.symbol.sdk.api.FinalizationRepository) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with FinalizedBlock

use of io.nem.symbol.sdk.model.blockchain.FinalizedBlock in project nem2-sdk-java by nemtech.

the class FinalizationRepositoryIntegrationTest method getFinalizationProofAtEpochLatest.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getFinalizationProofAtEpochLatest(RepositoryType type) {
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    FinalizedBlock finalizedBlock = get(repositoryFactory.createChainRepository().getChainInfo()).getLatestFinalizedBlock();
    FinalizationRepository repository = repositoryFactory.createFinalizationRepository();
    FinalizationProof finalizationProof = get(repository.getFinalizationProofAtEpoch(finalizedBlock.getFinalizationEpoch()));
    Assertions.assertEquals(finalizationProof.getFinalizationEpoch(), finalizationProof.getFinalizationEpoch());
    Assertions.assertEquals(finalizationProof.getFinalizationPoint(), finalizationProof.getFinalizationPoint());
    Assertions.assertEquals(finalizationProof.getHeight(), finalizationProof.getHeight());
    Assertions.assertEquals(1, finalizationProof.getVersion());
}
Also used : FinalizationProof(io.nem.symbol.sdk.model.finalization.FinalizationProof) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) FinalizationRepository(io.nem.symbol.sdk.api.FinalizationRepository) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FinalizedBlock (io.nem.symbol.sdk.model.blockchain.FinalizedBlock)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 FinalizationRepository (io.nem.symbol.sdk.api.FinalizationRepository)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)2 FinalizationProof (io.nem.symbol.sdk.model.finalization.FinalizationProof)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 JsonObject (com.google.gson.JsonObject)1 Listener (io.nem.symbol.sdk.api.Listener)1 ChainInfo (io.nem.symbol.sdk.model.blockchain.ChainInfo)1 Disabled (org.junit.jupiter.api.Disabled)1