Search in sources :

Example 31 with PublicAccount

use of io.nem.symbol.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class SecretLockTransactionTest method serialize.

@Test
@DisplayName("Serialize")
void serialize() {
    PublicAccount publicAccount = new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", NetworkType.MIJIN_TEST);
    String secret = "3fc8ba10229ab5778d05d9c4b7f56676a88bf9295c185acfc0f961db5408cafe";
    SecretLockTransaction transaction = SecretLockTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Currency.CAT_CURRENCY.createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), LockHashAlgorithm.SHA3_256, secret, Address.createFromRawAddress("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ")).signer(publicAccount).build();
    String expected = "D100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B2400000000019052410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A3FC8BA10229AB5778D05D9C4B7F56676A88BF9295C185ACFC0F961DB5408CAFE44B262C46CEABB858096980000000000640000000000000000";
    assertSerialization(expected, transaction);
    String expectedEmbbeded = "81000000000000009A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24000000000190524190F36CA680C35D630662A0C38DC89D4978D10B511B3D241A3FC8BA10229AB5778D05D9C4B7F56676A88BF9295C185ACFC0F961DB5408CAFE44B262C46CEABB858096980000000000640000000000000000";
    assertEmbeddedSerialization(expectedEmbbeded, transaction);
}
Also used : PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 32 with PublicAccount

use of io.nem.symbol.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class MosaicIdTest method hashCodeAndEquals.

@Test
void hashCodeAndEquals() {
    PublicAccount owner = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST);
    MosaicNonce nonce = MosaicNonce.createFromInteger(0);
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, owner);
    MosaicId mosaicId2 = new MosaicId(new BigInteger("5331590414131997017"));
    MosaicId mosaicId3 = MosaicId.createFromNonce(nonce, owner.getAddress());
    assertEquals(mosaicId, mosaicId);
    assertNotEquals("", mosaicId);
    assertNotEquals(mosaicId, "");
    assertEquals(mosaicId, mosaicId2);
    assertEquals(mosaicId.hashCode(), mosaicId2.hashCode());
    assertEquals(mosaicId, mosaicId3);
}
Also used : PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 33 with PublicAccount

use of io.nem.symbol.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class MosaicIdTest method createAMosaicIdFromNonceAndOwner.

@Test
void createAMosaicIdFromNonceAndOwner() {
    PublicAccount owner = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST);
    MosaicNonce nonce = MosaicNonce.createFromInteger(0);
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, owner);
    MosaicId mosaicId2 = new MosaicId(new BigInteger("5331590414131997017"));
    MosaicId mosaicId3 = MosaicId.createFromNonce(nonce, owner.getAddress());
    assertEquals(mosaicId, mosaicId);
    assertEquals(mosaicId, mosaicId2);
    assertEquals(mosaicId, mosaicId3);
    assertEquals(5331590414131997017L, mosaicId2.getIdAsLong());
}
Also used : PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 34 with PublicAccount

use of io.nem.symbol.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class MosaicIdTest method createAMosaicIdFromNonceAndOwnerTwiceTheSame.

@Test
void createAMosaicIdFromNonceAndOwnerTwiceTheSame() {
    PublicAccount owner = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST);
    MosaicNonce nonce = MosaicNonce.createFromInteger(0);
    MosaicId mosaicId1 = MosaicId.createFromNonce(nonce, owner);
    MosaicId mosaicId2 = MosaicId.createFromNonce(nonce, owner);
    assertEquals(mosaicId1, mosaicId2);
    assertEquals(mosaicId1.hashCode(), mosaicId2.hashCode());
}
Also used : PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Test(org.junit.jupiter.api.Test)

Example 35 with PublicAccount

use of io.nem.symbol.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class AddressAliasTransactionTest method shouldSerialize.

@Test
void shouldSerialize() {
    NetworkType networkType = NetworkType.MIJIN_TEST;
    BigInteger fee = BigInteger.ONE;
    NamespaceId namespaceId = NamespaceId.createFromId(new BigInteger("-8884663987180930485"));
    PublicAccount signature = PublicAccount.createFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b763", NetworkType.MIJIN_TEST);
    TransactionInfo transactionInfo = TransactionInfo.createAggregate(new BigInteger("121855"), 1, "5A3D23889CD1E800015929A9", "3D28C804EDD07D5A728E5C5FFEC01AB07AFA5766AE6997B38526D36015A4D006", "5A0069D83F17CF0001777E55");
    String signatureHex = createRandomSignature();
    AddressAliasTransaction transaction = AddressAliasTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), AliasAction.LINK, namespaceId, signature.getAddress()).signer(signature).transactionInfo(transactionInfo).signature(signatureHex).maxFee(fee).build();
    String expectedHash = "A100000000000000" + signatureHex + "68B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B7630000000001904E42010000000000000001000000000000004BFA5F372D55B3849049E14BEBCA93758EB36805BAE760A57239976F009A545C01";
    assertSerialization(expectedHash, transaction);
    String expectedEmbeddedHash = "510000000000000068B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B7630000000001904E424BFA5F372D55B3849049E14BEBCA93758EB36805BAE760A57239976F009A545C01";
    assertEmbeddedSerialization(expectedEmbeddedHash, transaction);
}
Also used : NetworkType(io.nem.symbol.sdk.model.network.NetworkType) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Aggregations

PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)35 Test (org.junit.jupiter.api.Test)30 Address (io.nem.symbol.sdk.model.account.Address)16 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)14 BigInteger (java.math.BigInteger)13 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)11 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)9 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)8 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)8 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)7 DisplayName (org.junit.jupiter.api.DisplayName)7 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)6 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)5 BinarySerialization (io.nem.symbol.sdk.api.BinarySerialization)4 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)4 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)3 TestHelperOkHttp.loadTransactionInfoDTO (io.nem.symbol.sdk.infrastructure.okhttp.TestHelperOkHttp.loadTransactionInfoDTO)3 Account (io.nem.symbol.sdk.model.account.Account)3 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)3