use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransactionServiceTest method announceAggregateBonded.
@Test
void announceAggregateBonded() throws ExecutionException, InterruptedException {
TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Arrays.asList(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);
TransactionAnnounceResponse aggregateTransactionAnnounceResponse = new TransactionAnnounceResponse("Aggregate Some Message");
Mockito.when(transactionRepositoryMock.announceAggregateBonded(Mockito.eq(aggregateSignedTransaction))).thenReturn(Observable.just(aggregateTransactionAnnounceResponse));
Mockito.when(listener.aggregateBondedAddedOrError(Mockito.eq(account.getAddress()), Mockito.eq(aggregateSignedTransaction.getHash()))).thenReturn(Observable.just(aggregateTransaction));
Observable<AggregateTransaction> announcedTransaction = service.announceAggregateBonded(listener, aggregateSignedTransaction);
Assertions.assertEquals(aggregateTransaction, announcedTransaction.toFuture().get());
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic 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.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class BinarySerializationTest method testSerializationDeserialization.
@Test
void testSerializationDeserialization() {
BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
TransferTransaction transaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Address.generateRandom(NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).build();
byte[] serialize = binarySerialization.serialize(transaction);
Assertions.assertNotNull(serialize);
TransferTransaction deserializedTransaction = (TransferTransaction) binarySerialization.deserialize(serialize);
Assertions.assertNotNull(deserializedTransaction);
Assertions.assertEquals("Some Message", deserializedTransaction.getMessage().get().getText());
Assertions.assertEquals(MessageType.PLAIN_MESSAGE, deserializedTransaction.getMessage().get().getType());
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class BinarySerializationTest method testSignature.
@Test
void testSignature() {
BinarySerializationImpl binarySerialization = new BinarySerializationImpl();
TransferTransaction transaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), Address.generateRandom(NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).build();
SignedTransaction signedTransaction = transaction.signWith(account, generationHash);
String signature = signedTransaction.getPayload().substring(16, 128 + 16);
// If we deserialize the signed transaction, we get everything back, include the
// signer and
// signature
byte[] payloadWithSignatureAndSigner = ConvertUtils.getBytes(signedTransaction.getPayload());
TransferTransaction deserialized = (TransferTransaction) binarySerialization.deserialize(payloadWithSignatureAndSigner);
Assertions.assertTrue(deserialized.getSignature().isPresent());
Assertions.assertTrue(deserialized.getSigner().isPresent());
Assertions.assertEquals(signature.toUpperCase(), deserialized.getSignature().get());
Assertions.assertEquals(account.getPublicAccount(), deserialized.getSigner().get());
// Test that the payload is the same, just without the signature and signer.
byte[] payloadWithoutSignatureAndSigner = binarySerialization.serialize(transaction);
Assertions.assertEquals(ConvertUtils.toHex(payloadWithoutSignatureAndSigner).substring(208), ConvertUtils.toHex(payloadWithSignatureAndSigner).substring(208));
Transaction deserializeWithoutSignature = binarySerialization.deserialize(payloadWithoutSignatureAndSigner);
Assertions.assertFalse(deserializeWithoutSignature.getSignature().isPresent());
Assertions.assertFalse(deserializeWithoutSignature.getSigner().isPresent());
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic 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());
}
Aggregations