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());
}
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())));
}
Aggregations