Search in sources :

Example 46 with AggregateTransaction

use of io.nem.symbol.sdk.model.transaction.AggregateTransaction 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 47 with AggregateTransaction

use of io.nem.symbol.sdk.model.transaction.AggregateTransaction 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 48 with AggregateTransaction

use of io.nem.symbol.sdk.model.transaction.AggregateTransaction 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 49 with AggregateTransaction

use of io.nem.symbol.sdk.model.transaction.AggregateTransaction in project nem2-sdk-java by nemtech.

the class OkHttpAggregateTransactionTest method shouldFindAccountInAsASignerOfTheTransaction.

@Test
void shouldFindAccountInAsASignerOfTheTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("accountInAsASignerOfTheTransaction.json");
    AggregateTransaction aggregateTransferTransaction = (AggregateTransaction) new GeneralTransactionMapper(jsonHelper).mapFromDto(aggregateTransferTransactionDTO);
    assertTrue(aggregateTransferTransaction.signedByAccount(PublicAccount.createFromPublicKey("A5F82EC8EBB341427B6785C8111906CD0DF18838FB11B51CE0E18B5E79DFF630", networkType)));
    assertTrue(aggregateTransferTransaction.signedByAccount(PublicAccount.createFromPublicKey("7681ED5023141D9CDCF184E5A7B60B7D466739918ED5DA30F7E71EA7B86EFF2D", networkType)));
    assertFalse(aggregateTransferTransaction.signedByAccount(PublicAccount.createFromPublicKey("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", networkType)));
}
Also used : GeneralTransactionMapper(io.nem.symbol.sdk.infrastructure.okhttp.mappers.GeneralTransactionMapper) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Test(org.junit.jupiter.api.Test)

Example 50 with AggregateTransaction

use of io.nem.symbol.sdk.model.transaction.AggregateTransaction in project nem2-sdk-java by nemtech.

the class OkHttpAggregateTransactionTest method createAAggregateTransactionViaStaticConstructor.

@Test
void createAAggregateTransactionViaStaticConstructor() {
    Duration epochAdjustment = Duration.ofSeconds(100);
    Address recipient = Address.generateRandom(NetworkType.MIJIN_TEST);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, recipient, Collections.emptyList()).message(new PlainMessage("")).build();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, Deadline.create(epochAdjustment), Collections.singletonList(transferTx.toAggregate(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", networkType)))).build();
    assertEquals(networkType, aggregateTx.getNetworkType());
    assertEquals(1, (int) aggregateTx.getVersion());
    assertTrue(LocalDateTime.now().isBefore(aggregateTx.getDeadline().getLocalDateTime(epochAdjustment)));
    assertEquals(BigInteger.valueOf(0), aggregateTx.getMaxFee());
    assertEquals(1, aggregateTx.getInnerTransactions().size());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)94 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)68 Test (org.junit.jupiter.api.Test)66 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)44 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)43 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)41 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)36 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)36 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)35 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)35 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)35 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)35 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)35 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)35 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)34 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)33 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)33 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)32 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)32 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)32