use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method transferTransactionResolveAliasCannotMosaicAliasResolveAliases.
@Test
void transferTransactionResolveAliasCannotMosaicAliasResolveAliases() {
ArrayList<Mosaic> mosaics = new ArrayList<>();
mosaics.add(new Mosaic(mosaicId1, BigInteger.valueOf(1)));
mosaics.add(new Mosaic(mosaicNamespace2, BigInteger.valueOf(2)));
NamespaceId idontexist = NamespaceId.createFromName("idontexist");
mosaics.add(new Mosaic(idontexist, BigInteger.valueOf(3)));
UnresolvedAddress recipient = addressNamespace1;
String transactionHash = "aaaa";
TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipient, mosaics).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
simulateStatement(height, 1, 0);
TransferTransaction 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)));
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ExceptionUtils.propagate(() -> service.resolveAliases(hashes).toFuture().get()));
Assertions.assertEquals("MosaicId could not be resolved for alias " + idontexist.getIdAsHex(), exception.getMessage());
}
use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method mosaicAddressRestrictionTransactionResolveAlias.
@Test
void mosaicAddressRestrictionTransactionResolveAlias() throws ExecutionException, InterruptedException {
String transactionHash = "aaaa";
TransactionFactory<MosaicAddressRestrictionTransaction> factory = MosaicAddressRestrictionTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), mosaicNamespace2, BigInteger.TEN, addressNamespace3, BigInteger.ONE).previousRestrictionValue(BigInteger.valueOf(3)).previousRestrictionValue(BigInteger.valueOf(3)).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
MosaicAddressRestrictionTransaction transaction = factory.build();
simulateStatement(height, 1, 0);
List<String> hashes = Collections.singletonList(transactionHash);
Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
MosaicAddressRestrictionTransaction resolvedTransaction = (MosaicAddressRestrictionTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaicId());
Assertions.assertEquals(address3, resolvedTransaction.getTargetAddress());
}
use of io.nem.symbol.sdk.model.transaction.Deadline 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());
}
use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method accountMosaicRestrictionTransactionResolveAlias.
@Test
void accountMosaicRestrictionTransactionResolveAlias() throws ExecutionException, InterruptedException {
String transactionHash = "aaaa";
TransactionFactory<AccountMosaicRestrictionTransaction> factory = AccountMosaicRestrictionTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), AccountMosaicRestrictionFlags.ALLOW_INCOMING_MOSAIC, Arrays.asList(mosaicNamespace1, mosaicId2, mosaicNamespace2), Arrays.asList(mosaicNamespace2, mosaicNamespace3, mosaicId3)).transactionInfo(TransactionInfo.create(height, 4, "ABC", transactionHash, ""));
AccountMosaicRestrictionTransaction transaction = factory.build();
simulateStatement(height, 5, 0);
List<String> hashes = Collections.singletonList(transactionHash);
Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
AccountMosaicRestrictionTransaction resolvedTransaction = (AccountMosaicRestrictionTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
Assertions.assertEquals(Arrays.asList(mosaicId1, mosaicId2, mosaicId2), resolvedTransaction.getRestrictionAdditions());
Assertions.assertEquals(Arrays.asList(mosaicId2, mosaicId3, mosaicId3), resolvedTransaction.getRestrictionDeletions());
}
Aggregations