Search in sources :

Example 56 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class MosaicAliasTransactionTest method shouldBuild.

@Test
void shouldBuild() {
    MosaicId mosaicId = new MosaicId(BigInteger.TEN);
    NamespaceId namespaceId = NamespaceId.createFromName("anamespaced");
    MosaicAliasTransaction transaction = MosaicAliasTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), AliasAction.LINK, namespaceId, mosaicId).build();
    assertEquals(NetworkType.MIJIN_TEST, transaction.getNetworkType());
    assertEquals(AliasAction.LINK, transaction.getAliasAction());
    assertEquals(mosaicId, transaction.getMosaicId());
    assertEquals(namespaceId, transaction.getNamespaceId());
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 57 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class AddressAliasTransactionTest method shouldSerialize.

@Test
void shouldSerialize() {
    NetworkType networkType = NetworkType.MIJIN_TEST;
    BigInteger fee = BigInteger.ONE;
    NamespaceId namespaceId = NamespaceId.createFromId(new BigInteger("-8884663987180930485"));
    PublicAccount signature = PublicAccount.createFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b763", NetworkType.MIJIN_TEST);
    TransactionInfo transactionInfo = TransactionInfo.createAggregate(new BigInteger("121855"), 1, "5A3D23889CD1E800015929A9", "3D28C804EDD07D5A728E5C5FFEC01AB07AFA5766AE6997B38526D36015A4D006", "5A0069D83F17CF0001777E55");
    String signatureHex = createRandomSignature();
    AddressAliasTransaction transaction = AddressAliasTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), AliasAction.LINK, namespaceId, signature.getAddress()).signer(signature).transactionInfo(transactionInfo).signature(signatureHex).maxFee(fee).build();
    String expectedHash = "A100000000000000" + signatureHex + "68B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B7630000000001904E42010000000000000001000000000000004BFA5F372D55B3849049E14BEBCA93758EB36805BAE760A57239976F009A545C01";
    assertSerialization(expectedHash, transaction);
    String expectedEmbeddedHash = "510000000000000068B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B7630000000001904E424BFA5F372D55B3849049E14BEBCA93758EB36805BAE760A57239976F009A545C01";
    assertEmbeddedSerialization(expectedEmbeddedHash, transaction);
}
Also used : NetworkType(io.nem.symbol.sdk.model.network.NetworkType) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 58 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class TestHelper method getTestAccount.

public Pair<Account, NamespaceId> getTestAccount(RepositoryType type) {
    Account testAccount = config().getTestAccount();
    NamespaceId namespaceId = setAddressAlias(type, testAccount.getAddress(), "testaccount");
    sendMosaicFromNemesis(type, testAccount.getAddress(), false);
    return Pair.of(testAccount, namespaceId);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 59 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId 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 60 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId 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

NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)70 Test (org.junit.jupiter.api.Test)37 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)18 BigInteger (java.math.BigInteger)17 Account (io.nem.symbol.sdk.model.account.Account)15 Address (io.nem.symbol.sdk.model.account.Address)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)14 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)10 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)9 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)8 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)8 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)7 Observable (io.reactivex.Observable)7 List (java.util.List)7 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)6 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)6 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)6 ArrayList (java.util.ArrayList)6