Search in sources :

Example 1 with Message

use of io.nem.symbol.sdk.model.message.Message 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 2 with Message

use of io.nem.symbol.sdk.model.message.Message in project nem2-sdk-java by nemtech.

the class TransferTransactionIntegrationTest method standaloneTransferTransactionEncryptedMessage.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void standaloneTransferTransactionEncryptedMessage(RepositoryType type) throws Exception {
    this.helper().sendMosaicFromNemesis(type, getRecipient(), false);
    String namespaceName = "standaloneTransferTransactionEncryptedMessagealias".toLowerCase();
    NamespaceId recipient = setAddressAlias(type, getRecipient(), namespaceName);
    System.out.println(recipient.getIdAsHex());
    Assertions.assertEquals("9960629109A48AFBC0000000000000000000000000000000", recipient.encoded(getNetworkType()));
    String message = "E2ETest:standaloneTransferTransaction:message 漢字";
    KeyPair senderKeyPair = KeyPair.random();
    KeyPair recipientKeyPair = KeyPair.random();
    Message encryptedMessage = EncryptedMessage.create(message, senderKeyPair.getPrivateKey(), recipientKeyPair.getPublicKey());
    Currency networkCurrency = getNetworkCurrency();
    Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(10202020));
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(encryptedMessage).maxFee(maxFee).build();
    TransferTransaction processed = announceAndValidate(type, signerAccount, transferTransaction);
    assertTransferTransactions(transferTransaction, processed);
    assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, processed);
    TransferTransaction restTransaction = (TransferTransaction) get(getRepositoryFactory(type).createTransactionRepository().getTransaction(TransactionGroup.CONFIRMED, processed.getTransactionInfo().get().getHash().get()));
    assertTransferTransactions(transferTransaction, restTransaction);
    assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, restTransaction);
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) Message(io.nem.symbol.sdk.model.message.Message) EncryptedMessage(io.nem.symbol.sdk.model.message.EncryptedMessage) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) PersistentHarvestingDelegationMessage(io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage) Currency(io.nem.symbol.sdk.model.mosaic.Currency) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Message

use of io.nem.symbol.sdk.model.message.Message 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());
}
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 4 with Message

use of io.nem.symbol.sdk.model.message.Message 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)

Aggregations

Message (io.nem.symbol.sdk.model.message.Message)4 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)4 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 TransactionPaginationStreamer (io.nem.symbol.sdk.api.TransactionPaginationStreamer)3 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)3 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)3 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)3 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)3 TransactionGroup (io.nem.symbol.sdk.model.transaction.TransactionGroup)3 KeyPair (io.nem.symbol.core.crypto.KeyPair)1 PublicKey (io.nem.symbol.core.crypto.PublicKey)1 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)1 Account (io.nem.symbol.sdk.model.account.Account)1 Address (io.nem.symbol.sdk.model.account.Address)1 EncryptedMessage (io.nem.symbol.sdk.model.message.EncryptedMessage)1 PersistentHarvestingDelegationMessage (io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage)1 Currency (io.nem.symbol.sdk.model.mosaic.Currency)1 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)1