use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.
the class AccountRepositoryIntegrationTest method outgoingTransactionsById.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void outgoingTransactionsById(RepositoryType type) {
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
Account account = config().getDefaultAccount();
List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).signerPublicKey(account.getPublicAccount().getPublicKey()).pageSize(10))).getData();
Assertions.assertTrue(transactions.size() > 1);
String id = transactions.get(1).getTransactionInfo().get().getId().get();
List<Transaction> transactions2 = get(transactionRepository.getTransactions(TransactionGroup.CONFIRMED, Arrays.asList(id)));
Assertions.assertEquals(1, transactions2.size());
transactions2.forEach(t -> Assertions.assertEquals(id, t.getTransactionInfo().get().getId().get()));
}
use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.
the class AccountRepositoryIntegrationTest method getTransactionById.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getTransactionById(RepositoryType type) {
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
Account account = config().getDefaultAccount();
List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).signerPublicKey(account.getPublicAccount().getPublicKey()).pageSize(10))).getData();
Assertions.assertTrue(transactions.size() > 0);
String id = transactions.get(1).getTransactionInfo().get().getId().get();
List<Transaction> transactions2 = get(transactionRepository.getTransactions(TransactionGroup.CONFIRMED, Arrays.asList(id)));
Assertions.assertEquals(1, transactions2.size());
transactions2.forEach(t -> Assertions.assertEquals(id, t.getTransactionInfo().get().getId().get()));
}
use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeValid.
@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeValid(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), NETWORK_TYPE);
String channelName = channel.toString();
List<Transaction> transactions = new ArrayList<>();
List<Throwable> exceptions = new ArrayList<>();
BiFunction<UnresolvedAddress, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmedOrError : listener::aggregateBondedAddedOrError;
TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
subscriber.apply(address, meta.getHash()).doOnError(exceptions::add).forEach(transactions::add);
handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
Assertions.assertEquals(1, transactions.size());
Assertions.assertEquals(0, exceptions.size());
Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
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, "status" + "/" + address.plain())));
}
use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeOnError.
@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeOnError(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), NETWORK_TYPE);
String channelName = channel.toString();
Map<String, Object> transactionStatusError = new HashMap<>();
transactionStatusError.put("address", address.encoded());
transactionStatusError.put("code", "Fail 666");
TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
transactionStatusError.put("hash", meta.getHash());
transactionStatusError.put("deadline", 123);
List<Transaction> transactions = new ArrayList<>();
List<Throwable> exceptions = new ArrayList<>();
BiFunction<Address, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmedOrError : listener::aggregateBondedAddedOrError;
subscriber.apply(address, meta.getHash()).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 " + meta.getHash(), exceptions.get(0).getMessage());
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, "status" + "/" + address.plain())));
}
use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.
the class TransactionMapperSerializationVertxTest method testDtoToModelMapping.
@ParameterizedTest
@MethodSource("transactionJsonFiles")
void testDtoToModelMapping(String jsonFilename) {
String json = TestHelperVertx.loadResource(jsonFilename);
TransactionInfoDTO originalTransactionInfo = jsonHelper.parse(json, TransactionInfoDTO.class);
Transaction transactionModel = transactionMapper.mapFromDto(originalTransactionInfo);
Assertions.assertNotNull(transactionModel);
TransactionInfoDTO mappedTransactionInfo = (TransactionInfoDTO) transactionMapper.mapToDto(transactionModel);
Map<String, Object> transactionMap = jsonHelper.convert(mappedTransactionInfo.getTransaction(), Map.class);
Map<String, Object> originalTransactionMap = jsonHelper.convert(originalTransactionInfo.getTransaction(), Map.class);
originalTransactionMap.put("size", transactionModel.getSize());
originalTransactionInfo.setTransaction(originalTransactionMap);
// Patching the sort
mappedTransactionInfo.setTransaction(transactionMap);
mappedTransactionInfo.setMeta(jsonHelper.convert(mappedTransactionInfo.getMeta(), Map.class));
Assertions.assertEquals(jsonHelper.prettyPrint(originalTransactionInfo), jsonHelper.prettyPrint(mappedTransactionInfo));
BinarySerialization serialization = new BinarySerializationImpl();
Transaction transaction = transactionMapper.mapFromDto(mappedTransactionInfo);
byte[] serialize1 = serialization.serialize(transactionModel);
byte[] serialize2 = serialization.serialize(transaction);
Assertions.assertEquals(ConvertUtils.toHex(serialize1), ConvertUtils.toHex(serialize2));
removeMeta(originalTransactionInfo);
byte[] serialize3 = serialization.serialize(transactionModel);
Assertions.assertEquals(ConvertUtils.toHex(serialize1), ConvertUtils.toHex(serialize3));
Transaction deserialized3 = serialization.deserialize(serialize3);
TransactionInfoDTO deserializedTransaction = (TransactionInfoDTO) transactionMapper.mapToDto(deserialized3, false);
deserializedTransaction.setTransaction(jsonHelper.convert(deserializedTransaction.getTransaction(), Map.class));
removeMeta(deserializedTransaction);
Assertions.assertEquals(jsonHelper.prettyPrint(originalTransactionInfo), jsonHelper.prettyPrint(deserializedTransaction));
}
Aggregations