Search in sources :

Example 56 with MosaicId

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)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ResolutionEntry(io.nem.symbol.sdk.model.receipt.ResolutionEntry) SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) Account(io.nem.symbol.sdk.model.account.Account) MosaicAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Map(java.util.Map) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) BigInteger(java.math.BigInteger) Listener(io.nem.symbol.sdk.api.Listener) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicDefinitionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransactionFactory) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) AccountAddressRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionFlags) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) MosaicMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AccountAddressRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransactionFactory) Collectors(java.util.stream.Collectors) StringEncoder(io.nem.symbol.core.utils.StringEncoder) Currency(io.nem.symbol.sdk.model.mosaic.Currency) ReceiptRepository(io.nem.symbol.sdk.api.ReceiptRepository) Test(org.junit.jupiter.api.Test) List(java.util.List) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) MosaicAddressRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransactionFactory) ExceptionUtils(io.nem.symbol.core.utils.ExceptionUtils) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) TransactionFactory(io.nem.symbol.sdk.model.transaction.TransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Page(io.nem.symbol.sdk.api.Page) SecretLockTransactionFactory(io.nem.symbol.sdk.model.transaction.SecretLockTransactionFactory) MosaicSupplyChangeTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransactionFactory) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) AccountMosaicRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransactionFactory) HashMap(java.util.HashMap) MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) ArrayList(java.util.ArrayList) AccountMosaicRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) ResolutionStatementSearchCriteria(io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria) TransactionService(io.nem.symbol.sdk.api.TransactionService) AddressResolutionStatement(io.nem.symbol.sdk.model.receipt.AddressResolutionStatement) MosaicResolutionStatement(io.nem.symbol.sdk.model.receipt.MosaicResolutionStatement) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) MosaicSupplyChangeActionType(io.nem.symbol.sdk.model.mosaic.MosaicSupplyChangeActionType) Observable(io.reactivex.Observable) SecretProofTransactionFactory(io.nem.symbol.sdk.model.transaction.SecretProofTransactionFactory) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) LockHashAlgorithm(io.nem.symbol.sdk.model.transaction.LockHashAlgorithm) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptSource(io.nem.symbol.sdk.model.receipt.ReceiptSource) ExecutionException(java.util.concurrent.ExecutionException) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) TransactionInfo(io.nem.symbol.sdk.model.transaction.TransactionInfo) Mockito(org.mockito.Mockito) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AfterEach(org.junit.jupiter.api.AfterEach) Assertions(org.junit.jupiter.api.Assertions) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) MosaicFlags(io.nem.symbol.sdk.model.mosaic.MosaicFlags) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) MosaicGlobalRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) HashMap(java.util.HashMap) ReceiptSource(io.nem.symbol.sdk.model.receipt.ReceiptSource) AddressResolutionStatement(io.nem.symbol.sdk.model.receipt.AddressResolutionStatement) ResolutionStatementSearchCriteria(io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria) Page(io.nem.symbol.sdk.api.Page) MosaicResolutionStatement(io.nem.symbol.sdk.model.receipt.MosaicResolutionStatement) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 57 with MosaicId

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());
}
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 58 with MosaicId

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());
}
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 59 with MosaicId

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());
}
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 60 with MosaicId

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

Aggregations

MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)138 Test (org.junit.jupiter.api.Test)92 Address (io.nem.symbol.sdk.model.account.Address)53 BigInteger (java.math.BigInteger)53 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)23 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)19 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)18 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)17 Account (io.nem.symbol.sdk.model.account.Account)16 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)15 ArrayList (java.util.ArrayList)13 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)12 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)10 MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)10 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)10 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)7 Currency (io.nem.symbol.sdk.model.mosaic.Currency)7 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)7 MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)7