Search in sources :

Example 21 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction 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);
}
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) Account(io.nem.symbol.sdk.model.account.Account) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) 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) 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) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction 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 23 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction 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 24 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction 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 25 with Transaction

use of io.nem.symbol.sdk.model.transaction.Transaction in project nem2-sdk-java by nemtech.

the class TransactionRepositoryIntegrationTest method setup.

@BeforeAll
void setup() {
    RepositoryType type = RepositoryType.VERTX;
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    Address recipient = getRecipient();
    String message = "someMessage";
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage(message)).maxFee(maxFee).build();
    TransferTransaction processed = announceAndValidate(type, config().getDefaultAccount(), transferTransaction);
    Assertions.assertEquals(message, processed.getMessage().get().getText());
    PublicAccount account = config().getDefaultAccount().getPublicAccount();
    List<Transaction> allTransactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).order(OrderBy.DESC).signerPublicKey(account.getPublicKey()))).getData();
    List<Transaction> transactions = allTransactions.stream().filter(t -> t.getType() == TransactionType.TRANSFER).collect(Collectors.toList());
    Assertions.assertTrue(allTransactions.size() > 0);
    Assertions.assertTrue(transactions.size() > 0);
    transactionHash = transactions.get(0).getTransactionInfo().get().getHash().get();
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) TransactionStatus(io.nem.symbol.sdk.model.transaction.TransactionStatus) TransactionStatusRepository(io.nem.symbol.sdk.api.TransactionStatusRepository) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) EnumSource(org.junit.jupiter.params.provider.EnumSource) TestInstance(org.junit.jupiter.api.TestInstance) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BeforeAll(org.junit.jupiter.api.BeforeAll) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) OrderBy(io.nem.symbol.sdk.api.OrderBy) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) 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) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Transaction (io.nem.symbol.sdk.model.transaction.Transaction)125 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)107 Test (org.junit.jupiter.api.Test)78 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)70 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)65 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)60 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)58 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)58 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)57 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)57 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)57 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)55 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)55 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)55 SecretLockTransaction (io.nem.symbol.sdk.model.transaction.SecretLockTransaction)55 SecretProofTransaction (io.nem.symbol.sdk.model.transaction.SecretProofTransaction)55 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)54 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)54 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)54 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)54