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));
}
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));
}
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());
}
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());
}
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;
}
Aggregations