Search in sources :

Example 6 with MosaicNames

use of io.nem.symbol.sdk.model.mosaic.MosaicNames in project nem2-sdk-java by nemtech.

the class CurrencyServiceTest method getNetworkCurrencyFromNamespaceId.

@Test
void getNetworkCurrencyFromNamespaceId() throws Exception {
    MosaicId mosaicId = new MosaicId(BigInteger.TEN);
    Account account = Account.generateNewAccount(NetworkType.MAIN_NET);
    BigInteger supply = BigInteger.valueOf(12);
    MosaicInfo mosaicInfo = new MosaicInfo("abc", 1, mosaicId, supply, BigInteger.ONE, account.getAddress(), 4L, MosaicFlags.create(true, true, true), 10, BigInteger.TEN);
    Mockito.when(mosaicRepository.getMosaic(Mockito.eq(mosaicId))).thenReturn(Observable.just(mosaicInfo));
    String name = "some.alias";
    NamespaceId namespaceId = NamespaceId.createFromName(name);
    MosaicNames mosaicNames = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName(name), new NamespaceName("some.alias2")));
    Mockito.when(namespaceRepository.getLinkedMosaicId(Mockito.eq(namespaceId))).thenReturn(Observable.just(mosaicId));
    Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(mosaicInfo)));
    Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(mosaicNames)));
    Currency currency = service.getCurrencyFromNamespaceId(namespaceId).toFuture().get();
    Assertions.assertEquals(10, currency.getDivisibility());
    Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
    Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
    Assertions.assertEquals(namespaceId, currency.getNamespaceId().get());
    Assertions.assertEquals("some.alias", currency.getNamespaceId().get().getFullName().get());
    Assertions.assertTrue(currency.isTransferable());
    Assertions.assertTrue(currency.isSupplyMutable());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) Currency(io.nem.symbol.sdk.model.mosaic.Currency) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 7 with MosaicNames

use of io.nem.symbol.sdk.model.mosaic.MosaicNames 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)

Aggregations

MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)7 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)7 Account (io.nem.symbol.sdk.model.account.Account)4 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)4 BigInteger (java.math.BigInteger)4 Test (org.junit.jupiter.api.Test)4 Currency (io.nem.symbol.sdk.model.mosaic.Currency)3 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)3 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)3 MosaicNamesDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicNamesDTO)2 MosaicsNamesDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicsNamesDTO)2 List (java.util.List)2 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1 MapperUtils.toNamespaceId (io.nem.symbol.core.utils.MapperUtils.toNamespaceId)1 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)1 NamespaceSearchCriteria (io.nem.symbol.sdk.api.NamespaceSearchCriteria)1 Page (io.nem.symbol.sdk.api.Page)1 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)1 AccountNames (io.nem.symbol.sdk.model.account.AccountNames)1 Address (io.nem.symbol.sdk.model.account.Address)1