Search in sources :

Example 21 with MosaicId

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

the class MosaicDefinitionTransactionTest method serialization.

@Test
@DisplayName("Serialization")
void serialization() {
    String expected = "96000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001904d410000000000000000010000000000000000000000000000001027000000000000000000000504";
    MosaicDefinitionTransaction transaction = MosaicDefinitionTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), MosaicNonce.createFromBigInteger(new BigInteger("0")), new MosaicId(new BigInteger("0")), MosaicFlags.create(true, false, true), 4, new BlockDuration(10000)).build();
    assertSerialization(expected, transaction);
}
Also used : BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with MosaicId

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

the class MosaicMetadataTransactionTest method shouldBuild.

@Test
void shouldBuild() {
    MosaicId mosaicId = new MosaicId(BigInteger.valueOf(1000));
    MosaicMetadataTransaction transaction = MosaicMetadataTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), account.getAddress(), mosaicId, BigInteger.TEN, StringEncoder.getBytes("123ABC")).valueSizeDelta(10).build();
    assertEquals("123ABC", StringEncoder.getString(transaction.getValue()));
    assertEquals(mosaicId, transaction.getTargetMosaicId());
    assertEquals(NetworkType.MIJIN_TEST, transaction.getNetworkType());
    assertEquals(10, transaction.getValueSizeDelta());
    assertEquals(BigInteger.TEN, transaction.getScopedMetadataKey());
    assertEquals(account.getAddress(), transaction.getTargetAddress());
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 23 with MosaicId

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

the class MosaicMetadataTransactionTest method shouldGenerateBytes.

@Test
void shouldGenerateBytes() {
    MosaicId mosaicId = new MosaicId(BigInteger.valueOf(1000));
    MosaicMetadataTransaction transaction = MosaicMetadataTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), account.getAddress(), mosaicId, BigInteger.TEN, StringEncoder.getBytes("123ABC")).valueSizeDelta(10).signer(account.getPublicAccount()).build();
    String expectedHash = "B20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E60000000001904442000000000000000001000000000000009083025FF3A8AB5AD104631FB370F290004952CD1FDDC4C90A00000000000000E8030000000000000A000600313233414243";
    assertSerialization(expectedHash, transaction);
    String expectedEmbeddedHash = "6200000000000000F6503F78FBF99544B906872DDB392F4BE707180D285E7919DBACEF2E9573B1E600000000019044429083025FF3A8AB5AD104631FB370F290004952CD1FDDC4C90A00000000000000E8030000000000000A000600313233414243";
    assertEmbeddedSerialization(expectedEmbeddedHash, transaction);
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 24 with MosaicId

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

the class HashLockInfoTest method constructor.

@Test
void constructor() {
    Optional<String> recordId = Optional.of("abc");
    Address ownerAddress = Address.createFromRawAddress("SDY3NFHBQAPO7ZBII3USHG2UZHJYD7G7FICKIII");
    MosaicId mosaicId = MosaicId.createFromNonce(new MosaicNonce(1), ownerAddress);
    BigInteger amount = BigInteger.ONE;
    BigInteger endHeight = BigInteger.TEN;
    LockStatus status = LockStatus.USED;
    String hash = "DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512F55";
    HashLockInfo info = new HashLockInfo(recordId.orElse(null), 1, ownerAddress, mosaicId, amount, endHeight, status, hash);
    Assertions.assertEquals(recordId, info.getRecordId());
    Assertions.assertEquals(ownerAddress, info.getOwnerAddress());
    Assertions.assertEquals(mosaicId, info.getMosaicId());
    Assertions.assertEquals(amount, info.getAmount());
    Assertions.assertEquals(endHeight, info.getEndHeight());
    Assertions.assertEquals(status, info.getStatus());
    Assertions.assertEquals(hash, info.getHash());
    byte[] serializedState = info.serialize();
    String expectedHex = "010090F1B694E1801EEFE42846E9239B54C9D381FCDF2A04A421E9F49B9E5199FC7601000000000000000A0000000000000001DD9EC2AC9AB11FC7E942E5FA39AF8811180F236E29BCD40DB812392295512F55";
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(serializedState));
    HashLockInfoBuilder builder = HashLockInfoBuilder.loadFromBinary(SerializationUtils.toDataInput(serializedState));
    Assertions.assertEquals(expectedHex, ConvertUtils.toHex(builder.serialize()));
}
Also used : HashLockInfoBuilder(io.nem.symbol.catapult.builders.HashLockInfoBuilder) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) Test(org.junit.jupiter.api.Test)

Example 25 with MosaicId

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

the class MosaicAddressRestrictionTransactionTest method createAMosaicAddressRestrictionTransactionViaStaticConstructor.

@Test
void createAMosaicAddressRestrictionTransactionViaStaticConstructor() {
    Duration epochAdjustment = Duration.ofSeconds(100);
    MosaicAddressRestrictionTransaction transaction = MosaicAddressRestrictionTransactionFactory.create(NetworkType.MIJIN_TEST, Deadline.create(epochAdjustment), // restricted
    new MosaicId(new BigInteger("0")), // restrictionKey
    BigInteger.valueOf(1), // targetAddress
    account.getAddress(), // newRestrictionValue
    BigInteger.valueOf(8)).previousRestrictionValue(BigInteger.valueOf(9)).build();
    assertEquals(NetworkType.MIJIN_TEST, transaction.getNetworkType());
    assertEquals(1, (int) transaction.getVersion());
    assertTrue(LocalDateTime.now().isBefore(transaction.getDeadline().getLocalDateTime(epochAdjustment)));
    assertEquals(BigInteger.valueOf(0), transaction.getMaxFee());
    assertEquals(new BigInteger("0"), transaction.getMosaicId().getId());
    assertEquals(BigInteger.valueOf(1), transaction.getRestrictionKey());
    assertEquals(account.getAddress(), transaction.getTargetAddress());
    assertEquals(BigInteger.valueOf(9), transaction.getPreviousRestrictionValue());
    assertEquals(BigInteger.valueOf(8), transaction.getNewRestrictionValue());
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Duration(java.time.Duration) 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