Search in sources :

Example 1 with AddressAliasTransaction

use of io.nem.symbol.sdk.model.transaction.AddressAliasTransaction in project nem2-sdk-java by nemtech.

the class AddressAliasTransactionIntegrationTest method sendAddressAliasTransactionAggregate.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void sendAddressAliasTransactionAggregate(RepositoryType type) {
    Account account = config().getDefaultAccount();
    String namespaceName = "test-root-namespace-aggregate-for-address-alias-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, helper().getDuration()).maxFee(maxFee).build();
    NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, account).getLeft().getNamespaceId();
    AddressAliasTransaction addressAliasTransaction = AddressAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, account.getAddress()).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction2 = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(addressAliasTransaction.toAggregate(account.getPublicAccount()))).maxFee(maxFee).build();
    announceAndValidate(type, account, aggregateTransaction2);
    sleep(1000);
    List<AccountNames> accountNames = get(getRepositoryFactory(type).createNamespaceRepository().getAccountsNames(Collections.singletonList(account.getAddress())));
    Assertions.assertEquals(1, accountNames.size());
    assertEquals(1, accountNames.size());
    assertEquals(account.getAddress(), accountNames.get(0).getAddress());
    assertTrue(accountNames.get(0).getNames().stream().map(NamespaceName::getName).collect(Collectors.toList()).contains(namespaceName));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) AccountNames(io.nem.symbol.sdk.model.account.AccountNames) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AddressAliasTransaction

use of io.nem.symbol.sdk.model.transaction.AddressAliasTransaction in project nem2-sdk-java by nemtech.

the class AddressAliasTransactionIntegrationTest method sendAddressAliasTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void sendAddressAliasTransaction(RepositoryType type) {
    Account account = config().getDefaultAccount();
    String namespaceName = "test-root-namespace-for-address-alias-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, helper().getDuration()).maxFee(maxFee).build();
    NamespaceId rootNamespaceId = announceAndValidate(type, account, namespaceRegistrationTransaction).getNamespaceId();
    AddressAliasTransaction addressAliasTransaction = AddressAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, account.getAddress()).maxFee(maxFee).build();
    announceAndValidate(type, account, addressAliasTransaction);
    sleep(1000);
    List<AccountNames> accountNames = get(getRepositoryFactory(type).createNamespaceRepository().getAccountsNames(Collections.singletonList(account.getAddress())));
    Assertions.assertEquals(1, accountNames.size());
    assertEquals(1, accountNames.size());
    assertEquals(account.getAddress(), accountNames.get(0).getAddress());
    assertTrue(accountNames.get(0).getNames().stream().map(NamespaceName::getName).collect(Collectors.toList()).contains(namespaceName));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) AccountNames(io.nem.symbol.sdk.model.account.AccountNames) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with AddressAliasTransaction

use of io.nem.symbol.sdk.model.transaction.AddressAliasTransaction in project nem2-sdk-java by nemtech.

the class TransactionMapperVertxTest method shouldCreateAggregateAddressAliasTransaction.

@Test
void shouldCreateAggregateAddressAliasTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperVertx.loadTransactionInfoDTO("aggregateAddressAliasTransaction.json");
    Transaction aggregateTransferTransaction = map(aggregateTransferTransactionDTO);
    validateAggregateTransaction((AggregateTransaction) aggregateTransferTransaction, aggregateTransferTransactionDTO);
    AddressAliasTransaction transaction = (AddressAliasTransaction) ((AggregateTransaction) aggregateTransferTransaction).getInnerTransactions().get(0);
    Assertions.assertEquals("SDT4THYNVUQK2GM6XXYTWHZXSPE3AUA2GTDPM2Q", transaction.getAddress().plain());
    Assertions.assertEquals(AliasAction.LINK, transaction.getAliasAction());
    Assertions.assertEquals(new BigInteger("307262000798378"), transaction.getNamespaceId().getId());
}
Also used : SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AccountKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 4 with AddressAliasTransaction

use of io.nem.symbol.sdk.model.transaction.AddressAliasTransaction in project nem2-sdk-java by nemtech.

the class TransactionMapperOkHttpTest method shouldCreateAggregateAddressAliasTransaction.

@Test
void shouldCreateAggregateAddressAliasTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateAddressAliasTransaction.json");
    Transaction aggregateTransferTransaction = map(aggregateTransferTransactionDTO);
    validateAggregateTransaction((AggregateTransaction) aggregateTransferTransaction, aggregateTransferTransactionDTO);
    AddressAliasTransaction transaction = (AddressAliasTransaction) ((AggregateTransaction) aggregateTransferTransaction).getInnerTransactions().get(0);
    Assertions.assertEquals("SDT4THYNVUQK2GM6XXYTWHZXSPE3AUA2GTDPM2Q", transaction.getAddress().plain());
    Assertions.assertEquals(AliasAction.LINK, transaction.getAliasAction());
    Assertions.assertEquals(new BigInteger("307262000798378"), transaction.getNamespaceId().getId());
}
Also used : SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AccountKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 5 with AddressAliasTransaction

use of io.nem.symbol.sdk.model.transaction.AddressAliasTransaction in project nem2-sdk-java by nemtech.

the class TestHelper method setAddressAlias.

public NamespaceId setAddressAlias(RepositoryType type, Address address, String namespaceName) {
    NamespaceId namespaceId = NamespaceId.createFromName(namespaceName);
    if (isAlias(type, address, namespaceId)) {
        System.out.println(namespaceName + " ADDRESS Alias for address " + address.plain() + " found, reusing it.");
        return namespaceId;
    }
    System.out.println(namespaceName + " ADDRESS Alias not found, CREATING ADDRESS " + address.plain() + " ALIAS");
    Account nemesisAccount = config().getNemesisAccount1();
    System.out.println("Setting up namespace " + namespaceName);
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, getDuration()).maxFee(maxFee).build();
    NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, nemesisAccount).getLeft().getNamespaceId();
    System.out.println("Setting account alias " + address.plain() + " alias: " + namespaceName);
    AddressAliasTransaction aliasTransaction = AddressAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, address).maxFee(maxFee).build();
    announceAggregateAndValidate(type, aliasTransaction, nemesisAccount);
    int retry = 10;
    while (!isAlias(type, address, namespaceId)) {
        sleep(300);
        retry--;
        if (retry == 0) {
            Assertions.fail("Could not create " + address.plain() + " alias: " + namespaceName);
        }
    }
    return rootNamespaceId;
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)

Aggregations

AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)5 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)5 Account (io.nem.symbol.sdk.model.account.Account)3 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)3 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)3 AccountNames (io.nem.symbol.sdk.model.account.AccountNames)2 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)2 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)2 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)2 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)2 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)2 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)2 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)2 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)2 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)2 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)2 SecretLockTransaction (io.nem.symbol.sdk.model.transaction.SecretLockTransaction)2 SecretProofTransaction (io.nem.symbol.sdk.model.transaction.SecretProofTransaction)2