Search in sources :

Example 6 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo in project nem2-sdk-java by nemtech.

the class MosaicRepositoryVertxImplTest method shouldGetMosaicsFromAccount.

@Test
public void shouldGetMosaicsFromAccount() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499AAA");
    MosaicDTO mosaicDto = new MosaicDTO();
    mosaicDto.setOwnerAddress(address.encoded());
    mosaicDto.setId("481110499AAA");
    mosaicDto.setRevision(123L);
    mosaicDto.setFlags(5);
    mosaicDto.setDivisibility(6);
    mosaicDto.setVersion(1);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mockRemoteCall(toPage(new MosaicInfoDTO().mosaic(mosaicDto).id("ABC")));
    List<MosaicInfo> resolvedList = repository.search(new MosaicSearchCriteria().ownerAddress(publicAccount.getAddress())).toFuture().get().getData();
    Assertions.assertEquals(1, resolvedList.size());
    MosaicInfo mosaicInfo = resolvedList.get(0);
    Assertions.assertEquals(mosaicId, mosaicInfo.getMosaicId());
    Assertions.assertEquals(mosaicDto.getRevision(), mosaicInfo.getRevision());
    Assertions.assertEquals(mosaicDto.getOwnerAddress(), mosaicInfo.getOwnerAddress().encoded(NetworkType.MIJIN_TEST));
    Assertions.assertFalse(mosaicInfo.isTransferable());
    Assertions.assertEquals(6, mosaicInfo.getDivisibility());
    Assertions.assertEquals(BigInteger.valueOf(7), mosaicInfo.getDuration());
    Assertions.assertEquals(mosaicDto.getStartHeight(), mosaicInfo.getStartHeight());
    Assertions.assertEquals(mosaicDto.getSupply(), mosaicInfo.getSupply());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) Address(io.nem.symbol.sdk.model.account.Address) MosaicDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 7 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo in project nem2-sdk-java by nemtech.

the class CurrencyServiceTest method getNetworkCurrencies.

@Test
void getNetworkCurrencies() throws Exception {
    NetworkConfiguration networkConfiguration = Mockito.mock(NetworkConfiguration.class);
    ChainProperties chainProperties = Mockito.mock(ChainProperties.class);
    String currencyMosaicIdHex = "0x62EF'46FD'6555'AAAA";
    MosaicId currencyMosaicId = new MosaicId(FormatUtils.toSimpleHex(currencyMosaicIdHex));
    Mockito.when(chainProperties.getCurrencyMosaicId()).thenReturn(currencyMosaicIdHex);
    String harvestMosaicIdHex = "0x62EF'46FD'6555'BBBB";
    MosaicId harvestMosaicId = new MosaicId(FormatUtils.toSimpleHex(harvestMosaicIdHex));
    Mockito.when(chainProperties.getHarvestingMosaicId()).thenReturn(harvestMosaicIdHex);
    Mockito.when(networkConfiguration.getChain()).thenReturn(chainProperties);
    Mockito.when(networkRepository.getNetworkProperties()).thenReturn(Observable.just(networkConfiguration));
    Address account = Address.generateRandom(NetworkType.MIJIN_TEST);
    MosaicInfo currencyMosaicInfo = new MosaicInfo("abc", 1, currencyMosaicId, BigInteger.valueOf(100), BigInteger.ONE, account, 4L, MosaicFlags.create(false, true, false), 10, BigInteger.TEN);
    MosaicInfo harvestMosaicInfo = new MosaicInfo("abc", 1, harvestMosaicId, BigInteger.valueOf(200), BigInteger.ONE, account, 4L, MosaicFlags.create(true, false, true), 3, BigInteger.TEN);
    Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Arrays.asList(currencyMosaicId, harvestMosaicId)))).thenReturn(Observable.just(Arrays.asList(currencyMosaicInfo, harvestMosaicInfo)));
    Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Arrays.asList(currencyMosaicId, harvestMosaicId)))).thenReturn(Observable.just(Collections.emptyList()));
    NetworkCurrencies networkCurrencies = service.getNetworkCurrencies().toFuture().get();
    Assertions.assertEquals(currencyMosaicInfo.toCurrency(), networkCurrencies.getCurrency());
    Assertions.assertEquals(harvestMosaicInfo.toCurrency(), networkCurrencies.getHarvest());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ChainProperties(io.nem.symbol.sdk.model.network.ChainProperties) NetworkConfiguration(io.nem.symbol.sdk.model.network.NetworkConfiguration) NetworkCurrencies(io.nem.symbol.sdk.model.mosaic.NetworkCurrencies) Test(org.junit.jupiter.api.Test)

Example 8 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo in project nem2-sdk-java by nemtech.

the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenEmptyNames.

@Test
void getNetworkCurrencyFromMosaicIdWhenEmptyNames() 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(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(mosaicInfo)));
    Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(new MosaicNames(mosaicId, Collections.emptyList()))));
    Currency currency = service.getCurrency(mosaicId).toFuture().get();
    Assertions.assertEquals(10, currency.getDivisibility());
    Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
    Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
    Assertions.assertFalse(currency.getNamespaceId().isPresent());
    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) 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) Test(org.junit.jupiter.api.Test)

Example 9 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo 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 10 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo in project nem2-sdk-java by nemtech.

the class StateProofServiceTest method mosaic.

@Test
void mosaic() throws Exception {
    MosaicRepository repository = mock(MosaicRepository.class);
    when(factory.createMosaicRepository()).thenReturn(repository);
    MosaicId id = new MosaicId(BigInteger.ONE);
    MosaicInfo state = Mockito.mock(MosaicInfo.class);
    when(state.getMosaicId()).thenReturn(id);
    when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
    when(repository.getMosaic(eq(id))).thenReturn(Observable.just(state));
    when(repository.getMosaicMerkle(eq(id))).thenReturn(Observable.just(tree));
    StateMerkleProof<MosaicInfo> proof = service.mosaic(id).toFuture().get();
    Assertions.assertTrue(proof.isValid());
    Assertions.assertEquals(state, proof.getState());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)19 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)15 Test (org.junit.jupiter.api.Test)13 Address (io.nem.symbol.sdk.model.account.Address)9 MosaicSearchCriteria (io.nem.symbol.sdk.api.MosaicSearchCriteria)6 Account (io.nem.symbol.sdk.model.account.Account)5 Currency (io.nem.symbol.sdk.model.mosaic.Currency)5 BigInteger (java.math.BigInteger)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 MosaicDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicDTO)4 MosaicInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO)4 MosaicPaginationStreamer (io.nem.symbol.sdk.api.MosaicPaginationStreamer)3 MosaicRepository (io.nem.symbol.sdk.api.MosaicRepository)3 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)3 MosaicDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicDTO)3 MosaicInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicInfoDTO)3 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)2