Search in sources :

Example 1 with HashLockInfoBuilder

use of io.nem.symbol.catapult.builders.HashLockInfoBuilder 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)

Aggregations

HashLockInfoBuilder (io.nem.symbol.catapult.builders.HashLockInfoBuilder)1 Address (io.nem.symbol.sdk.model.account.Address)1 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)1 BigInteger (java.math.BigInteger)1 Test (org.junit.jupiter.api.Test)1