Search in sources :

Example 21 with NamespaceId

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());
}
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 22 with NamespaceId

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());
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) Page(io.nem.symbol.sdk.api.Page) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 23 with NamespaceId

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"));
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 24 with NamespaceId

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());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 25 with NamespaceId

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());
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) 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