Search in sources :

Example 61 with MosaicId

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

the class MosaicRestrictionTransactionServiceTest method createMosaicGlobalRestrictionTransactionFactoryWhenExistUsingAlias.

@Test
void createMosaicGlobalRestrictionTransactionFactoryWhenExistUsingAlias() throws Exception {
    MosaicGlobalRestrictionTransaction transaction = service.createMosaicGlobalRestrictionTransactionFactory(mosaicAlias1, restrictionKey, BigInteger.valueOf(30), MosaicRestrictionType.GE).toFuture().get().build();
    Assertions.assertEquals(networkType, transaction.getNetworkType());
    Assertions.assertEquals(mosaicAlias1, 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)

Example 62 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId 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)

Example 63 with MosaicId

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

the class AccountInfoTest method regularValueAccountCreationAndSerialization.

@Test
void regularValueAccountCreationAndSerialization() {
    List<ResolvedMosaic> mosaics = Collections.singletonList(new ResolvedMosaic(new MosaicId(BigInteger.TEN), BigInteger.valueOf(10000)));
    SupplementalAccountKeys supplementalAccountKeys = new SupplementalAccountKeys(linkedKey, nodeKey, vrfKey, Collections.singletonList(new AccountLinkVotingKey(votingKey, 10, 20)));
    List<ActivityBucket> activityBuckets = Collections.emptyList();
    AccountInfo accountInfo = new AccountInfo("abc", 1, address, new BigInteger("964"), accountPublicKey, new BigInteger("966"), BigInteger.ZERO, BigInteger.ZERO, mosaics, AccountType.REMOTE_UNLINKED, supplementalAccountKeys, activityBuckets);
    assertEquals("abc", accountInfo.getRecordId().get());
    assertEquals(address, accountInfo.getAddress());
    assertEquals(new BigInteger("964"), accountInfo.getAddressHeight());
    assertEquals(accountPublicKey, accountInfo.getPublicKey());
    assertEquals(new BigInteger("966"), accountInfo.getPublicKeyHeight());
    assertEquals(new BigInteger("0"), accountInfo.getImportance().getValue());
    assertEquals(new BigInteger("0"), accountInfo.getImportance().getHeight());
    assertEquals(mosaics, accountInfo.getMosaics());
    assertEquals(PublicAccount.createFromPublicKey(accountPublicKey.toHex(), networkType), accountInfo.getPublicAccount());
    assertEquals(AccountType.REMOTE_UNLINKED, accountInfo.getAccountType());
    assertEquals(supplementalAccountKeys, accountInfo.getSupplementalAccountKeys());
    assertEquals(activityBuckets, accountInfo.getActivityBuckets());
    assertEquals(linkedKey, supplementalAccountKeys.getLinked().get());
    assertEquals(nodeKey, supplementalAccountKeys.getNode().get());
    assertEquals(vrfKey, supplementalAccountKeys.getVrf().get());
    assertEquals(votingKey, supplementalAccountKeys.getVoting().get(0).getPublicKey());
    assertEquals(10, supplementalAccountKeys.getVoting().get(0).getStartEpoch());
    assertEquals(20, supplementalAccountKeys.getVoting().get(0).getEndEpoch());
    assertFalse(accountInfo.isHighValue());
    byte[] serializedState = accountInfo.serialize();
    String expectedHex = "010090FD35818960C7B18B72F49A5598FA9F712A354DB38EB076C4030000000000001111111111111111111111111111111111111111111111111111111111111111C6030000000000000300070122222222222222222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333333333333333444444444444444444444444444444444444444444444444444444444444444455555555555555555555555555555555555555555555555555555555555555550A0000001400000001000A000000000000001027000000000000";
    assertEquals(expectedHex, ConvertUtils.toHex(serializedState));
    AccountStateBuilder builder = AccountStateBuilder.loadFromBinary(SerializationUtils.toDataInput(serializedState));
    Assertions.assertEquals(AccountStateFormatDto.REGULAR, builder.getFormat());
    Assertions.assertEquals(ConvertUtils.toHex(serializedState), ConvertUtils.toHex(builder.serialize()));
}
Also used : ResolvedMosaic(io.nem.symbol.sdk.model.mosaic.ResolvedMosaic) AccountStateBuilder(io.nem.symbol.catapult.builders.AccountStateBuilder) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 64 with MosaicId

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

the class AccountInfoTest method highValueAccountCreationAndSerialization.

@Test
void highValueAccountCreationAndSerialization() {
    List<ResolvedMosaic> mosaics = Collections.singletonList(new ResolvedMosaic(new MosaicId(BigInteger.TEN), BigInteger.valueOf(10000)));
    SupplementalAccountKeys supplementalAccountKeys = new SupplementalAccountKeys(linkedKey, nodeKey, vrfKey, Collections.singletonList(new AccountLinkVotingKey(votingKey, 10, 20)));
    List<ActivityBucket> activityBuckets = Stream.of(1, 2, 3, 4, 5).map(index -> new ActivityBucket(BigInteger.valueOf(index), BigInteger.valueOf(10 * index), 100 * index, BigInteger.valueOf(1000 * index))).collect(Collectors.toList());
    AccountInfo accountInfo = new AccountInfo("abc", 1, address, new BigInteger("964"), accountPublicKey, new BigInteger("966"), new BigInteger("777"), new BigInteger("0"), mosaics, AccountType.REMOTE_UNLINKED, supplementalAccountKeys, activityBuckets);
    assertEquals("abc", accountInfo.getRecordId().get());
    assertEquals(address, accountInfo.getAddress());
    assertEquals(new BigInteger("964"), accountInfo.getAddressHeight());
    assertEquals(accountPublicKey, accountInfo.getPublicKey());
    assertEquals(new BigInteger("966"), accountInfo.getPublicKeyHeight());
    assertEquals(new BigInteger("777"), accountInfo.getImportance().getValue());
    assertEquals(new BigInteger("0"), accountInfo.getImportance().getHeight());
    assertEquals(mosaics, accountInfo.getMosaics());
    assertEquals(PublicAccount.createFromPublicKey(accountPublicKey.toHex(), NetworkType.MIJIN_TEST), accountInfo.getPublicAccount());
    assertEquals(AccountType.REMOTE_UNLINKED, accountInfo.getAccountType());
    assertTrue(accountInfo.isHighValue());
    assertEquals(supplementalAccountKeys, accountInfo.getSupplementalAccountKeys());
    assertEquals(activityBuckets, accountInfo.getActivityBuckets());
    assertEquals(linkedKey, supplementalAccountKeys.getLinked().get());
    assertEquals(nodeKey, supplementalAccountKeys.getNode().get());
    assertEquals(vrfKey, supplementalAccountKeys.getVrf().get());
    assertEquals(votingKey, supplementalAccountKeys.getVoting().get(0).getPublicKey());
    assertEquals(10, supplementalAccountKeys.getVoting().get(0).getStartEpoch());
    assertEquals(20, supplementalAccountKeys.getVoting().get(0).getEndEpoch());
    byte[] serializedState = accountInfo.serialize();
    assertEquals(388, serializedState.length);
    String expectedHex = "010090FD35818960C7B18B72F49A5598FA9F712A354DB38EB076C4030000000000001111111111111111111111111111111111111111111111111111111111111111C6030000000000000301070122222222222222222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333333333333333444444444444444444444444444444444444444444444444444444444444444455555555555555555555555555555555555555555555555555555555555555550A000000140000000903000000000000000000000000000001000000000000000A0000000000000064000000E80300000000000002000000000000001400000000000000C8000000D00700000000000003000000000000001E000000000000002C010000B80B0000000000000400000000000000280000000000000090010000A00F00000000000005000000000000003200000000000000F4010000881300000000000001000A000000000000001027000000000000";
    assertEquals(expectedHex, ConvertUtils.toHex(serializedState));
    AccountStateBuilder accountStateBuilder = AccountStateBuilder.loadFromBinary(SerializationUtils.toDataInput(serializedState));
    Assertions.assertEquals(AccountStateFormatDto.HIGH_VALUE, accountStateBuilder.getFormat());
    Assertions.assertEquals(ConvertUtils.toHex(serializedState), ConvertUtils.toHex(accountStateBuilder.serialize()));
}
Also used : ResolvedMosaic(io.nem.symbol.sdk.model.mosaic.ResolvedMosaic) AccountStateFormatDto(io.nem.symbol.catapult.builders.AccountStateFormatDto) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Collectors(java.util.stream.Collectors) AccountStateBuilder(io.nem.symbol.catapult.builders.AccountStateBuilder) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PublicKey(io.nem.symbol.core.crypto.PublicKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Collections(java.util.Collections) SerializationUtils(io.nem.symbol.sdk.infrastructure.SerializationUtils) AccountStateBuilder(io.nem.symbol.catapult.builders.AccountStateBuilder) ResolvedMosaic(io.nem.symbol.sdk.model.mosaic.ResolvedMosaic) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 65 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId 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)

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