Search in sources :

Example 11 with NamespaceRegistrationTransaction

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;
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)

Example 12 with NamespaceRegistrationTransaction

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

Example 13 with NamespaceRegistrationTransaction

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())));
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) Account(io.nem.symbol.sdk.model.account.Account) EnumSource(org.junit.jupiter.params.provider.EnumSource) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicAliasTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicAliasTransactionFactory) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TestInstance(org.junit.jupiter.api.TestInstance) NamespaceRegistrationTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) Assertions(org.junit.jupiter.api.Assertions) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AliasAction(io.nem.symbol.sdk.model.namespace.AliasAction) Collections(java.util.Collections) Account(io.nem.symbol.sdk.model.account.Account) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with NamespaceRegistrationTransaction

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());
}
Also used : NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)14 Account (io.nem.symbol.sdk.model.account.Account)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)5 NamespaceInfo (io.nem.symbol.sdk.model.namespace.NamespaceInfo)4 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)3 AccountNames (io.nem.symbol.sdk.model.account.AccountNames)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)2 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)2 SecretProofTransaction (io.nem.symbol.sdk.model.transaction.SecretProofTransaction)2 TransactionInfo (io.nem.symbol.sdk.model.transaction.TransactionInfo)2 Order (org.junit.jupiter.api.Order)2 Test (org.junit.jupiter.api.Test)2 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)2 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)1 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)1 AliasAction (io.nem.symbol.sdk.model.namespace.AliasAction)1