Search in sources :

Example 11 with HashLockTransaction

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

the class TransactionServiceTest method announceHashLockAggregateBonded.

@Test
void announceHashLockAggregateBonded() throws ExecutionException, InterruptedException {
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transaction1), Collections.emptyList()).build();
    String generationHash = "abc";
    SignedTransaction aggregateSignedTransaction = aggregateTransaction.signWith(account, generationHash);
    HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Currency.CAT_CURRENCY.createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), aggregateSignedTransaction.getHash()).build();
    SignedTransaction hashLockSignedTranscation = hashLockTransaction.signWith(account, generationHash);
    TransactionAnnounceResponse aggregateTransactionAnnounceResponse = new TransactionAnnounceResponse("Aggregate Some Message");
    TransactionAnnounceResponse hashTransactionAnnounceResponse = new TransactionAnnounceResponse("Hash Some Message");
    Mockito.when(transactionRepositoryMock.announceAggregateBonded(Mockito.eq(aggregateSignedTransaction))).thenReturn(Observable.just(aggregateTransactionAnnounceResponse));
    Mockito.when(transactionRepositoryMock.announce(Mockito.eq(hashLockSignedTranscation))).thenReturn(Observable.just(hashTransactionAnnounceResponse));
    Mockito.when(listener.confirmedOrError(Mockito.eq(account.getAddress()), Mockito.eq(hashLockSignedTranscation.getHash()))).thenReturn(Observable.just(hashLockTransaction));
    Mockito.when(listener.aggregateBondedAddedOrError(Mockito.eq(account.getAddress()), Mockito.eq(aggregateSignedTransaction.getHash()))).thenReturn(Observable.just(aggregateTransaction));
    Observable<AggregateTransaction> announcedTransaction = service.announceHashLockAggregateBonded(listener, hashLockSignedTranscation, aggregateSignedTransaction);
    Assertions.assertEquals(aggregateTransaction, announcedTransaction.toFuture().get());
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)11 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)7 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)6 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)5 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)4 BigInteger (java.math.BigInteger)4 Account (io.nem.symbol.sdk.model.account.Account)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)3 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)3 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)3 Test (org.junit.jupiter.api.Test)3 TransactionService (io.nem.symbol.sdk.api.TransactionService)2 Address (io.nem.symbol.sdk.model.account.Address)2 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)2 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)2 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2