use of io.nem.symbol.sdk.model.namespace.NamespaceId 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());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class StateProofServiceTest method namespace.
@Test
void namespace() throws Exception {
NamespaceRepository repository = mock(NamespaceRepository.class);
when(factory.createNamespaceRepository()).thenReturn(repository);
NamespaceId id = NamespaceId.createFromId(BigInteger.ONE);
NamespaceInfo state = Mockito.mock(NamespaceInfo.class);
when(state.getId()).thenReturn(id);
when(state.serialize(any())).thenReturn(ConvertUtils.fromHexToBytes(serialized));
when(repository.streamer()).thenReturn(new PaginationStreamer<>(repository));
when(repository.search(any())).thenReturn(Observable.just(new Page<>(new ArrayList<>())));
when(repository.getNamespace(eq(id))).thenReturn(Observable.just(state));
when(repository.getNamespaceMerkle(eq(id))).thenReturn(Observable.just(tree));
StateMerkleProof<NamespaceInfo> proof = service.namespace(id).toFuture().get();
Assertions.assertTrue(proof.isValid());
Assertions.assertEquals(state, proof.getState());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class MapperUtilsTest method toUnresolvedMosaicId.
@Test
void toUnresolvedMosaicId() {
MosaicId mosaicId = new MosaicId("11F4B1B3AC033DB5");
NamespaceId namespaceId = NamespaceId.createFromName("some.name123");
Assertions.assertNull(MapperUtils.toUnresolvedMosaicId(null));
Assertions.assertEquals(mosaicId, MapperUtils.toUnresolvedMosaicId(mosaicId.getIdAsHex()));
Assertions.assertEquals(namespaceId, MapperUtils.toUnresolvedMosaicId(namespaceId.getIdAsHex()));
Assertions.assertEquals(new NamespaceId("9a52fde35777cd4f"), MapperUtils.toUnresolvedMosaicId("9a52fde35777cd4f"));
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class MapperUtilsTest method toUnresolvedAddressZeroPadded.
@Test
void toUnresolvedAddressZeroPadded() {
UnresolvedAddress actual = MapperUtils.toUnresolvedAddress("01E7CA7E22727DDD8800000000000000000000000000000000");
Assertions.assertTrue(actual instanceof NamespaceId);
Assertions.assertEquals("88DD7D72227ECAE7", ((NamespaceId) actual).getIdAsHex());
}
use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.
the class MapperUtilsTest method toUnresolvedAddressFromPlain.
@Test
public void toUnresolvedAddressFromPlain() {
Assertions.assertEquals(new NamespaceId("C0FB8AA409916260"), MapperUtils.toUnresolvedAddressFromPlain("C0FB8AA409916260"));
Assertions.assertEquals(Address.createFromRawAddress("TAHNZXQBC57AA7KJTMGS3PJPZBXN7DV5JHJU42A"), MapperUtils.toUnresolvedAddressFromPlain("TAHNZXQBC57AA7KJTMGS3PJPZBXN7DV5JHJU42A"));
IllegalArgumentException e = Assertions.assertThrows(IllegalArgumentException.class, () -> {
MapperUtils.toUnresolvedAddressFromPlain("abc");
});
Assertions.assertEquals("'abc' is not a valid plain address or namespace hex", e.getMessage());
}
Aggregations