Search in sources :

Example 1 with NetworkConfiguration

use of io.nem.symbol.sdk.model.network.NetworkConfiguration in project nem2-sdk-java by nemtech.

the class NetworkRepositoryVertxImplTest method getNetworkProperties.

@Test
void getNetworkProperties() throws Exception {
    NetworkConfigurationDTO dto = TestHelperVertx.loadResource("network-configuration.json", NetworkConfigurationDTO.class);
    Assertions.assertNotNull(dto);
    ObjectNode plain = TestHelperVertx.loadResource("network-configuration.json", ObjectNode.class);
    Assertions.assertNotNull(plain);
    Assertions.assertEquals(jsonHelper.prettyPrint(dto), jsonHelper.prettyPrint(plain));
    mockRemoteCall(dto);
    NetworkConfiguration configuration = repository.getNetworkProperties().toFuture().get();
    Assertions.assertNotNull(configuration);
    Map sorted = TestHelperVertx.loadResource("network-configuration.json", Map.class);
    Assertions.assertNotNull(sorted);
    ((Map) sorted.get("network")).put("nodeEqualityStrategy", "PUBLIC_KEY");
    Assertions.assertEquals(jsonHelper.prettyPrint(sorted), jsonHelper.prettyPrint(configuration));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NetworkConfigurationDTO(io.nem.symbol.sdk.openapi.vertx.model.NetworkConfigurationDTO) NetworkConfiguration(io.nem.symbol.sdk.model.network.NetworkConfiguration) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with NetworkConfiguration

use of io.nem.symbol.sdk.model.network.NetworkConfiguration in project nem2-sdk-java by nemtech.

the class AggregateTransactionServiceTest method getNetworkMaxCosignaturesPerAggregateWhenValidInvalid.

@Test
void getNetworkMaxCosignaturesPerAggregateWhenValidInvalid() {
    NetworkConfiguration configuration = Mockito.mock(NetworkConfiguration.class);
    PluginsProperties pluginsProperties = Mockito.mock(PluginsProperties.class);
    AggregateNetworkProperties aggregateNetworkProperties = Mockito.mock(AggregateNetworkProperties.class);
    Mockito.when(pluginsProperties.getAggregate()).thenReturn(aggregateNetworkProperties);
    Mockito.when(configuration.getPlugins()).thenReturn(pluginsProperties);
    Mockito.when(networkRepository.getNetworkProperties()).thenReturn(Observable.just(configuration));
    IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> ExceptionUtils.propagate(() -> service.getNetworkMaxCosignaturesPerAggregate().toFuture().get()));
    Assertions.assertEquals("Cannot get maxCosignaturesPerAggregate from network properties.", exception.getMessage());
}
Also used : PluginsProperties(io.nem.symbol.sdk.model.network.PluginsProperties) AggregateNetworkProperties(io.nem.symbol.sdk.model.network.AggregateNetworkProperties) NetworkConfiguration(io.nem.symbol.sdk.model.network.NetworkConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with NetworkConfiguration

use of io.nem.symbol.sdk.model.network.NetworkConfiguration in project nem2-sdk-java by nemtech.

the class AggregateTransactionServiceTest method getNetworkMaxCosignaturesPerAggregateWhenValid.

@Test
void getNetworkMaxCosignaturesPerAggregateWhenValid() throws ExecutionException, InterruptedException {
    NetworkConfiguration configuration = Mockito.mock(NetworkConfiguration.class);
    PluginsProperties pluginsProperties = Mockito.mock(PluginsProperties.class);
    AggregateNetworkProperties aggregateNetworkProperties = Mockito.mock(AggregateNetworkProperties.class);
    Mockito.when(aggregateNetworkProperties.getMaxCosignaturesPerAggregate()).thenReturn("25");
    Mockito.when(pluginsProperties.getAggregate()).thenReturn(aggregateNetworkProperties);
    Mockito.when(configuration.getPlugins()).thenReturn(pluginsProperties);
    Mockito.when(networkRepository.getNetworkProperties()).thenReturn(Observable.just(configuration));
    Integer maxCosignaturesPerAggregate = service.getNetworkMaxCosignaturesPerAggregate().toFuture().get();
    Assertions.assertEquals(25, maxCosignaturesPerAggregate);
}
Also used : BigInteger(java.math.BigInteger) PluginsProperties(io.nem.symbol.sdk.model.network.PluginsProperties) AggregateNetworkProperties(io.nem.symbol.sdk.model.network.AggregateNetworkProperties) NetworkConfiguration(io.nem.symbol.sdk.model.network.NetworkConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with NetworkConfiguration

use of io.nem.symbol.sdk.model.network.NetworkConfiguration 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 5 with NetworkConfiguration

use of io.nem.symbol.sdk.model.network.NetworkConfiguration in project nem2-sdk-java by nemtech.

the class NetworkRepositoryOkHttpImplTest method getNetworkProperties.

@Test
void getNetworkProperties() throws Exception {
    NetworkConfigurationDTO dto = TestHelperOkHttp.loadResource("network-configuration.json", NetworkConfigurationDTO.class);
    Assertions.assertNotNull(dto);
    JsonObject plain = TestHelperOkHttp.loadResource("network-configuration.json", JsonObject.class);
    Assertions.assertNotNull(plain);
    Assertions.assertEquals(jsonHelper.prettyPrint(dto), jsonHelper.prettyPrint(plain));
    mockRemoteCall(dto);
    NetworkConfiguration configuration = repository.getNetworkProperties().toFuture().get();
    Assertions.assertNotNull(configuration);
    plain.get("network").getAsJsonObject().addProperty("nodeEqualityStrategy", "PUBLIC_KEY");
    Assertions.assertEquals(jsonHelper.prettyPrint(plain), jsonHelper.prettyPrint(configuration));
}
Also used : JsonObject(com.google.gson.JsonObject) NetworkConfigurationDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NetworkConfigurationDTO) NetworkConfiguration(io.nem.symbol.sdk.model.network.NetworkConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

NetworkConfiguration (io.nem.symbol.sdk.model.network.NetworkConfiguration)5 Test (org.junit.jupiter.api.Test)5 AggregateNetworkProperties (io.nem.symbol.sdk.model.network.AggregateNetworkProperties)2 PluginsProperties (io.nem.symbol.sdk.model.network.PluginsProperties)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 JsonObject (com.google.gson.JsonObject)1 Address (io.nem.symbol.sdk.model.account.Address)1 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)1 NetworkCurrencies (io.nem.symbol.sdk.model.mosaic.NetworkCurrencies)1 ChainProperties (io.nem.symbol.sdk.model.network.ChainProperties)1 NetworkConfigurationDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.NetworkConfigurationDTO)1 NetworkConfigurationDTO (io.nem.symbol.sdk.openapi.vertx.model.NetworkConfigurationDTO)1 BigInteger (java.math.BigInteger)1 Map (java.util.Map)1