Search in sources :

Example 11 with TransactionRepository

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

the class TransactionSearchRepositoryIntegrationTest method searchUsingOffset.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUsingOffset(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.CONFIRMED);
    criteria.setPageSize(10);
    int offsetIndex = 2;
    List<Transaction> transactionsWithoutOffset = get(streamer.search(criteria).toList().toObservable());
    criteria.setOffset(transactionsWithoutOffset.get(offsetIndex).getRecordId().get());
    List<Transaction> transactionFromOffsets = get(streamer.search(criteria).toList().toObservable());
    PaginationTester.sameEntities(transactionsWithoutOffset.stream().skip(offsetIndex + 1).collect(Collectors.toList()), transactionFromOffsets);
    helper.assertById(transactionRepository, TransactionGroup.CONFIRMED, transactionFromOffsets);
    helper.assertById(transactionRepository, TransactionGroup.CONFIRMED, transactionsWithoutOffset);
}
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 12 with TransactionRepository

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

the class TransactionSearchRepositoryIntegrationTest method searchByTransactionHeight.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByTransactionHeight(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.CONFIRMED);
    criteria.height(BigInteger.ONE);
    criteria.embedded(true);
    List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
    transactions.forEach(b -> Assertions.assertEquals(BigInteger.ONE, b.getTransactionInfo().get().getHeight()));
    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 13 with TransactionRepository

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

the class TransactionSearchRepositoryIntegrationTest method searchEmbeddedTransactionType.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchEmbeddedTransactionType(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(TransactionGroup.CONFIRMED);
    criteria.setEmbedded(true);
    List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
    Assertions.assertFalse(transactions.isEmpty());
    transactions.stream().forEach(t -> {
        Transaction storedById = get(transactionRepository.getTransaction(TransactionGroup.CONFIRMED, t.getRecordId().get()));
        Assertions.assertEquals(storedById.getRecordId().get(), t.getRecordId().get());
        if (t.getTransactionInfo().get().getHash().isPresent()) {
            Transaction transaction = get(transactionRepository.getTransaction(TransactionGroup.CONFIRMED, t.getTransactionInfo().get().getHash().get()));
            Assertions.assertEquals(storedById.getRecordId().get(), t.getRecordId().get());
            Assertions.assertEquals(t.getTransactionInfo().get().getHash().get(), t.getTransactionInfo().get().getHash().get());
        } else {
            Assertions.assertEquals(0, t.getMaxFee().intValue());
        }
    });
}
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 14 with TransactionRepository

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

the class ListenerIntegrationTest method shouldReturnCosignatureAddedViaListener.

@ParameterizedTest
@EnumSource(RepositoryType.class)
@Disabled
void shouldReturnCosignatureAddedViaListener(RepositoryType type) {
    Listener listener = getListener(type);
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    TransactionService transactionService = new TransactionServiceImpl(repositoryFactory);
    Pair<SignedTransaction, SignedTransaction> pair = this.createAggregateBondedTransaction(type);
    System.out.println("Announcing HashLock transaction " + pair.getRight().getHash());
    get(transactionService.announce(listener, pair.getRight()));
    SignedTransaction signedTransaction = pair.getLeft();
    AggregateTransaction announcedTransaction = get(transactionService.announceAggregateBonded(listener, signedTransaction));
    assertEquals(signedTransaction.getHash(), announcedTransaction.getTransactionInfo().get().getHash().get());
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).transactionTypes(Collections.singletonList(TransactionType.AGGREGATE_BONDED)).signerPublicKey(this.cosignatoryAccount.getPublicAccount().getPublicKey()))).getData();
    AggregateTransaction transactionToCosign = (AggregateTransaction) transactions.get(0);
    this.announceCosignatureTransaction(transactionToCosign, type);
    CosignatureSignedTransaction cosignatureSignedTransaction = get(listener.cosignatureAdded(this.cosignatoryAccount.getAddress()).take(1));
    assertEquals(cosignatureSignedTransaction.getSigner(), this.cosignatoryAccount2.getPublicAccount());
}
Also used : CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Listener(io.nem.symbol.sdk.api.Listener) TransactionService(io.nem.symbol.sdk.api.TransactionService) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Disabled(org.junit.jupiter.api.Disabled)

Example 15 with TransactionRepository

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

the class AccountRepositoryIntegrationTest method getMosaicGlobalRegistration.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicGlobalRegistration(RepositoryType type) {
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    Account account = config().getDefaultAccount();
    TransactionType transactionType = TransactionType.MOSAIC_GLOBAL_RESTRICTION;
    List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).transactionTypes(Collections.singletonList(transactionType)).signerPublicKey(account.getPublicAccount().getPublicKey()).pageSize(10))).getData();
    System.out.println(transactions.size());
    Assertions.assertFalse(transactions.isEmpty());
    transactions.forEach(t -> Assertions.assertEquals(transactionType, t.getType()));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)24 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)24 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)24 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)22 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)14 TransactionPaginationStreamer (io.nem.symbol.sdk.api.TransactionPaginationStreamer)13 Account (io.nem.symbol.sdk.model.account.Account)8 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)7 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)6 TransactionGroup (io.nem.symbol.sdk.model.transaction.TransactionGroup)6 BigInteger (java.math.BigInteger)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 Collections (java.util.Collections)4 List (java.util.List)4