Search in sources :

Example 11 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress 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 12 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class TransactionServiceTest method transferTransactionResolveAlias.

@Test
void transferTransactionResolveAlias() 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).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    simulateStatement(height, 1, 0);
    TransferTransaction transaction = factory.build();
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    TransferTransaction resolvedTransaction = (TransferTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(transaction.getMosaics().size(), resolvedTransaction.getMosaics().size());
    Assertions.assertEquals(transaction.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(transaction.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) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) 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 13 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress 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 14 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress 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 15 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class MapperUtilsTest method toUnresolvedAddressZeroPadded.

@Test
void toUnresolvedAddressZeroPadded() {
    UnresolvedAddress actual = MapperUtils.toUnresolvedAddress("01E7CA7E22727DDD8800000000000000000000000000000000");
    Assertions.assertTrue(actual instanceof NamespaceId);
    Assertions.assertEquals("88DD7D72227ECAE7", ((NamespaceId) actual).getIdAsHex());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Aggregations

UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)35 BigInteger (java.math.BigInteger)13 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)11 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)11 Test (org.junit.jupiter.api.Test)11 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)10 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)10 Address (io.nem.symbol.sdk.model.account.Address)8 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)8 ArrayList (java.util.ArrayList)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Account (io.nem.symbol.sdk.model.account.Account)7 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)7 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)7 Observable (io.reactivex.Observable)7 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)6 EnumSource (org.junit.jupiter.params.provider.EnumSource)6 Listener (io.nem.symbol.sdk.api.Listener)5 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)5 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)5