use of io.nem.symbol.sdk.model.transaction.TransferTransaction 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.TransferTransaction 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);
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method basicTransfer.
private List<String> basicTransfer(RepositoryType type, UnresolvedAddress recipient, String s, int i, List<String> expected, boolean includeAliases, UnresolvedAddress... listenTo) throws InterruptedException, ExecutionException {
List<String> messages = new ArrayList<>();
Listener listener = listen(type, messages, includeAliases, listenTo);
sleep(1000);
try {
String message = s;
Currency networkCurrency = getNetworkCurrency();
Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(i));
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(new PlainMessage(message)).maxFee(maxFee).build();
TransferTransaction processed = announceAggregateAndValidate(type, transferTransaction, signerAccount).getKey();
Assertions.assertEquals(message, processed.getMessage().get().getText());
sleep(1000);
Assertions.assertEquals(expected, messages);
return messages;
} finally {
listener.close();
}
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method standaloneCreatePersistentDelegationRequestTransaction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void standaloneCreatePersistentDelegationRequestTransaction(RepositoryType type) {
KeyPair signingKeyPair = KeyPair.random();
KeyPair vrfPrivateKey = KeyPair.random();
KeyPair recipientKeyPair = KeyPair.random();
TransferTransaction transferTransaction = TransferTransactionFactory.createPersistentDelegationRequestTransaction(getNetworkType(), getDeadline(), signingKeyPair.getPrivateKey(), vrfPrivateKey.getPrivateKey(), recipientKeyPair.getPublicKey()).maxFee(maxFee).build();
TransferTransaction processed = announceAndValidate(type, signerAccount, transferTransaction);
assertPersistentDelegationTransaction(recipientKeyPair, signingKeyPair, vrfPrivateKey, processed);
TransferTransaction restTransaction = (TransferTransaction) get(getRepositoryFactory(type).createTransactionRepository().getTransaction(TransactionGroup.CONFIRMED, processed.getTransactionInfo().get().getHash().get()));
assertPersistentDelegationTransaction(recipientKeyPair, signingKeyPair, vrfPrivateKey, restTransaction);
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method transferTransactionNotEnoughFundAccount.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void transferTransactionNotEnoughFundAccount(RepositoryType type) {
Address recipient = config().getTestAccount2().getAddress();
NetworkType networkType = getNetworkType();
Account account = Account.generateNewAccount(networkType);
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1000000000)))).message(new PlainMessage("")).maxFee(maxFee).build();
IllegalArgumentException exceptions = Assertions.assertThrows(IllegalArgumentException.class, () -> announceAndValidate(type, account, transferTransaction));
Assertions.assertTrue(exceptions.getMessage().contains("Failure_Core_Insufficient_Balance"));
}
Aggregations