Search in sources :

Example 26 with TransactionSearchCriteria

use of io.nem.symbol.sdk.api.TransactionSearchCriteria 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);
}
Also used : TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) Arrays(java.util.Arrays) Account(io.nem.symbol.sdk.model.account.Account) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) EnumSource(org.junit.jupiter.params.provider.EnumSource) ArrayList(java.util.ArrayList) TestInstance(org.junit.jupiter.api.TestInstance) Message(io.nem.symbol.sdk.model.message.Message) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) PublicKey(io.nem.symbol.core.crypto.PublicKey) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions(org.junit.jupiter.api.Assertions) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) ArrayList(java.util.ArrayList) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) List(java.util.List) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with TransactionSearchCriteria

use of io.nem.symbol.sdk.api.TransactionSearchCriteria in project nem2-sdk-java by nemtech.

the class TransactionSearchRepositoryIntegrationTest method searchByTransactionToHeight.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByTransactionToHeight(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionSearchCriteria toBlockOneTransactions = new TransactionSearchCriteria(TransactionGroup.CONFIRMED).toHeight(BigInteger.ONE).embedded(true);
    List<Transaction> transactions = get(streamer.search(toBlockOneTransactions).toList().toObservable());
    transactions.forEach(b -> Assertions.assertEquals(BigInteger.ONE, b.getTransactionInfo().get().getHeight()));
    Assertions.assertFalse(transactions.isEmpty());
    TransactionSearchCriteria blockOneTransactions = new TransactionSearchCriteria(TransactionGroup.CONFIRMED).height(BigInteger.ONE).embedded(true);
    helper.assertSameRecordList(get(streamer.search(toBlockOneTransactions).toList().toObservable()), get(streamer.search(blockOneTransactions).toList().toObservable()));
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with TransactionSearchCriteria

use of io.nem.symbol.sdk.api.TransactionSearchCriteria in project nem2-sdk-java by nemtech.

the class TransactionSearchRepositoryIntegrationTest method searchByTransactionType.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByTransactionType(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.CONFIRMED);
    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.assertFalse(transactions.isEmpty());
    helper.assertById(transactionRepository, TransactionGroup.CONFIRMED, transactions);
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with TransactionSearchCriteria

use of io.nem.symbol.sdk.api.TransactionSearchCriteria 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());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Message(io.nem.symbol.sdk.model.message.Message) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with TransactionSearchCriteria

use of io.nem.symbol.sdk.api.TransactionSearchCriteria in project nem2-sdk-java by nemtech.

the class TransactionSearchRepositoryIntegrationTest method searchByTransactionFromHeight.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByTransactionFromHeight(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionSearchCriteria toBlockOneTransactions = new TransactionSearchCriteria(TransactionGroup.CONFIRMED).fromHeight(BigInteger.valueOf(2)).embedded(true);
    List<Transaction> transactions = get(streamer.search(toBlockOneTransactions).toList().toObservable());
    transactions.forEach(b -> Assertions.assertTrue(b.getTransactionInfo().get().getHeight().compareTo(BigInteger.ONE) > 0));
    Assertions.assertFalse(transactions.isEmpty());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)31 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)31 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)29 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)24 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)21 TransactionPaginationStreamer (io.nem.symbol.sdk.api.TransactionPaginationStreamer)13 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)12 Account (io.nem.symbol.sdk.model.account.Account)8 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)8 BigInteger (java.math.BigInteger)7 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)6 TransactionGroup (io.nem.symbol.sdk.model.transaction.TransactionGroup)6 Test (org.junit.jupiter.api.Test)6 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)5 PublicKey (io.nem.symbol.core.crypto.PublicKey)4 Address (io.nem.symbol.sdk.model.account.Address)4 Message (io.nem.symbol.sdk.model.message.Message)4 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)4