use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerOkHttpTest method aggregateBondedAddedRaisingError.
@Test
public void aggregateBondedAddedRaisingError() 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.AGGREGATE_BONDED_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.aggregateBondedAddedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
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())));
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());
}
use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerOkHttpTest method cosignatureAdded.
@Test
public void cosignatureAdded() throws InterruptedException, ExecutionException, TimeoutException {
simulateWebSocketStartup();
Cosignature cosignature = new Cosignature().parentHash("aParentHash").signature("aSignature").version(BigInteger.ONE).signerPublicKey(Account.generateNewAccount(networkType).getPublicKey());
JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(cosignature, JsonObject.class);
Address address = Address.createFromPublicKey(cosignature.getSignerPublicKey(), networkType);
String channelName = ListenerChannel.COSIGNATURE.toString();
List<CosignatureSignedTransaction> transactions = new ArrayList<>();
listener.cosignatureAdded(address).forEach(transactions::add);
handle(transactionInfoDtoJsonObject, channelName + "/" + 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).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerOkHttpTest method shouldHandleStatus.
@Test
public void shouldHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
Account account1 = Account.generateNewAccount(networkType);
AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
simulateWebSocketStartup();
Assertions.assertNotNull(listener.status(account1.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.assertNotNull(reference.get());
Assertions.assertEquals(message.get("hash"), reference.get().getHash());
Assertions.assertEquals(message.get("code"), reference.get().getStatus());
Assertions.assertEquals(account1.getAddress(), reference.get().getAddress());
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account1.getAddress().plain())));
}
use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeAlias.
@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED", "UNCONFIRMED_ADDED" })
public void subscribeAlias(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
String channelName = channel.toString();
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("transferEmptyMessage.json");
NamespaceId namespaceId = NamespaceId.createFromName("alias");
ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
List<Transaction> transactions = new ArrayList<>();
BiFunction<UnresolvedAddress, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmed : channel == ListenerChannel.UNCONFIRMED_ADDED ? listener::unconfirmedAdded : listener::aggregateBondedAdded;
TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
subscriber.apply(namespaceId, meta.getHash()).forEach(transactions::add);
handle(transactionInfoDtoJsonObject, channelName + "/" + namespaceId.plain());
Assertions.assertEquals(1, transactions.size());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
}
use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeToHashWhenInvalidHash.
@ParameterizedTest
@ValueSource(strings = { "AGGREGATE_BONDED_REMOVED", "UNCONFIRMED_REMOVED" })
public void subscribeToHashWhenInvalidHash(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
String channelName = channel.toString();
simulateWebSocketStartup();
Address address = Address.generateRandom(NETWORK_TYPE);
String hash = "someHash";
List<String> hashes = new ArrayList<>();
BiFunction<Address, String, Observable<String>> subscriber = channel == ListenerChannel.AGGREGATE_BONDED_REMOVED ? listener::aggregateBondedRemoved : listener::unconfirmedRemoved;
subscriber.apply(address, hash).forEach(hashes::add);
Map<String, Map<String, String>> message = new HashMap<>();
Map<String, String> meta = new HashMap<>();
meta.put("hash", "invalidHash");
message.put("meta", meta);
handle(message, channelName + "/" + address.plain());
Assertions.assertEquals(0, hashes.size());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
Aggregations