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());
}
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());
}
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()));
}
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()));
}
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"));
}
Aggregations