use of io.nem.symbol.sdk.model.transaction.TransactionGroup in project nem2-sdk-java by nemtech.
the class TransactionSearchRepositoryIntegrationTest method searchUnconfirmed.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUnconfirmed(RepositoryType type) {
TransactionRepository transactionRepository = getTransactionRepository(type);
Address recipient = getRecipient();
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("")).maxFee(maxFee).build();
Account signer = config().getDefaultAccount();
SignedTransaction signedTransaction = transferTransaction.signWith(signer, getGenerationHash());
get(transactionRepository.announce(signedTransaction));
get(getListener(type).unconfirmedAdded(signer.getAddress(), signedTransaction.getHash()).take(1));
TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
TransactionGroup group = TransactionGroup.UNCONFIRMED;
TransactionSearchCriteria criteria = new TransactionSearchCriteria(group);
criteria.transactionTypes(Collections.singletonList(TransactionType.TRANSFER));
List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
transactions.forEach(b -> Assertions.assertEquals(TransactionType.TRANSFER, b.getType()));
Assertions.assertTrue(transactions.stream().filter(t -> t.getTransactionInfo().get().getHash().get().equals(signedTransaction.getHash())).findAny().isPresent());
helper.assertById(transactionRepository, group, transactions);
}
use of io.nem.symbol.sdk.model.transaction.TransactionGroup in project nem2-sdk-java by nemtech.
the class TransactionSearchRepositoryIntegrationTest method searchEmbedded.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchEmbedded(RepositoryType type) {
TransactionRepository transactionRepository = getTransactionRepository(type);
TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
TransactionGroup group = TransactionGroup.CONFIRMED;
TransactionSearchCriteria criteria = new TransactionSearchCriteria(group).embedded(true);
List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
transactions.forEach(b -> {
TransferTransaction transferTransaction = (TransferTransaction) b;
Message message = transferTransaction.getMessage().orElse(PlainMessage.create("No Message!!"));
Assertions.assertNotNull(message.getText());
});
Assertions.assertFalse(transactions.isEmpty());
}
use of io.nem.symbol.sdk.model.transaction.TransactionGroup in project nem2-sdk-java by nemtech.
the class TransactionSearchRepositoryIntegrationTest method searchByGroup.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByGroup(RepositoryType type) {
TransactionRepository transactionRepository = getTransactionRepository(type);
TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
TransactionGroup group = TransactionGroup.CONFIRMED;
TransactionSearchCriteria criteria = new TransactionSearchCriteria(group);
List<Transaction> transactions = get(streamer.search(criteria).flatMap(t -> t.isTransactionFullyLoaded() ? Observable.just(t) : transactionRepository.getTransaction(group, t.getTransactionInfo().get().getHash().get())).toList().toObservable());
String generationHash = getGenerationHash();
List<List<String>> reported = new ArrayList<>();
transactions.forEach(b -> {
String originalHash = b.getTransactionInfo().get().getHash().get();
BigInteger height = b.getTransactionInfo().get().getHeight();
String calculatedHash = b.createTransactionHash(ConvertUtils.toHex(b.serialize()), ConvertUtils.fromHexToBytes(generationHash));
boolean valid = originalHash.equals(calculatedHash);
if (!valid) {
List<String> values = Arrays.asList(Boolean.toString(valid), b.getType().name(), height.toString(), originalHash, calculatedHash, ConvertUtils.toHex(b.serialize()), toJson(b));
reported.add(values);
}
Assertions.assertNotNull(b.getTransactionInfo().get().getHeight());
});
reported.forEach(values -> {
System.out.println("| " + String.join(" | ", values) + " |");
});
Assertions.assertTrue(reported.isEmpty());
Assertions.assertFalse(transactions.isEmpty());
helper.assertById(transactionRepository, group, transactions);
}
use of io.nem.symbol.sdk.model.transaction.TransactionGroup in project nem2-sdk-java by nemtech.
the class TransactionSearchRepositoryIntegrationTest method searchTransactionType.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchTransactionType(RepositoryType type) {
TransactionRepository transactionRepository = getTransactionRepository(type);
TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
TransactionGroup group = TransactionGroup.CONFIRMED;
TransactionSearchCriteria criteria = new TransactionSearchCriteria(group).transactionTypes(Arrays.asList(TransactionType.TRANSFER));
List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
transactions.forEach(b -> {
TransferTransaction transferTransaction = (TransferTransaction) b;
Message message = transferTransaction.getMessage().orElse(PlainMessage.create("No Message!!"));
Assertions.assertNotNull(message.getText());
});
Assertions.assertFalse(transactions.isEmpty());
}
Aggregations