Search in sources :

Example 1 with ResolvedMosaic

use of io.nem.symbol.sdk.model.mosaic.ResolvedMosaic 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 2 with ResolvedMosaic

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

Aggregations

AccountStateBuilder (io.nem.symbol.catapult.builders.AccountStateBuilder)2 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)2 ResolvedMosaic (io.nem.symbol.sdk.model.mosaic.ResolvedMosaic)2 BigInteger (java.math.BigInteger)2 Test (org.junit.jupiter.api.Test)2 AccountStateFormatDto (io.nem.symbol.catapult.builders.AccountStateFormatDto)1 PublicKey (io.nem.symbol.core.crypto.PublicKey)1 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)1 SerializationUtils (io.nem.symbol.sdk.infrastructure.SerializationUtils)1 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Assertions (org.junit.jupiter.api.Assertions)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1