use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method simulateStatement.
private void simulateStatement(BigInteger height, int primaryId, int secondaryId) {
Map<NamespaceId, Address> addressMap = new HashMap<>();
addressMap.put(addressNamespace1, address1);
addressMap.put(addressNamespace2, address2);
addressMap.put(addressNamespace3, address3);
Map<NamespaceId, MosaicId> mosaicMap = new HashMap<>();
mosaicMap.put(mosaicNamespace1, mosaicId1);
mosaicMap.put(mosaicNamespace2, mosaicId2);
mosaicMap.put(mosaicNamespace3, mosaicId3);
List<AddressResolutionStatement> addressResolutionStatements = addressMap.entrySet().stream().map(e -> new AddressResolutionStatement("abc", height, e.getKey(), Collections.singletonList(ResolutionEntry.forAddress(e.getValue(), new ReceiptSource(primaryId, secondaryId))))).collect(Collectors.toList());
List<MosaicResolutionStatement> mosaicResolutionStatements = mosaicMap.entrySet().stream().map(e -> new MosaicResolutionStatement("abc", height, e.getKey(), Collections.singletonList(ResolutionEntry.forMosaicId(e.getValue(), new ReceiptSource(primaryId, secondaryId))))).collect(Collectors.toList());
Mockito.when(receiptRepositoryMock.searchAddressResolutionStatements(Mockito.eq(new ResolutionStatementSearchCriteria().height(height)))).thenReturn(Observable.just(new Page<>(addressResolutionStatements)));
Mockito.when(receiptRepositoryMock.searchMosaicResolutionStatements(Mockito.eq(new ResolutionStatementSearchCriteria().height(height)))).thenReturn(Observable.just(new Page<>(mosaicResolutionStatements)));
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId 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());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId 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());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId 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.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class MosaicRestrictionTransactionServiceTest method createMosaicGlobalRestrictionTransactionFactoryWhenExist.
@Test
void createMosaicGlobalRestrictionTransactionFactoryWhenExist() throws Exception {
MosaicGlobalRestrictionTransaction transaction = service.createMosaicGlobalRestrictionTransactionFactory(mosaicId1, restrictionKey, BigInteger.valueOf(30), MosaicRestrictionType.GE).toFuture().get().build();
Assertions.assertEquals(networkType, transaction.getNetworkType());
Assertions.assertEquals(mosaicId1, transaction.getMosaicId());
Assertions.assertEquals(restrictionKey, transaction.getRestrictionKey());
Assertions.assertEquals(new MosaicId(BigInteger.ZERO), transaction.getReferenceMosaicId());
Assertions.assertEquals(BigInteger.valueOf(30), transaction.getNewRestrictionValue());
Assertions.assertEquals(MosaicRestrictionType.GE, transaction.getNewRestrictionType());
Assertions.assertEquals(BigInteger.valueOf(20), transaction.getPreviousRestrictionValue());
Assertions.assertEquals(MosaicRestrictionType.EQ, transaction.getPreviousRestrictionType());
Assertions.assertEquals(networkType, transaction.getNetworkType());
}
Aggregations