Search in sources :

Example 56 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusTRUEMultisigSingleLevel.

/*
   * ACT - Multisig single level Alice (account1): initiate an transfer to Bob Bob (multisig3): is
   * a 2/2 multisig account (account2 && account3)
   */
@Test
void shouldReturnCorrectIsCompleteStatusTRUEMultisigSingleLevel() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account4.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTransaction.toAggregate(multisig3.getPublicAccount()))).build();
    SignedTransaction signedTransactionNoCosignatures = account2.sign(aggregateTransaction, generationHash);
    SignedTransaction signedTransaction1 = account2.signTransactionGivenSignatures(aggregateTransaction, Collections.singletonList(account3.signCosignatureTransaction(signedTransactionNoCosignatures.getHash())), generationHash);
    SignedTransaction signedTransaction2 = account2.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account3), generationHash);
    Assertions.assertEquals(signedTransaction1.getPayload(), signedTransaction2.getPayload());
    Assertions.assertEquals(signedTransaction1.getHash(), signedTransaction2.getHash());
    Assertions.assertEquals(signedTransaction1.getSigner(), signedTransaction2.getSigner());
    Assertions.assertEquals(signedTransaction1.getType(), signedTransaction2.getType());
    Assertions.assertTrue(service.isComplete(signedTransaction1).toFuture().get());
    Assertions.assertTrue(service.isComplete(signedTransaction2).toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 57 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnIsCompleteTrueForAggregatedCompleteTransaction2LevelsMultisig.

/*
   * MLMA Alice (account1): normal account Bob (multisig2) - Multisig 2-1 (account1 && multisig1)
   * Charles (multisig1) - Multisig 1-1 (account2 || account3) Given signatories: Account1 &&
   * Account4 Expecting complete as Bob needs 2 signatures (account1 && (account2 || account3))
   */
@Test
void shouldReturnIsCompleteTrueForAggregatedCompleteTransaction2LevelsMultisig() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTransaction.toAggregate(multisig2.getPublicAccount()))).build();
    SignedTransaction signedTransaction = account1.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account2), generationHash);
    Assertions.assertTrue(service.isComplete(signedTransaction).toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 58 with PlainMessage

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

the class BinarySerializationTest method testSerializationDeserialization.

@Test
void testSerializationDeserialization() {
    BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
    TransferTransaction transaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Address.generateRandom(NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).build();
    byte[] serialize = binarySerialization.serialize(transaction);
    Assertions.assertNotNull(serialize);
    TransferTransaction deserializedTransaction = (TransferTransaction) binarySerialization.deserialize(serialize);
    Assertions.assertNotNull(deserializedTransaction);
    Assertions.assertEquals("Some Message", deserializedTransaction.getMessage().get().getText());
    Assertions.assertEquals(MessageType.PLAIN_MESSAGE, deserializedTransaction.getMessage().get().getType());
}
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) Test(org.junit.jupiter.api.Test)

Example 59 with PlainMessage

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

the class BinarySerializationTest method testSignature.

@Test
void testSignature() {
    BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
    TransferTransaction transaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Address.generateRandom(NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).build();
    SignedTransaction signedTransaction = transaction.signWith(account, generationHash);
    String signature = signedTransaction.getPayload().substring(16, 128 + 16);
    // If we deserialize the signed transaction, we get everything back, include the
    // signer and
    // signature
    byte[] payloadWithSignatureAndSigner = ConvertUtils.getBytes(signedTransaction.getPayload());
    TransferTransaction deserialized = (TransferTransaction) binarySerialization.deserialize(payloadWithSignatureAndSigner);
    Assertions.assertTrue(deserialized.getSignature().isPresent());
    Assertions.assertTrue(deserialized.getSigner().isPresent());
    Assertions.assertEquals(signature.toUpperCase(), deserialized.getSignature().get());
    Assertions.assertEquals(account.getPublicAccount(), deserialized.getSigner().get());
    // Test that the payload is the same, just without the signature and signer.
    byte[] payloadWithoutSignatureAndSigner = binarySerialization.serialize(transaction);
    Assertions.assertEquals(ConvertUtils.toHex(payloadWithoutSignatureAndSigner).substring(208), ConvertUtils.toHex(payloadWithSignatureAndSigner).substring(208));
    Transaction deserializeWithoutSignature = binarySerialization.deserialize(payloadWithoutSignatureAndSigner);
    Assertions.assertFalse(deserializeWithoutSignature.getSignature().isPresent());
    Assertions.assertFalse(deserializeWithoutSignature.getSigner().isPresent());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) 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 60 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusFalseForAggregatedCompleteTransactionNoneMultisig.

/*
   * If the inner transaction is issued to a multisig account and the inner transaction itself is
   * a ModifyMultiSigAccountTransaction - Removal The validator should use minRemoval value rather
   * than minApproval value to determine if the act is complete or not
   */
@Test
void shouldReturnCorrectIsCompleteStatusFalseForAggregatedCompleteTransactionNoneMultisig() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account2.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTransaction.toAggregate(account4.getPublicAccount()))).build();
    SignedTransaction signedTransaction = aggregateTransaction.signWith(account1, generationHash);
    Assertions.assertFalse(service.isComplete(signedTransaction).toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) 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