Search in sources :

Example 6 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage 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 7 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method confirmedUsingHashRaiseError.

@Test
public void confirmedUsingHashRaiseError() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
    Map<String, Object> transactionStatusError = new HashMap<>();
    transactionStatusError.put("address", address.encoded());
    transactionStatusError.put("code", "Fail 666");
    transactionStatusError.put("hash", getHash(transactionInfo));
    transactionStatusError.put("deadline", 123);
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.confirmedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionStatusError, "status/" + address.plain());
    Assertions.assertEquals(0, transactions.size());
    Assertions.assertEquals(1, exceptions.size());
    Assertions.assertEquals(TransactionStatusException.class, exceptions.get(0).getClass());
    Assertions.assertEquals("Fail 666 processing transaction " + getHash(transactionInfo), exceptions.get(0).getMessage());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test)

Example 8 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerVertx method subscribeTo.

protected void subscribeTo(String channel) {
    final ListenerSubscribeMessage subscribeMessage = new ListenerSubscribeMessage(this.getUid(), channel);
    this.webSocket.writeTextMessage(getJsonHelper().print(subscribeMessage));
}
Also used : ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)

Example 9 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method shouldFilterOutHandleStatus.

@Test
public void shouldFilterOutHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
    Account account1 = Account.generateNewAccount(NETWORK_TYPE);
    Account account2 = Account.generateNewAccount(NETWORK_TYPE);
    AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
    simulateWebSocketStartup();
    Assertions.assertNotNull(listener.status(account2.getAddress()).subscribe(reference::set));
    Map<String, Object> message = new HashMap<>();
    message.put("hash", "1234hash");
    message.put("address", account1.getAddress().encoded());
    message.put("code", "some error");
    message.put("deadline", 5555);
    handle(message, "status/" + account1.getAddress().plain());
    Assertions.assertNull(reference.get());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account2.getAddress().plain())));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method cosignatureAdded.

@Test
public void cosignatureAdded() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    ListenerChannel consignature = ListenerChannel.COSIGNATURE;
    NetworkType networkType = NETWORK_TYPE;
    Cosignature cosignature = new Cosignature().parentHash("aParentHash").signature("aSignature").version(BigInteger.ONE).signerPublicKey(Account.generateNewAccount(networkType).getPublicKey());
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(cosignature, ObjectNode.class);
    Address address = Address.createFromPublicKey(cosignature.getSignerPublicKey(), networkType);
    String channelName = consignature.toString();
    List<CosignatureSignedTransaction> transactions = new ArrayList<>();
    listener.cosignatureAdded(address).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, consignature.toString() + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(cosignature.getSignerPublicKey(), transactions.get(0).getSigner().getPublicKey().toHex());
    Assertions.assertEquals(cosignature.getParentHash(), transactions.get(0).getParentHash());
    Assertions.assertEquals(cosignature.getSignature(), transactions.get(0).getSignature());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
Also used : CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ListenerChannel(io.nem.symbol.sdk.infrastructure.ListenerChannel) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) ArrayList(java.util.ArrayList) Cosignature(io.nem.symbol.sdk.openapi.vertx.model.Cosignature) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)24 ArrayList (java.util.ArrayList)18 Address (io.nem.symbol.sdk.model.account.Address)15 Test (org.junit.jupiter.api.Test)14 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 JsonObject (com.google.gson.JsonObject)10 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)10 HashMap (java.util.HashMap)10 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)9 ValueSource (org.junit.jupiter.params.provider.ValueSource)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 Observable (io.reactivex.Observable)7 TransactionInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO)6 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)5 TransactionMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)5 Account (io.nem.symbol.sdk.model.account.Account)4 TransactionStatusError (io.nem.symbol.sdk.model.transaction.TransactionStatusError)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Map (java.util.Map)3