Search in sources :

Example 16 with NamespaceId

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

the class CurrencyTest method assertCreatedUsingNamespaceId.

@Test
void assertCreatedUsingNamespaceId() {
    NamespaceId namespaceId = NamespaceId.createFromName("mycurrency");
    Currency currency = new CurrencyBuilder(namespaceId, 6).withSupplyMutable(false).withTransferable(true).build();
    Assertions.assertEquals(namespaceId, currency.getNamespaceId().get());
    Assertions.assertEquals(namespaceId, currency.getUnresolvedMosaicId());
    Assertions.assertFalse(currency.getMosaicId().isPresent());
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 17 with NamespaceId

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

the class NamespaceRepositoryOkHttpImplTest method shouldGetNamespace.

@Test
public void shouldGetNamespace() throws Exception {
    Address ownerAccount = Account.generateNewAccount(NetworkType.MIJIN_TEST).getAddress();
    NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
    NamespaceInfoDTO dto = new NamespaceInfoDTO();
    NamespaceMetaDTO meta = new NamespaceMetaDTO();
    meta.setActive(true);
    dto.setId("SomeId");
    meta.setIndex(123);
    dto.setMeta(meta);
    NamespaceDTO namespace = new NamespaceDTO();
    namespace.setDepth(111);
    namespace.setStartHeight(BigInteger.valueOf(4));
    namespace.setEndHeight(BigInteger.valueOf(5));
    namespace.setRegistrationType(NamespaceRegistrationTypeEnum.NUMBER_1);
    namespace.setOwnerAddress(ownerAccount.encoded());
    namespace.setVersion(1);
    AliasDTO alias = new AliasDTO();
    alias.setType(AliasTypeEnum.NUMBER_1);
    alias.setMosaicId("123");
    namespace.setAlias(alias);
    dto.setNamespace(namespace);
    mockRemoteCall(dto);
    NamespaceInfo info = repository.getNamespace(namespaceId).toFuture().get();
    Assertions.assertNotNull(info);
    Assertions.assertEquals(NamespaceRegistrationType.SUB_NAMESPACE, info.getRegistrationType());
    Assertions.assertEquals(dto.getId(), info.getRecordId().get());
    Assertions.assertEquals(meta.getIndex(), info.getIndex());
    Assertions.assertEquals(meta.getActive(), info.isActive());
    Assertions.assertEquals(BigInteger.valueOf(4), info.getStartHeight());
    Assertions.assertEquals(BigInteger.valueOf(5), info.getEndHeight());
}
Also used : NamespaceDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceDTO) Address(io.nem.symbol.sdk.model.account.Address) NamespaceMetaDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceMetaDTO) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceInfoDTO) AliasDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AliasDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 18 with NamespaceId

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

the class NamespaceRepositoryOkHttpImplTest method shouldGetLinkedAddress.

@Test
public void shouldGetLinkedAddress() throws Exception {
    Address address = Address.generateRandom(networkType);
    NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
    Address ownerAccount = Account.generateNewAccount(NetworkType.MIJIN_TEST).getAddress();
    NamespaceInfoDTO dto = new NamespaceInfoDTO();
    NamespaceMetaDTO meta = new NamespaceMetaDTO();
    meta.setActive(true);
    dto.setId("SomeId");
    meta.setIndex(123);
    dto.setMeta(meta);
    NamespaceDTO namespace = new NamespaceDTO();
    namespace.setDepth(111);
    namespace.setRegistrationType(NamespaceRegistrationTypeEnum.NUMBER_0);
    namespace.setOwnerAddress(ownerAccount.encoded());
    AliasDTO alias = new AliasDTO();
    alias.setType(AliasTypeEnum.NUMBER_2);
    alias.setAddress(address.encoded());
    namespace.setAlias(alias);
    dto.setNamespace(namespace);
    mockRemoteCall(dto);
    Address linkedAddress = repository.getLinkedAddress(namespaceId).toFuture().get();
    Assertions.assertNotNull(linkedAddress);
    Assertions.assertEquals(address, linkedAddress);
}
Also used : NamespaceDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceDTO) Address(io.nem.symbol.sdk.model.account.Address) NamespaceMetaDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceMetaDTO) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceInfoDTO) AliasDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AliasDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 19 with NamespaceId

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

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

the class ListenerOkHttpTest method confirmedUsingHashUsingAlias.

@Test
public void confirmedUsingHashUsingAlias() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    NamespaceId alias = NamespaceId.createFromId(BigInteger.TEN);
    String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.confirmedOrError(alias, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + alias.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + alias.plain())));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + alias.plain())));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

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