Search in sources :

Example 6 with Deadline

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

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

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

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

the class TransactionServiceTest method announce.

@Test
void announce() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Collections.emptyList()).build();
    SignedTransaction signedTransaction = transferTransaction.signWith(account, "abc");
    TransactionAnnounceResponse transactionAnnounceResponse = new TransactionAnnounceResponse("Some Message");
    Mockito.when(transactionRepositoryMock.announce(Mockito.eq(signedTransaction))).thenReturn(Observable.just(transactionAnnounceResponse));
    Mockito.when(listener.confirmedOrError(Mockito.eq(account.getAddress()), Mockito.eq(signedTransaction.getHash()))).thenReturn(Observable.just(transferTransaction));
    Observable<Transaction> announcedTransaction = service.announce(listener, signedTransaction);
    Assertions.assertEquals(transferTransaction, announcedTransaction.toFuture().get());
}
Also used : SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) MosaicAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 10 with Deadline

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

the class TransactionServiceTest method hashLockTransactionResolveAlias.

@Test
void hashLockTransactionResolveAlias() throws ExecutionException, InterruptedException {
    Mosaic unresolvedMosaicId = new Mosaic(mosaicNamespace2, BigInteger.valueOf(2));
    String transactionHash = "aaaa";
    TransactionFactory<HashLockTransaction> factory = HashLockTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), unresolvedMosaicId, BigInteger.TEN, "SomeHash").transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    simulateStatement(height, 1, 0);
    HashLockTransaction transaction = factory.build();
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    HashLockTransaction resolvedTransaction = (HashLockTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaic().getId());
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Aggregations

Deadline (io.nem.symbol.sdk.model.transaction.Deadline)49 Test (org.junit.jupiter.api.Test)38 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)28 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)23 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)22 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)19 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)14 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)9 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)9 BigInteger (java.math.BigInteger)8 ArrayList (java.util.ArrayList)6 Address (io.nem.symbol.sdk.model.account.Address)5 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)5 Account (io.nem.symbol.sdk.model.account.Account)4 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)4 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)4 Duration (java.time.Duration)4 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)3 TransactionAnnounceResponse (io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse)3 BinarySerialization (io.nem.symbol.sdk.api.BinarySerialization)2