use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeAlias.
@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED", "UNCONFIRMED_ADDED" })
public void subscribeAlias(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
String channelName = channel.toString();
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("transferEmptyMessage.json");
NamespaceId namespaceId = NamespaceId.createFromName("alias");
ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
List<Transaction> transactions = new ArrayList<>();
BiFunction<UnresolvedAddress, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmed : channel == ListenerChannel.UNCONFIRMED_ADDED ? listener::unconfirmedAdded : listener::aggregateBondedAdded;
TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
subscriber.apply(namespaceId, meta.getHash()).forEach(transactions::add);
handle(transactionInfoDtoJsonObject, channelName + "/" + namespaceId.plain());
Assertions.assertEquals(1, transactions.size());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class NamespaceRepositoryVertxImplTest method getNamespaceMerkle.
@Test
public void getNamespaceMerkle() throws Exception {
NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
mockRemoteCall(new MerkleStateInfoDTO().raw("abc"));
MerkleStateInfo merkle = repository.getNamespaceMerkle(namespaceId).toFuture().get();
Assertions.assertEquals("abc", merkle.getRaw());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class MosaicAliasTransactionMapper method createFactory.
@Override
protected TransactionFactory<MosaicAliasTransaction> createFactory(NetworkType networkType, Deadline deadline, MosaicAliasTransactionDTO transaction) {
NamespaceId namespaceId = MapperUtils.toNamespaceId(transaction.getNamespaceId());
AliasAction aliasAction = AliasAction.rawValueOf(transaction.getAliasAction().getValue().byteValue());
return MosaicAliasTransactionFactory.create(networkType, deadline, aliasAction, namespaceId, MapperUtils.toMosaicId(transaction.getMosaicId()));
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class NamespaceMetadataTransactionMapper method createFactory.
@Override
protected NamespaceMetadataTransactionFactory createFactory(NetworkType networkType, Deadline deadline, NamespaceMetadataTransactionDTO transaction) {
UnresolvedAddress targetAddress = MapperUtils.toUnresolvedAddress(transaction.getTargetAddress());
Integer valueSizeDelta = transaction.getValueSizeDelta();
BigInteger scopedMetaDataKey = MapperUtils.fromHexToBigInteger(transaction.getScopedMetadataKey());
byte[] value = ConvertUtils.fromHexToBytes(transaction.getValue());
NamespaceId targetNamespace = MapperUtils.toNamespaceId(transaction.getTargetNamespaceId());
NamespaceMetadataTransactionFactory factory = NamespaceMetadataTransactionFactory.create(networkType, deadline, targetAddress, targetNamespace, scopedMetaDataKey, value);
factory.valueSizeDelta(valueSizeDelta);
Long valueSize = transaction.getValueSize();
if (valueSize != null) {
factory.valueSize(valueSize);
}
return factory;
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId 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());
}
Aggregations