Search in sources :

Example 31 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusForAggregatedCompleteTransaction2LevelsMultisigMmultiInnerTransaction.

/*
   * MLMA - with multiple transaction Alice (account1): normal account Bob (multisig2) - Multisig
   * 2-1 (account1 && multisig1) Charles (multisig1) - Multisig 1-1 (account2 || account3) An
   * extra inner transaction to account4 (just to increase the complexity) Given signatories:
   * Account1 && Account4 && Account2 Expecting complete
   */
@Test
void shouldReturnCorrectIsCompleteStatusForAggregatedCompleteTransaction2LevelsMultisigMmultiInnerTransaction() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account2.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    TransferTransaction transferTransaction2 = 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), Arrays.asList(transferTransaction.toAggregate(multisig2.getPublicAccount()), transferTransaction2.toAggregate(account4.getPublicAccount()))).build();
    SignedTransaction signedTransaction = account1.signTransactionWithCosignatories(aggregateTransaction, Arrays.asList(account4, 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 32 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusTrueForAggregatedCompleteTransactionNoneMultisig.

/*
   * ACT Alice (account1): normal account Bob (account4) - normal account Alice initiate the
   * transaction Bob sign
   */
@Test
void shouldReturnCorrectIsCompleteStatusTrueForAggregatedCompleteTransactionNoneMultisig() 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(account4, 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 33 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnIsCompleteFalseForAggregatedCompleteTransaction2LevelsMultisig.

/*
   * MLMA Alice (account1): normal account Bob (multisig2) - Multisig 2-1 (account1 && multisig1)
   * Charles (multisig1) - Multisig 1-1 (account2 || account3) Given signatories: Account1 &&
   * Account4 Expecting incomplete as Bob needs 2 signatures (account1 && (account2 || account3))
   * but only got account1
   */
@Test
void shouldReturnIsCompleteFalseForAggregatedCompleteTransaction2LevelsMultisig() 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.emptyList(), generationHash);
    Assertions.assertFalse(service.isComplete(signedTransaction).toFuture().get());
    AggregateTransaction deserialize = (AggregateTransaction) BinarySerializationImpl.INSTANCE.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
    Assertions.assertEquals(account1.getAddress(), deserialize.getSigner().get().getAddress());
    Assertions.assertEquals(0, deserialize.getCosignatures().size());
    Assertions.assertEquals(multisig2.getPublicAccount(), deserialize.getInnerTransactions().get(0).getSigner().get());
    Assertions.assertEquals(deserialize.getSize(), ConvertUtils.fromHexToBytes(signedTransaction.getPayload()).length);
}
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 34 with PlainMessage

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

the class AggregateTransactionServiceTest method shouldReturnIsCompleteFalseForAggregatedCompleteTransaction2LevelsMultisig2.

/*
   * MLMA Alice (account1): normal account Bob (multisig2) - Multisig 2-1 (account1 && multisig1)
   * Charles (multisig1) - Multisig 1-1 (account2 || account3) Given signatories: Account1 &&
   * Account4 Expecting incomplete as Bob needs 2 signatures (account1 && (account2 || account3))
   * but got account4
   */
@Test
void shouldReturnIsCompleteFalseForAggregatedCompleteTransaction2LevelsMultisig2() 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 signedTransaction1 = account1.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account4), generationHash);
    SignedTransaction signedTransaction2 = account1.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account4), generationHash);
    Assertions.assertEquals(signedTransaction1.getHash(), signedTransaction2.getHash());
    Assertions.assertEquals(signedTransaction1.getPayload(), signedTransaction2.getPayload());
    Assertions.assertFalse(service.isComplete(signedTransaction1).toFuture().get());
    AggregateTransaction deserialize = (AggregateTransaction) BinarySerializationImpl.INSTANCE.deserialize(ConvertUtils.fromHexToBytes(signedTransaction2.getPayload()));
    Assertions.assertEquals(account1.getAddress(), deserialize.getSigner().get().getAddress());
    Assertions.assertEquals(1, deserialize.getCosignatures().size());
    Assertions.assertEquals(account4.getPublicAccount(), deserialize.getCosignatures().get(0).getSigner());
    Assertions.assertEquals(multisig2.getPublicAccount(), deserialize.getInnerTransactions().get(0).getSigner().get());
    Assertions.assertEquals(deserialize.getSize(), ConvertUtils.fromHexToBytes(signedTransaction1.getPayload()).length);
}
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 35 with PlainMessage

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

the class TransactionRepositoryOkHttpImplTest method getSignedTransaction.

private SignedTransaction getSignedTransaction() {
    String generationHash = "A94B1BE81F1D4C95D6D252AD7BA3FFFB1674991FD880B7A57DC3180AF8D69C32";
    Account account = Account.createFromPrivateKey("063F36659A8BB01D5685826C19E2C2CA9D281465B642BD5E43CB69510408ECF7", networkType);
    Address address = Address.generateRandom(networkType);
    TransferTransaction transferTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, deadline, address, Collections.singletonList(createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneTransferTransaction:message")).build();
    SignedTransaction signedTransaction = account.sign(transferTransaction, generationHash);
    String payload = signedTransaction.getPayload();
    assertEquals(444, payload.length());
    return signedTransaction;
}
Also used : 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) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

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