Search in sources :

Example 6 with Mosaic

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

the class AccountTest method shouldSignTransaction.

@Test
void shouldSignTransaction() {
    Account account = new Account("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", NetworkType.MIJIN_TEST);
    TransferTransaction transferTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", NetworkType.MIJIN_TEST), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("")).build();
    SignedTransaction signedTransaction = account.sign(transferTransaction, generationHash);
    String payload = signedTransaction.getPayload();
    assertEquals("B10000000000000013193EF4F0D94DE26249D196A0575944877D5572CE13B80E4E8380FA34F9F54FF936F96162473857546F7B624A6248D8F7B3D0142DC85BBB06EB7BFEE125880B2134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F200000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0100010000000000672B0000CE560000640000000000000000", payload);
    assertEquals("58D649ABF9A26AFB3F070E26F157920DAB6423415B4344108B93EDD80DE330E5", signedTransaction.getHash());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 7 with Mosaic

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

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

the class TransferTransactionTest method shouldGenerateBytesNoMessage.

@Test
void shouldGenerateBytesNoMessage() {
    String expected = "B00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0000010000000000672B0000CE5600006400000000000000";
    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)))).build();
    assertSerialization(expected, transaction);
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) 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 9 with Mosaic

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

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

Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)35 Test (org.junit.jupiter.api.Test)26 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)24 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)19 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)18 BigInteger (java.math.BigInteger)18 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)15 Address (io.nem.symbol.sdk.model.account.Address)12 ArrayList (java.util.ArrayList)12 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)8 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)6 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)6 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)5 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)5 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)4 Account (io.nem.symbol.sdk.model.account.Account)4 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)4 Currency (io.nem.symbol.sdk.model.mosaic.Currency)4 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)4