Search in sources :

Example 31 with UnresolvedAddress

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

the class TransactionServiceTest method transferTransactionResolveAliasCannotAddressResolveAliases.

@Test
void transferTransactionResolveAliasCannotAddressResolveAliases() {
    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, 0, 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)));
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ExceptionUtils.propagate(() -> service.resolveAliases(hashes).toFuture().get()));
    Assertions.assertEquals("Address could not be resolved for alias " + addressNamespace1.getIdAsHex(), exception.getMessage());
}
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 32 with UnresolvedAddress

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

the class TransactionServiceTest method secretLockTransactionResolveAlias.

@Test
void secretLockTransactionResolveAlias() throws ExecutionException, InterruptedException {
    Mosaic unresolvedMosaicId = new Mosaic(mosaicNamespace2, BigInteger.valueOf(2));
    UnresolvedAddress recipient = addressNamespace1;
    String transactionHash = "aaaa";
    String secret = "3fc8ba10229ab5778d05d9c4b7f56676a88bf9295c185acfc0f961db5408cafe";
    TransactionFactory<SecretLockTransaction> factory = SecretLockTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), unresolvedMosaicId, BigInteger.TEN, LockHashAlgorithm.SHA3_256, secret, recipient).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    simulateStatement(height, 1, 0);
    SecretLockTransaction 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)));
    SecretLockTransaction resolvedTransaction = (SecretLockTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaic().getId());
    Assertions.assertEquals(address1, resolvedTransaction.getRecipient());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) Test(org.junit.jupiter.api.Test)

Example 33 with UnresolvedAddress

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

the class TransactionServiceTest method transferTransactionResolveAliasCannotMosaicAliasResolveAliases.

@Test
void transferTransactionResolveAliasCannotMosaicAliasResolveAliases() {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
    NamespaceId idontexist = NamespaceId.createFromName("idontexist");
    mosaics.add(new Mosaic(idontexist, 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)));
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ExceptionUtils.propagate(() -> service.resolveAliases(hashes).toFuture().get()));
    Assertions.assertEquals("MosaicId could not be resolved for alias " + idontexist.getIdAsHex(), exception.getMessage());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) ArrayList(java.util.ArrayList) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 34 with UnresolvedAddress

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

the class ResolutionStatement method serialize.

/**
 * Serializes the statement using the catuffer builders
 *
 * @param networkType the network type.
 * @return the serialized content.
 */
private byte[] serialize(NetworkType networkType) {
    ReceiptType type = this.resolutionType == ResolutionType.ADDRESS ? ReceiptType.ADDRESS_ALIAS_RESOLUTION : ReceiptType.MOSAIC_ALIAS_RESOLUTION;
    ReceiptTypeDto recipientTypeDto = ReceiptTypeDto.rawValueOf((short) type.getValue());
    short version = (short) ReceiptVersion.RESOLUTION_STATEMENT.getValue();
    Serializer serializer = this.resolutionType == ResolutionType.ADDRESS ? AddressResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedAddress((UnresolvedAddress) this.unresolved, networkType), this.resolutionEntries.stream().map((entry) -> AddressResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toAddressDto((Address) entry.getResolved()))).collect(Collectors.toList())) : MosaicResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedMosaicIdDto((UnresolvedMosaicId) this.unresolved), this.resolutionEntries.stream().map((entry) -> MosaicResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toMosaicIdDto((MosaicId) entry.getResolved()))).collect(Collectors.toList()));
    return serializer.serialize();
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicResolutionStatementBuilder(io.nem.symbol.catapult.builders.MosaicResolutionStatementBuilder) Hashes(io.nem.symbol.core.crypto.Hashes) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptSourceBuilder(io.nem.symbol.catapult.builders.ReceiptSourceBuilder) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Collectors(java.util.stream.Collectors) Stored(io.nem.symbol.sdk.model.Stored) AddressResolutionStatementBuilder(io.nem.symbol.catapult.builders.AddressResolutionStatementBuilder) MosaicResolutionEntryBuilder(io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder) Serializer(io.nem.symbol.catapult.builders.Serializer) List(java.util.List) AddressResolutionEntryBuilder(io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Address(io.nem.symbol.sdk.model.account.Address) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) SerializationUtils(io.nem.symbol.sdk.infrastructure.SerializationUtils) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Serializer(io.nem.symbol.catapult.builders.Serializer)

Example 35 with UnresolvedAddress

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

the class MultisigAccountModificationTransactionTest method createAMultisigModificationTransactionViaConstructor.

@Test
void createAMultisigModificationTransactionViaConstructor() {
    Duration epochAdjustment = Duration.ofSeconds(100);
    List<UnresolvedAddress> additions = Collections.singletonList(PublicAccount.createFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b111", NetworkType.MIJIN_TEST).getAddress());
    List<UnresolvedAddress> deletions = Collections.singletonList(PublicAccount.createFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b222", NetworkType.MIJIN_TEST).getAddress());
    MultisigAccountModificationTransaction multisigAccountModificationTransaction = MultisigAccountModificationTransactionFactory.create(NetworkType.MIJIN_TEST, Deadline.create(epochAdjustment), (byte) 2, (byte) 1, additions, deletions).build();
    assertEquals(NetworkType.MIJIN_TEST, multisigAccountModificationTransaction.getNetworkType());
    assertTrue(1 == multisigAccountModificationTransaction.getVersion());
    assertTrue(LocalDateTime.now().isBefore(multisigAccountModificationTransaction.getDeadline().getLocalDateTime(epochAdjustment)));
    assertEquals(BigInteger.valueOf(0), multisigAccountModificationTransaction.getMaxFee());
    assertEquals(2, multisigAccountModificationTransaction.getMinApprovalDelta());
    assertEquals(1, multisigAccountModificationTransaction.getMinRemovalDelta());
    assertEquals(additions, multisigAccountModificationTransaction.getAddressAdditions());
    assertEquals(deletions, multisigAccountModificationTransaction.getAddressDeletions());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Duration(java.time.Duration) 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