Search in sources :

Example 11 with PublicAccount

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

the class MosaicDefinitionTransactionTest method shouldGenerateEmbeddedBytes.

@Test
@DisplayName("SerializationEmbeddedBytes")
void shouldGenerateEmbeddedBytes() {
    String expected = "460000000000000068b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b7630000000001904d4100000000000000000a00000000000000000000000203";
    NetworkType networkType = NetworkType.MIJIN_TEST;
    MosaicId mosaicId = new MosaicId(new BigInteger("0"));
    BigInteger fee = BigInteger.ONE;
    MosaicNonce mosaicNonce = MosaicNonce.createFromBigInteger(new BigInteger("0"));
    MosaicFlags mosaicFlags = MosaicFlags.create(false, true, false);
    PublicAccount signature = PublicAccount.createFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b763", NetworkType.MIJIN_TEST);
    TransactionInfo transactionInfo = TransactionInfo.createAggregate(new BigInteger("121855"), 1, "5A3D23889CD1E800015929A9", "3D28C804EDD07D5A728E5C5FFEC01AB07AFA5766AE6997B38526D36015A4D006", "5A0069D83F17CF0001777E55");
    MosaicDefinitionTransaction transaction = MosaicDefinitionTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), mosaicNonce, mosaicId, mosaicFlags, 3, new BlockDuration(10)).maxFee(fee).signature("theSigner").signer(signature).transactionInfo(transactionInfo).build();
    assertEmbeddedSerialization(expected, transaction);
}
Also used : MosaicFlags(io.nem.symbol.sdk.model.mosaic.MosaicFlags) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with PublicAccount

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

the class HashLockTransactionTest method toAggregate.

@Test
@DisplayName("To aggregate")
void toAggregate() {
    String expected = "68000000000000009a49366406aca952b88badf5f1e9be6ce4968141035a60be503273ea65456b24000000000190484144b262c46ceabb85809698000000000064000000000000008498b38d89c1dc8a448ea5824938ff828926cd9f7747b1844b59b4b6807e878b";
    HashLockTransaction transaction = HashLockTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Currency.CAT_CURRENCY.createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), "8498B38D89C1DC8A448EA5824938FF828926CD9F7747B1844B59B4B6807E878B").build();
    transaction.toAggregate(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", networkType));
    assertEmbeddedSerialization(expected, transaction);
}
Also used : PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with PublicAccount

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

the class TransactionRepositoryVertxImplTest method searchTransactions.

@Test
public void searchTransactions() throws Exception {
    TransactionInfoDTO transferTransactionDTO = loadTransactionInfoDTO("standaloneTransferTransaction.json");
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    mockRemoteCall(toPage(transferTransactionDTO));
    Page<Transaction> transactions = repository.search(new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED).signerPublicKey(publicAccount.getPublicKey())).toFuture().get();
    Assertions.assertEquals(TransactionType.TRANSFER, transactions.getData().get(0).getType());
    Assertions.assertEquals(TransactionGroup.UNCONFIRMED, transactions.getData().get(0).getGroup().get());
    Assertions.assertEquals(1, transactions.getData().size());
    Assertions.assertEquals(1, transactions.getPageNumber());
    Assertions.assertEquals(2, transactions.getPageSize());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TestHelperVertx.loadTransactionInfoDTO(io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 14 with PublicAccount

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

the class VertxAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.

@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
    Address address = Address.generateRandom(networkType);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", networkType)))).build();
    Account cosignatoryAccount = Account.generateNewAccount(this.networkType);
    Account cosignatoryAccount2 = Account.generateNewAccount(this.networkType);
    Account cosignatoryAccount3 = Account.generateNewAccount(this.networkType);
    SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2, cosignatoryAccount3), generationHash);
    BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
    AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
    Assertions.assertEquals(2, deserialized.getCosignatures().size());
    Assertions.assertEquals(cosignatoryAccount2.getPublicAccount(), deserialized.getCosignatures().get(0).getSigner());
    Assertions.assertEquals(cosignatoryAccount3.getPublicAccount(), deserialized.getCosignatures().get(1).getSigner());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 15 with PublicAccount

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

the class VertxAggregateTransactionTest method serialization.

@Test
@DisplayName("Serialization")
void serialization() {
    Address address = Address.generateRandom(networkType);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), address, Collections.singletonList(createAbsolute(BigInteger.valueOf(10000000)))).message(new PlainMessage("")).build();
    PublicAccount signer = Account.generateNewAccount(networkType).getPublicAccount();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTx.toAggregate(signer))).build();
    byte[] actual = aggregateTx.serialize();
    BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
    AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(actual);
    assertEquals(signer, deserialized.getInnerTransactions().get(0).getSigner().get());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

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