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());
}
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;
}
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);
}
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());
}
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());
}
Aggregations