Search in sources :

Example 6 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class TransactionTest method generateHashFromTransferTransactionPayload.

@Test
void generateHashFromTransferTransactionPayload() {
    TransferTransactionFactory factory = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.emptyList()).message(new PlainMessage(""));
    TransferTransaction transaction = factory.build();
    String hash = transaction.createTransactionHash("C7000000D0B190DFEEAB0378F943F79CDB7BC44453491890FAA70F5AA95B909E67487408407956BDE32AC977D035FBBA575C11AA034B23402066C16FD6126893F3661B099A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24039054410000000000000000A76541BE0C00000090E8FEBD671DD41BEE94EC3BA5831CB608A312C2F203BA84AC03000300303064000000000000006400000000000000002F00FA0DEDD9086400000000000000443F6D806C05543A6400000000000000", generationHash.getBytes());
    assertEquals("820C535E7998AEE4255677A9C53566190225C02D99558AC48192171EC8144B43", hash);
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Test(org.junit.jupiter.api.Test)

Example 7 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method shouldGenerateBytes.

@Test
void shouldGenerateBytes() {
    String expected = "B10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0100010000000000672B0000CE560000640000000000000000";
    TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("")).build();
    assertSerialization(expected, transaction);
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 8 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method createATransferTransactionViaStaticConstructor.

@Test
void createATransferTransactionViaStaticConstructor() {
    Duration epochAdjustment = Duration.ofSeconds(100);
    Address address = Address.generateRandom(networkType);
    Deadline originalDeadline = new Deadline(BigInteger.ONE);
    TransferTransactionFactory factory = TransferTransactionFactory.create(networkType, originalDeadline, address, Collections.emptyList()).message(new PlainMessage(""));
    Assertions.assertEquals(originalDeadline, factory.getDeadline());
    Deadline updatedDeadline = Deadline.create(epochAdjustment);
    factory.deadline(updatedDeadline);
    Assertions.assertEquals(updatedDeadline, factory.getDeadline());
    TransferTransaction transaction = factory.build();
    assertEquals(networkType, transaction.getNetworkType());
    assertEquals(1, (int) transaction.getVersion());
    assertTrue(LocalDateTime.now().isBefore(transaction.getDeadline().getLocalDateTime(epochAdjustment)));
    assertEquals(BigInteger.valueOf(0), transaction.getMaxFee());
    assertEquals(address, transaction.getRecipient());
    assertEquals(0, transaction.getMosaics().size());
    assertNotNull(transaction.getMessage());
    assertEquals(161, factory.getSize());
    assertEquals(transaction.getSize(), factory.getSize());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test)

Example 9 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method toAggregate.

@Test
@DisplayName("To aggregate")
void toAggregate() {
    String expected = "61000000000000009A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24000000000190544190F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0100010000000000672B0000CE560000640000000000000000";
    TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("")).build();
    Transaction aggregateTransaction = transaction.toAggregate(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", networkType));
    assertEmbeddedSerialization(expected, aggregateTransaction);
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with PlainMessage

use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method mosaicArrayToBeSorted.

@Test
void mosaicArrayToBeSorted() {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(new MosaicId(new BigInteger("200")), BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(new MosaicId(new BigInteger("100")), BigInteger.valueOf(2)));
    TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), mosaics).message(new PlainMessage("")).build();
    assertEquals(mosaics.get(0).getId().getIdAsLong(), new BigInteger("200").longValue());
    assertEquals(mosaics.get(1).getId().getIdAsLong(), new BigInteger("100").longValue());
    TransferTransaction deserialized = (TransferTransaction) new BinarySerializationImpl().deserialize(transaction.serialize());
    assertEquals(mosaics.get(1).getId(), deserialized.getMosaics().get(0).getId());
    assertEquals(mosaics.get(0).getId(), deserialized.getMosaics().get(1).getId());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Aggregations

PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)63 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)45 Test (org.junit.jupiter.api.Test)45 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)31 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)30 Address (io.nem.symbol.sdk.model.account.Address)26 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)23 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)23 BigInteger (java.math.BigInteger)20 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)17 Account (io.nem.symbol.sdk.model.account.Account)14 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 ArrayList (java.util.ArrayList)7 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)6 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)6 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)6 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)6 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)5