use of io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction in project nem2-sdk-java by nemtech.
the class TestHelper method setMosaicAlias.
protected NamespaceId setMosaicAlias(RepositoryType type, MosaicId mosaicId, String namespaceName) {
Account nemesisAccount = config().getNemesisAccount1();
NamespaceId namespaceId = NamespaceId.createFromName(namespaceName);
if (isAlias(type, mosaicId, namespaceId)) {
System.out.println(namespaceName + " MOSAIC Alias found, reusing it.");
return namespaceId;
} else {
System.out.println(namespaceName + " MOSAIC Alias not found, CREATING MOSAIC ALIAS");
}
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 mosaic alias " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
MosaicAliasTransaction aliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
announceAggregateAndValidate(type, aliasTransaction, nemesisAccount);
int retry = 10;
while (!isAlias(type, mosaicId, namespaceId)) {
sleep(300);
retry--;
if (retry == 0) {
Assertions.fail("Could not create " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
}
}
return rootNamespaceId;
}
use of io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction 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;
}
use of io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction in project nem2-sdk-java by nemtech.
the class MosaicAliasTransactionIntegrationTest method sendMosaicAliasTransaction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void sendMosaicAliasTransaction(RepositoryType type) {
String namespaceName = "test-root-namespace-for-mosaic-alias-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
Account account = this.config().getDefaultAccount();
AccountInfo accountInfo = get(getRepositoryFactory(type).createAccountRepository().getAccountInfo(account.getPublicAccount().getAddress()));
Assertions.assertFalse(accountInfo.getMosaics().isEmpty());
MosaicId mosaicId = createMosaic(account, type, BigInteger.ZERO, null);
NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, helper().getDuration()).maxFee(maxFee).build();
NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, account).getLeft().getNamespaceId();
MosaicAliasTransaction addressAliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
announceAggregateAndValidate(type, addressAliasTransaction, account);
List<MosaicNames> accountNames = get(getRepositoryFactory(type).createNamespaceRepository().getMosaicsNames(Collections.singletonList(mosaicId)));
Assertions.assertEquals(1, accountNames.size());
assertEquals(1, accountNames.size());
assertEquals(mosaicId, accountNames.get(0).getMosaicId());
assertTrue(accountNames.get(0).getNames().stream().anyMatch(n -> namespaceName.equals(n.getName())));
}
use of io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction in project nem2-sdk-java by nemtech.
the class NamespaceRegistrationIntegrationTest method aggregateSubNamespaceRegisterNamespaceTransaction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void aggregateSubNamespaceRegisterNamespaceTransaction(RepositoryType type) {
this.aggregateRootRegisterNamespaceTransaction(type);
String namespaceName = "test-sub-namespace-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createSubNamespace(getNetworkType(), getDeadline(), namespaceName, this.rootNamespaceId).maxFee(maxFee).build();
announceAggregateAndValidate(type, namespaceRegistrationTransaction, this.account);
sleep(1000);
NamespaceInfo namespaceInfo = get(getRepositoryFactory(type).createNamespaceRepository().getNamespace(namespaceRegistrationTransaction.getNamespaceId()));
Assertions.assertEquals(this.account.getAddress(), namespaceInfo.getOwnerAddress());
Assertions.assertEquals(namespaceRegistrationTransaction.getNamespaceId(), namespaceInfo.getId());
}
Aggregations