use of io.nem.symbol.sdk.model.message.PlainMessage 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.message.PlainMessage 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"));
}
use of io.nem.symbol.sdk.model.message.PlainMessage 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();
}
use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.
the class TransactionServiceIntegrationTest method transferUsingAliasesAggregate.
private AggregateTransaction transferUsingAliasesAggregate(Account sender, RepositoryType type, String mosaicAlias, String recipientAlias, BigInteger amount) {
NamespaceId recipientNamespace = NamespaceId.createFromName(recipientAlias);
NamespaceId mosaicNamespace = NamespaceId.createFromName(mosaicAlias);
System.out.println("Sending " + amount + " Mosaic to: " + mosaicAlias);
TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipientNamespace, Collections.singletonList(new Mosaic(mosaicNamespace, amount))).message(new PlainMessage("E2ETest:TransactionServiceIntegrationTest"));
factory.maxFee(maxFee);
TransferTransaction transferTransaction = factory.build();
Assertions.assertTrue(transferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
Assertions.assertTrue(transferTransaction.getRecipient() instanceof NamespaceId);
Pair<TransferTransaction, AggregateTransaction> pair = announceAggregateAndValidate(type, transferTransaction, sender);
TransferTransaction processedTransferTransaction = pair.getLeft();
Assertions.assertEquals(amount, processedTransferTransaction.getMosaics().get(0).getAmount());
System.out.println(toJson(processedTransferTransaction));
Assertions.assertTrue(processedTransferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
Assertions.assertTrue(processedTransferTransaction.getRecipient() instanceof NamespaceId);
return pair.getRight();
}
use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method createAggregateBondedTransaction.
private Pair<SignedTransaction, SignedTransaction> createAggregateBondedTransaction(RepositoryType type) {
helper().sendMosaicFromNemesis(type, this.cosignatoryAccount.getAddress(), false);
helper().sendMosaicFromNemesis(type, this.cosignatoryAccount2.getAddress(), false);
helper().sendMosaicFromNemesis(type, this.multisigAccount.getAddress(), false);
helper().createMultisigAccountBonded(type, this.multisigAccount, this.cosignatoryAccount, this.cosignatoryAccount2);
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), Account.generateNewAccount(getNetworkType()).getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(transferTransaction.toAggregate(this.multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction aggregateSignedTransaction = this.cosignatoryAccount.sign(aggregateTransaction, getGenerationHash());
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), aggregateSignedTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = hashLockTransaction.signWith(this.cosignatoryAccount, getGenerationHash());
return Pair.of(aggregateSignedTransaction, signedHashLockTransaction);
}
Aggregations