Search in sources :

Example 1 with NamespaceName

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

the class ListenerIntegrationTest method getAllMultisigAddressesAndAliasesWhenBasic.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAllMultisigAddressesAndAliasesWhenBasic(RepositoryType type) {
    Account testAccount = this.helper().getTestAccount(type).getKey();
    Set<NamespaceId> cosignatoryAccount1aliases = get(getRepositoryFactory(type).createNamespaceRepository().getAccountsNames(Collections.singletonList(testAccount.getAddress()))).stream().flatMap(a -> a.getNames().stream().map(NamespaceName::getNamespaceId)).collect(Collectors.toSet());
    Listener listener = getRepositoryFactory(type).createListener();
    final Set<UnresolvedAddress> unresolvedAddresses = get(listener.getAllMultisigAddressesAndAliases(testAccount.getAddress()));
    final Set<UnresolvedAddress> expectedAddresees = Sets.newSet(testAccount.getAddress());
    expectedAddresees.addAll(cosignatoryAccount1aliases);
    Assertions.assertEquals(expectedAddresees, unresolvedAddresses);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) Arrays(java.util.Arrays) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) Account(io.nem.symbol.sdk.model.account.Account) CompletableFuture(java.util.concurrent.CompletableFuture) EnumSource(org.junit.jupiter.params.provider.EnumSource) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) Disabled(org.junit.jupiter.api.Disabled) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) TestInstance(org.junit.jupiter.api.TestInstance) Sets(org.mockito.internal.util.collections.Sets) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Pair(org.apache.commons.lang3.tuple.Pair) TransactionService(io.nem.symbol.sdk.api.TransactionService) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Listener(io.nem.symbol.sdk.api.Listener) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) Set(java.util.Set) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Account(io.nem.symbol.sdk.model.account.Account) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) Listener(io.nem.symbol.sdk.api.Listener) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with NamespaceName

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

the class NamespaceRepositoryVertxImpl method getNamespaceNames.

@Override
public Observable<List<NamespaceName>> getNamespaceNames(List<NamespaceId> namespaceIds) {
    NamespaceIds ids = new NamespaceIds().namespaceIds(namespaceIds.stream().map(NamespaceId::getIdAsHex).collect(Collectors.toList()));
    Consumer<Handler<AsyncResult<List<NamespaceNameDTO>>>> callback = handler -> client.getNamespacesNames(ids, handler);
    return exceptionHandling(call(callback).flatMapIterable(item -> item).map(this::toNamespaceName).toList().toObservable());
}
Also used : AliasTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.AliasTypeEnum) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) NamespaceDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceDTO) Addresses(io.nem.symbol.sdk.openapi.vertx.model.Addresses) NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) NamespaceRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.NamespaceRoutesApi) ArrayList(java.util.ArrayList) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MapperUtils.toNamespaceId(io.nem.symbol.core.utils.MapperUtils.toNamespaceId) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MosaicAlias(io.nem.symbol.sdk.model.namespace.MosaicAlias) Observable(io.reactivex.Observable) AsyncResult(io.vertx.core.AsyncResult) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicNamesDTO) MapperUtils(io.nem.symbol.core.utils.MapperUtils) Alias(io.nem.symbol.sdk.model.namespace.Alias) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) MosaicsNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicsNamesDTO) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) NamespacePage(io.nem.symbol.sdk.openapi.vertx.model.NamespacePage) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) NamespaceNameDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceNameDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) NamespaceRegistrationTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.NamespaceRegistrationTypeEnum) EmptyAlias(io.nem.symbol.sdk.model.namespace.EmptyAlias) Collectors(java.util.stream.Collectors) NamespaceRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.NamespaceRoutesApiImpl) MosaicIds(io.nem.symbol.sdk.openapi.vertx.model.MosaicIds) NamespaceIds(io.nem.symbol.sdk.openapi.vertx.model.NamespaceIds) AccountNames(io.nem.symbol.sdk.model.account.AccountNames) NamespaceRegistrationType(io.nem.symbol.sdk.model.namespace.NamespaceRegistrationType) Consumer(java.util.function.Consumer) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceInfoDTO) List(java.util.List) AccountNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountNamesDTO) AliasType(io.nem.symbol.sdk.model.namespace.AliasType) AccountsNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountsNamesDTO) Optional(java.util.Optional) Address(io.nem.symbol.sdk.model.account.Address) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) AddressAlias(io.nem.symbol.sdk.model.namespace.AddressAlias) Handler(io.vertx.core.Handler) ArrayList(java.util.ArrayList) List(java.util.List) NamespaceIds(io.nem.symbol.sdk.openapi.vertx.model.NamespaceIds) MapperUtils.toNamespaceId(io.nem.symbol.core.utils.MapperUtils.toNamespaceId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 3 with NamespaceName

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

the class NamespaceRepositoryVertxImplTest method shouldGetNamespaceNames.

@Test
public void shouldGetNamespaceNames() throws Exception {
    NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
    NamespaceNameDTO dto1 = new NamespaceNameDTO();
    dto1.setName("someName1");
    dto1.setId("1");
    dto1.setParentId("2");
    NamespaceNameDTO dto2 = new NamespaceNameDTO();
    dto2.setName("someName2");
    dto2.setId("3");
    mockRemoteCall(Arrays.asList(dto1, dto2));
    List<NamespaceName> names = repository.getNamespaceNames(Arrays.asList(namespaceId)).toFuture().get();
    Assertions.assertNotNull(names);
    Assertions.assertEquals(2, names.size());
    Assertions.assertEquals("someName1", names.get(0).getName());
    Assertions.assertEquals(BigInteger.valueOf(1L), names.get(0).getNamespaceId().getId());
    Assertions.assertEquals(BigInteger.valueOf(2L), names.get(0).getParentId().orElseThrow(() -> new IllegalStateException("No parent id")).getId());
    Assertions.assertEquals("someName2", names.get(1).getName());
    Assertions.assertEquals(BigInteger.valueOf(3L), names.get(1).getNamespaceId().getId());
    Assertions.assertFalse(names.get(1).getParentId().isPresent());
}
Also used : NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) NamespaceNameDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceNameDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 4 with NamespaceName

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

the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent.

@Test
void getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent() 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.getMosaics(Mockito.eq(Arrays.asList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicInfo)));
    String name = "some.alias";
    NamespaceId namespaceId = NamespaceId.createFromName(name);
    MosaicNames mosaicNames = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName(name), new NamespaceName("some.alias2")));
    MosaicNames mosaicNames2 = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName("some.alias2"), new NamespaceName("some.alias3")));
    Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicNames, mosaicNames2)));
    Currency currency = service.getCurrency(mosaicId).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 5 with NamespaceName

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

the class AccountNamesTest method createAccountNames.

@Test
void createAccountNames() {
    Address address = Address.generateRandom(NetworkType.MIJIN_TEST);
    List<NamespaceName> namespaceNames = Arrays.asList(new NamespaceName("accountalias"), new NamespaceName("anotheralias"));
    AccountNames names = new AccountNames(address, namespaceNames);
    assertEquals(address, names.getAddress());
    assertEquals(namespaceNames, names.getNames());
}
Also used : NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) Test(org.junit.jupiter.api.Test)

Aggregations

NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)8 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)6 Test (org.junit.jupiter.api.Test)6 BigInteger (java.math.BigInteger)4 Account (io.nem.symbol.sdk.model.account.Account)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)3 Address (io.nem.symbol.sdk.model.account.Address)2 Currency (io.nem.symbol.sdk.model.mosaic.Currency)2 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)2 NamespaceNameDTO (io.nem.symbol.sdk.openapi.vertx.model.NamespaceNameDTO)2 Observable (io.reactivex.Observable)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1 MapperUtils.toNamespaceId (io.nem.symbol.core.utils.MapperUtils.toNamespaceId)1 Listener (io.nem.symbol.sdk.api.Listener)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