Search in sources :

Example 1 with NamespaceId

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

the class TestHelper method getMultisigAccount.

public Pair<Account, NamespaceId> getMultisigAccount(RepositoryType type) {
    Account multisigAccount = config().getMultisigAccount();
    sendMosaicFromNemesis(type, multisigAccount.getAddress(), false);
    NamespaceId namespaceId = setAddressAlias(type, multisigAccount.getAddress(), "multisigaccount");
    this.createMultisigAccountBonded(type, multisigAccount, config().getCosignatoryAccount(), config().getCosignatory2Account());
    return Pair.of(multisigAccount, namespaceId);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 2 with NamespaceId

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

the class TransactionServiceIntegrationTest method transferUsingAliasesAggregate.

private AggregateTransaction transferUsingAliasesAggregate(Account sender, RepositoryType type, String mosaicAlias, String recipientAlias, BigInteger amount) {
    NamespaceId recipientNamespace = NamespaceId.createFromName(recipientAlias);
    NamespaceId mosaicNamespace = NamespaceId.createFromName(mosaicAlias);
    System.out.println("Sending " + amount + " Mosaic to: " + mosaicAlias);
    TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipientNamespace, Collections.singletonList(new Mosaic(mosaicNamespace, amount))).message(new PlainMessage("E2ETest:TransactionServiceIntegrationTest"));
    factory.maxFee(maxFee);
    TransferTransaction transferTransaction = factory.build();
    Assertions.assertTrue(transferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
    Assertions.assertTrue(transferTransaction.getRecipient() instanceof NamespaceId);
    Pair<TransferTransaction, AggregateTransaction> pair = announceAggregateAndValidate(type, transferTransaction, sender);
    TransferTransaction processedTransferTransaction = pair.getLeft();
    Assertions.assertEquals(amount, processedTransferTransaction.getMosaics().get(0).getAmount());
    System.out.println(toJson(processedTransferTransaction));
    Assertions.assertTrue(processedTransferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
    Assertions.assertTrue(processedTransferTransaction.getRecipient() instanceof NamespaceId);
    return pair.getRight();
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic)

Example 3 with NamespaceId

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

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

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

the class NamespaceMetadataServiceIntegrationTest method setAndUpdateNamespaceMetadata.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void setAndUpdateNamespaceMetadata(RepositoryType type) {
    // TODO try target != signer
    Account signerAccount = config().getDefaultAccount();
    Account targetAccount = config().getDefaultAccount();
    String namespaceName = "namespace-id-metadata-service-integration-test-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    NamespaceId targetNamespaceId = super.createRootNamespace(type, signerAccount, namespaceName);
    BigInteger key = BigInteger.valueOf(RandomUtils.generateRandomInt(100000));
    String originalMessage = "The original message";
    String newMessage = "The new Message";
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    MetadataRepository metadataRepository = repositoryFactory.createMetadataRepository();
    MetadataTransactionService service = new MetadataTransactionServiceImpl(repositoryFactory);
    NamespaceMetadataTransaction originalTransaction = get(service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), key, originalMessage, signerAccount.getAddress(), targetNamespaceId)).maxFee(maxFee).build();
    announceAggregateAndValidate(type, originalTransaction, signerAccount);
    assertMetadata(targetNamespaceId, key, originalMessage, metadataRepository, signerAccount);
    NamespaceMetadataTransaction updateTransaction = get(service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), key, newMessage, signerAccount.getAddress(), targetNamespaceId)).maxFee(maxFee).build();
    announceAggregateAndValidate(type, updateTransaction, signerAccount);
    assertMetadata(targetNamespaceId, key, newMessage, metadataRepository, signerAccount);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) Account(io.nem.symbol.sdk.model.account.Account) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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