Search in sources :

Example 21 with Deadline

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

the class TransactionServiceTest method aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfo.

@Test
void aggregateTransferTransactionResolveAliasFailWhenNoTransactionInfo() {
    ArrayList<Mosaic> mosaics = new ArrayList<>();
    mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
    mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
    mosaics.add(new Mosaic(mosaicId3, BigInteger.valueOf(3)));
    UnresolvedAddress recipient = addressNamespace1;
    String transactionHash = "aaaa";
    TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipient, mosaics).message(new PlainMessage("")).transactionInfo(TransactionInfo.create(height, 0, "ABC", "BBBB", ""));
    // Extra transfer not aliases
    TransactionFactory<TransferTransaction> extraTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), address2, Collections.singletonList(new Mosaic(mosaicId1, BigInteger.valueOf(1)))).message(new PlainMessage(""));
    TransferTransaction transferTransaction = factory.build();
    transferTransaction.toAggregate(Account.generateNewAccount(networkType).getPublicAccount());
    TransactionFactory<AggregateTransaction> aggregateTransactionFactory = AggregateTransactionFactory.createComplete(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction, extraTransaction.build().toAggregate(Account.generateNewAccount(networkType).getPublicAccount()))).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    AggregateTransaction aggregateTransaction = aggregateTransactionFactory.build();
    simulateStatement(height, 1, 1);
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(aggregateTransaction)));
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
        ExceptionUtils.propagate(service.resolveAliases(hashes).toFuture()::get);
    });
    Assertions.assertEquals("TransactionIndex cannot be loaded from Transaction TRANSFER", exception.getMessage());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) ArrayList(java.util.ArrayList) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 22 with Deadline

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

the class AbstractTransactionMapper method createFactory.

protected final TransactionFactory<T> createFactory(TransactionInfo transactionInfo, Object transactionDto) {
    D transaction = getJsonHelper().convert(transactionDto, transactionDtoClass);
    TransactionDTO transactionDTO = getJsonHelper().convert(transactionDto, TransactionDTO.class);
    NetworkType networkType = NetworkType.rawValueOf(transactionDTO.getNetwork().getValue());
    Deadline deadline = transactionDTO.getDeadline() != null ? new Deadline(transactionDTO.getDeadline()) : new Deadline(BigInteger.ZERO);
    TransactionFactory<T> factory = createFactory(networkType, deadline, transaction);
    factory.version(transactionDTO.getVersion());
    if (transactionDTO.getSignerPublicKey() != null) {
        factory.signer(PublicAccount.createFromPublicKey(transactionDTO.getSignerPublicKey(), networkType));
    }
    if (transactionDTO.getSignature() != null) {
        factory.signature(transactionDTO.getSignature());
    }
    if (transactionDTO.getMaxFee() != null) {
        factory.maxFee(transactionDTO.getMaxFee());
    }
    if (transactionDTO.getSize() != null) {
        factory.size(transactionDTO.getSize());
    }
    if (transactionInfo != null) {
        factory.transactionInfo(transactionInfo);
    }
    if (factory.getType() != getTransactionType()) {
        throw new IllegalStateException("Expected transaction to be " + getTransactionType() + " but got " + factory.getType());
    }
    return factory;
}
Also used : TransactionDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionDTO) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Deadline(io.nem.symbol.sdk.model.transaction.Deadline)

Example 23 with Deadline

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

the class AccountOperationRestrictionTransactionMapper method createFactory.

@Override
protected AccountOperationRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountOperationRestrictionTransactionDTO transaction) {
    AccountOperationRestrictionFlags restrictionFlags = AccountOperationRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
    List<TransactionType> additions = transaction.getRestrictionAdditions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
    List<TransactionType> deletions = transaction.getRestrictionDeletions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
    return AccountOperationRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, additions, deletions);
}
Also used : Deadline(io.nem.symbol.sdk.model.transaction.Deadline) List(java.util.List) AccountRestrictionFlagsEnum(io.nem.symbol.sdk.openapi.vertx.model.AccountRestrictionFlagsEnum) AccountOperationRestrictionTransactionDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountOperationRestrictionTransactionDTO) JsonHelper(io.nem.symbol.sdk.model.transaction.JsonHelper) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) AccountOperationRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionFlags) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) TransactionTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.TransactionTypeEnum) Collectors(java.util.stream.Collectors) AccountOperationRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransactionFactory) AccountOperationRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionFlags) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType)

Example 24 with Deadline

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

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatuTrueMultipleNormalAccount.

/*
   * ACT Alice: account1 Bob: account4 An escrow contract is signed by all the participants
   * (normal accounts) Given Alice defined the following escrow contract: | sender | recipient |
   * type | data | | Alice | Bob | send-an-asset | 1 concert.ticket | | Bob | Alice |
   * send-an-asset | 20 euros | And Bob signs the contract And Alice signs the contract Then the
   * contract should appear as complete
   */
@Test
void shouldReturnCorrectIsCompleteStatuTrueMultipleNormalAccount() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account1.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    TransferTransaction transferTransaction2 = 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), Arrays.asList(transferTransaction.toAggregate(account4.getPublicAccount()), transferTransaction2.toAggregate(account1.getPublicAccount()))).build();
    SignedTransaction signedTransaction1 = aggregateTransaction.signWith(account1, generationHash);
    Assertions.assertFalse(service.isComplete(signedTransaction1).toFuture().get());
    SignedTransaction signedTransaction2 = account1.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account4), generationHash);
    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 25 with Deadline

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

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