Search in sources :

Example 26 with PlainMessage

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

the class ListenerIntegrationTest method announceStandaloneTransferTransactionWithInsufficientBalance.

private SignedTransaction announceStandaloneTransferTransactionWithInsufficientBalance(RepositoryType type) {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), Address.generateRandom(getNetworkType()), Collections.singletonList(getNetworkCurrency().createRelative(new BigInteger("100000000000")))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
    SignedTransaction signedTransaction = this.account.sign(transferTransaction, getGenerationHash());
    get(getTransactionRepository(type).announce(signedTransaction));
    return signedTransaction;
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

Example 27 with PlainMessage

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

the class TransactionServiceTest method aggregateTransferTransactionResolveAlias.

@Test
void aggregateTransferTransactionResolveAlias() throws ExecutionException, InterruptedException {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
    mosaics.add(new Mosaic(mosaicId3, BigInteger.valueOf(3)));
    UnresolvedAddress recipient = addressNamespace1;
    String transactionHash = "aaaa";
    TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipient, mosaics).message(new PlainMessage("")).transactionInfo(TransactionInfo.create(height, 0, "ABC", "BBBB", ""));
    // Extra transfer not aliases
    TransactionFactory<TransferTransaction> extraTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), address2, Collections.singletonList(new Mosaic(mosaicId1, BigInteger.valueOf(1)))).transactionInfo(TransactionInfo.create(height, 1, "ABC", "CCCC", ""));
    TransferTransaction transferTransaction = factory.build();
    transferTransaction.toAggregate(Account.generateNewAccount(networkType).getPublicAccount());
    TransactionFactory<AggregateTransaction> aggregateTransactionFactory = AggregateTransactionFactory.createComplete(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction, extraTransaction.build().toAggregate(Account.generateNewAccount(networkType).getPublicAccount()))).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    AggregateTransaction aggregateTransaction = aggregateTransactionFactory.build();
    simulateStatement(height, 1, 1);
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(aggregateTransaction)));
    AggregateTransaction aggregateResolvedTransaction = (AggregateTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    TransferTransaction resolvedTransaction = (TransferTransaction) aggregateResolvedTransaction.getInnerTransactions().get(0);
    Assertions.assertEquals(transferTransaction.getMosaics().size(), resolvedTransaction.getMosaics().size());
    Assertions.assertEquals(transferTransaction.getMosaics().get(0).getId(), resolvedTransaction.getMosaics().get(0).getId());
    Assertions.assertEquals(BigInteger.valueOf(1), resolvedTransaction.getMosaics().get(0).getAmount());
    Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaics().get(1).getId());
    Assertions.assertEquals(BigInteger.valueOf(2), resolvedTransaction.getMosaics().get(1).getAmount());
    Assertions.assertEquals(transferTransaction.getMosaics().get(2).getId(), resolvedTransaction.getMosaics().get(2).getId());
    Assertions.assertEquals(BigInteger.valueOf(3), resolvedTransaction.getMosaics().get(2).getAmount());
    Assertions.assertEquals(address1, resolvedTransaction.getRecipient());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) ArrayList(java.util.ArrayList) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 28 with PlainMessage

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

the class TransactionServiceTest method aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfoInner.

@Test
void aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfoInner() {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
    mosaics.add(new Mosaic(mosaicId3, BigInteger.valueOf(3)));
    UnresolvedAddress recipient = addressNamespace1;
    String transactionHash = "aaaa";
    TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipient, mosaics).message(new PlainMessage("")).transactionInfo(TransactionInfo.create(height, 0, "ABC", "BBBB", ""));
    // Extra transfer not aliases
    TransactionFactory<TransferTransaction> extraTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), address2, Collections.singletonList(new Mosaic(mosaicId1, BigInteger.valueOf(1)))).message(new PlainMessage(""));
    TransferTransaction transferTransaction = factory.build();
    transferTransaction.toAggregate(Account.generateNewAccount(networkType).getPublicAccount());
    TransactionFactory<AggregateTransaction> aggregateTransactionFactory = AggregateTransactionFactory.createComplete(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction, extraTransaction.build().toAggregate(Account.generateNewAccount(networkType).getPublicAccount()))).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    AggregateTransaction aggregateTransaction = aggregateTransactionFactory.build();
    simulateStatement(height, 1, 1);
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(aggregateTransaction)));
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
        ExceptionUtils.propagate(service.resolveAliases(hashes).toFuture()::get);
    });
    Assertions.assertEquals("TransactionIndex cannot be loaded from Transaction TRANSFER", exception.getMessage());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) ArrayList(java.util.ArrayList) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 29 with PlainMessage

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

the class TransactionServiceTest method aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfo.

@Test
void aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfo() {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
    mosaics.add(new Mosaic(mosaicId3, BigInteger.valueOf(3)));
    UnresolvedAddress recipient = addressNamespace1;
    String transactionHash = "aaaa";
    TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipient, mosaics).message(new PlainMessage("")).transactionInfo(TransactionInfo.create(height, 0, "ABC", "BBBB", ""));
    // Extra transfer not aliases
    TransactionFactory<TransferTransaction> extraTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), address2, Collections.singletonList(new Mosaic(mosaicId1, BigInteger.valueOf(1)))).message(new PlainMessage(""));
    TransferTransaction transferTransaction = factory.build();
    transferTransaction.toAggregate(Account.generateNewAccount(networkType).getPublicAccount());
    TransactionFactory<AggregateTransaction> aggregateTransactionFactory = AggregateTransactionFactory.createComplete(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction, extraTransaction.build().toAggregate(Account.generateNewAccount(networkType).getPublicAccount()))).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    AggregateTransaction aggregateTransaction = aggregateTransactionFactory.build();
    simulateStatement(height, 1, 1);
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(aggregateTransaction)));
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
        ExceptionUtils.propagate(service.resolveAliases(hashes).toFuture()::get);
    });
    Assertions.assertEquals("TransactionIndex cannot be loaded from Transaction TRANSFER", exception.getMessage());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) ArrayList(java.util.ArrayList) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 30 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusForAggregatedCompleteTransaction2LevelsMultisigMultiinnerTransaction.

/*
   * MLMA - with multiple transaction Alice (account1): normal account Bob (multisig2) - Multisig
   * 2-1 (account1 && multisig1) Charles (multisig1) - Multisig 1-1 (account2 || account3) An
   * extra inner transaction to account4 (just to increase the complexity) Given signatories:
   * Account1 && Account4 Expecting incomplete as Bob needs 2 signatures (account1 && (account2 ||
   * account3))
   */
@Test
void shouldReturnCorrectIsCompleteStatusForAggregatedCompleteTransaction2LevelsMultisigMultiinnerTransaction() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    TransferTransaction transferTransaction2 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account2.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction.toAggregate(multisig2.getPublicAccount()), transferTransaction2.toAggregate(account4.getPublicAccount()))).build();
    SignedTransaction signedTransaction = account1.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account4), generationHash);
    Assertions.assertFalse(service.isComplete(signedTransaction).toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)63 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)45 Test (org.junit.jupiter.api.Test)45 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)31 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)30 Address (io.nem.symbol.sdk.model.account.Address)26 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)23 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)23 BigInteger (java.math.BigInteger)20 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)17 Account (io.nem.symbol.sdk.model.account.Account)14 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 ArrayList (java.util.ArrayList)7 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)6 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)6 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)6 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)6 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)5