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)));
}
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())));
}
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));
}
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())));
}
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())));
}
Aggregations